yairschiff
commited on
Commit
•
20fdad1
1
Parent(s):
beb359a
Upload tokenizer
Browse files- README.md +201 -0
- special_tokens_map.json +9 -0
- tokenization_caduceus.py +135 -0
- tokenizer_config.json +70 -0
README.md
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
tags: []
|
4 |
+
---
|
5 |
+
|
6 |
+
# Model Card for Model ID
|
7 |
+
|
8 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
## Model Details
|
13 |
+
|
14 |
+
### Model Description
|
15 |
+
|
16 |
+
<!-- Provide a longer summary of what this model is. -->
|
17 |
+
|
18 |
+
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
+
|
20 |
+
- **Developed by:** [More Information Needed]
|
21 |
+
- **Funded by [optional]:** [More Information Needed]
|
22 |
+
- **Shared by [optional]:** [More Information Needed]
|
23 |
+
- **Model type:** [More Information Needed]
|
24 |
+
- **Language(s) (NLP):** [More Information Needed]
|
25 |
+
- **License:** [More Information Needed]
|
26 |
+
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
+
|
28 |
+
### Model Sources [optional]
|
29 |
+
|
30 |
+
<!-- Provide the basic links for the model. -->
|
31 |
+
|
32 |
+
- **Repository:** [More Information Needed]
|
33 |
+
- **Paper [optional]:** [More Information Needed]
|
34 |
+
- **Demo [optional]:** [More Information Needed]
|
35 |
+
|
36 |
+
## Uses
|
37 |
+
|
38 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
+
|
40 |
+
### Direct Use
|
41 |
+
|
42 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
+
|
44 |
+
[More Information Needed]
|
45 |
+
|
46 |
+
### Downstream Use [optional]
|
47 |
+
|
48 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
+
|
50 |
+
[More Information Needed]
|
51 |
+
|
52 |
+
### Out-of-Scope Use
|
53 |
+
|
54 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
+
|
56 |
+
[More Information Needed]
|
57 |
+
|
58 |
+
## Bias, Risks, and Limitations
|
59 |
+
|
60 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
+
|
62 |
+
[More Information Needed]
|
63 |
+
|
64 |
+
### Recommendations
|
65 |
+
|
66 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
+
|
68 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
+
|
70 |
+
## How to Get Started with the Model
|
71 |
+
|
72 |
+
Use the code below to get started with the model.
|
73 |
+
|
74 |
+
[More Information Needed]
|
75 |
+
|
76 |
+
## Training Details
|
77 |
+
|
78 |
+
### Training Data
|
79 |
+
|
80 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
+
|
82 |
+
[More Information Needed]
|
83 |
+
|
84 |
+
### Training Procedure
|
85 |
+
|
86 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
+
|
88 |
+
#### Preprocessing [optional]
|
89 |
+
|
90 |
+
[More Information Needed]
|
91 |
+
|
92 |
+
|
93 |
+
#### Training Hyperparameters
|
94 |
+
|
95 |
+
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
+
|
97 |
+
#### Speeds, Sizes, Times [optional]
|
98 |
+
|
99 |
+
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
+
|
101 |
+
[More Information Needed]
|
102 |
+
|
103 |
+
## Evaluation
|
104 |
+
|
105 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
+
|
107 |
+
### Testing Data, Factors & Metrics
|
108 |
+
|
109 |
+
#### Testing Data
|
110 |
+
|
111 |
+
<!-- This should link to a Dataset Card if possible. -->
|
112 |
+
|
113 |
+
[More Information Needed]
|
114 |
+
|
115 |
+
#### Factors
|
116 |
+
|
117 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
+
|
119 |
+
[More Information Needed]
|
120 |
+
|
121 |
+
#### Metrics
|
122 |
+
|
123 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
+
|
125 |
+
[More Information Needed]
|
126 |
+
|
127 |
+
### Results
|
128 |
+
|
129 |
+
[More Information Needed]
|
130 |
+
|
131 |
+
#### Summary
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
## Model Examination [optional]
|
136 |
+
|
137 |
+
<!-- Relevant interpretability work for the model goes here -->
|
138 |
+
|
139 |
+
[More Information Needed]
|
140 |
+
|
141 |
+
## Environmental Impact
|
142 |
+
|
143 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
+
|
145 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
+
|
147 |
+
- **Hardware Type:** [More Information Needed]
|
148 |
+
- **Hours used:** [More Information Needed]
|
149 |
+
- **Cloud Provider:** [More Information Needed]
|
150 |
+
- **Compute Region:** [More Information Needed]
|
151 |
+
- **Carbon Emitted:** [More Information Needed]
|
152 |
+
|
153 |
+
## Technical Specifications [optional]
|
154 |
+
|
155 |
+
### Model Architecture and Objective
|
156 |
+
|
157 |
+
[More Information Needed]
|
158 |
+
|
159 |
+
### Compute Infrastructure
|
160 |
+
|
161 |
+
[More Information Needed]
|
162 |
+
|
163 |
+
#### Hardware
|
164 |
+
|
165 |
+
[More Information Needed]
|
166 |
+
|
167 |
+
#### Software
|
168 |
+
|
169 |
+
[More Information Needed]
|
170 |
+
|
171 |
+
## Citation [optional]
|
172 |
+
|
173 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
+
|
175 |
+
**BibTeX:**
|
176 |
+
|
177 |
+
[More Information Needed]
|
178 |
+
|
179 |
+
**APA:**
|
180 |
+
|
181 |
+
[More Information Needed]
|
182 |
+
|
183 |
+
## Glossary [optional]
|
184 |
+
|
185 |
+
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
+
|
187 |
+
[More Information Needed]
|
188 |
+
|
189 |
+
## More Information [optional]
|
190 |
+
|
191 |
+
[More Information Needed]
|
192 |
+
|
193 |
+
## Model Card Authors [optional]
|
194 |
+
|
195 |
+
[More Information Needed]
|
196 |
+
|
197 |
+
## Model Card Contact
|
198 |
+
|
199 |
+
[More Information Needed]
|
200 |
+
|
201 |
+
|
special_tokens_map.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "[BOS]",
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"eos_token": "[SEP]",
|
5 |
+
"mask_token": "[MASK]",
|
6 |
+
"pad_token": "[PAD]",
|
7 |
+
"sep_token": "[SEP]",
|
8 |
+
"unk_token": "[UNK]"
|
9 |
+
}
|
tokenization_caduceus.py
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Character tokenizer for Hugging Face.
|
2 |
+
|
3 |
+
"""
|
4 |
+
|
5 |
+
from typing import List, Optional, Dict, Sequence, Tuple
|
6 |
+
|
7 |
+
from transformers import PreTrainedTokenizer
|
8 |
+
|
9 |
+
|
10 |
+
class CaduceusTokenizer(PreTrainedTokenizer):
|
11 |
+
model_input_names = ["input_ids"]
|
12 |
+
|
13 |
+
def __init__(self,
|
14 |
+
model_max_length: int,
|
15 |
+
characters: Sequence[str] = ("A", "C", "G", "T", "N"),
|
16 |
+
complement_map=None,
|
17 |
+
bos_token="[BOS]",
|
18 |
+
eos_token="[SEP]",
|
19 |
+
sep_token="[SEP]",
|
20 |
+
cls_token="[CLS]",
|
21 |
+
pad_token="[PAD]",
|
22 |
+
mask_token="[MASK]",
|
23 |
+
unk_token="[UNK]",
|
24 |
+
**kwargs):
|
25 |
+
"""Character tokenizer for Hugging Face transformers.
|
26 |
+
|
27 |
+
Adapted from https://huggingface.co/LongSafari/hyenadna-tiny-1k-seqlen-hf/blob/main/tokenization_hyena.py
|
28 |
+
Args:
|
29 |
+
model_max_length (int): Model maximum sequence length.
|
30 |
+
characters (Sequence[str]): List of desired characters. Any character which
|
31 |
+
is not included in this list will be replaced by a special token called
|
32 |
+
[UNK] with id=6. Following is a list of the special tokens with
|
33 |
+
their corresponding ids:
|
34 |
+
"[CLS]": 0
|
35 |
+
"[SEP]": 1
|
36 |
+
"[BOS]": 2
|
37 |
+
"[MASK]": 3
|
38 |
+
"[PAD]": 4
|
39 |
+
"[RESERVED]": 5
|
40 |
+
"[UNK]": 6
|
41 |
+
an id (starting at 7) will be assigned to each character.
|
42 |
+
complement_map (Optional[Dict[str, str]]): Dictionary with string complements for each character.
|
43 |
+
"""
|
44 |
+
if complement_map is None:
|
45 |
+
complement_map = {"A": "T", "C": "G", "G": "C", "T": "A", "N": "N"}
|
46 |
+
self.characters = characters
|
47 |
+
self.model_max_length = model_max_length
|
48 |
+
|
49 |
+
self._vocab_str_to_int = {
|
50 |
+
"[CLS]": 0,
|
51 |
+
"[SEP]": 1,
|
52 |
+
"[BOS]": 2,
|
53 |
+
"[MASK]": 3,
|
54 |
+
"[PAD]": 4,
|
55 |
+
"[RESERVED]": 5,
|
56 |
+
"[UNK]": 6,
|
57 |
+
**{ch: i + 7 for i, ch in enumerate(self.characters)},
|
58 |
+
}
|
59 |
+
self._vocab_int_to_str = {v: k for k, v in self._vocab_str_to_int.items()}
|
60 |
+
add_prefix_space = kwargs.pop("add_prefix_space", False)
|
61 |
+
padding_side = kwargs.pop("padding_side", "left")
|
62 |
+
|
63 |
+
self._complement_map = {}
|
64 |
+
for k, v in self._vocab_str_to_int.items():
|
65 |
+
complement_id = self._vocab_str_to_int[complement_map[k]] if k in complement_map.keys() else v
|
66 |
+
self._complement_map[self._vocab_str_to_int[k]] = complement_id
|
67 |
+
|
68 |
+
super().__init__(
|
69 |
+
bos_token=bos_token,
|
70 |
+
eos_token=eos_token,
|
71 |
+
sep_token=sep_token,
|
72 |
+
cls_token=cls_token,
|
73 |
+
pad_token=pad_token,
|
74 |
+
mask_token=mask_token,
|
75 |
+
unk_token=unk_token,
|
76 |
+
add_prefix_space=add_prefix_space,
|
77 |
+
model_max_length=model_max_length,
|
78 |
+
padding_side=padding_side,
|
79 |
+
**kwargs,
|
80 |
+
)
|
81 |
+
|
82 |
+
@property
|
83 |
+
def vocab_size(self) -> int:
|
84 |
+
return len(self._vocab_str_to_int)
|
85 |
+
|
86 |
+
@property
|
87 |
+
def complement_map(self) -> Dict[int, int]:
|
88 |
+
return self._complement_map
|
89 |
+
|
90 |
+
def _tokenize(self, text: str, **kwargs) -> List[str]:
|
91 |
+
return list(text.upper()) # Convert all base pairs to uppercase
|
92 |
+
|
93 |
+
def _convert_token_to_id(self, token: str) -> int:
|
94 |
+
return self._vocab_str_to_int.get(token, self._vocab_str_to_int["[UNK]"])
|
95 |
+
|
96 |
+
def _convert_id_to_token(self, index: int) -> str:
|
97 |
+
return self._vocab_int_to_str[index]
|
98 |
+
|
99 |
+
def convert_tokens_to_string(self, tokens):
|
100 |
+
return "".join(tokens) # Note: this operation has lost info about which base pairs were originally lowercase
|
101 |
+
|
102 |
+
def get_special_tokens_mask(
|
103 |
+
self,
|
104 |
+
token_ids_0: List[int],
|
105 |
+
token_ids_1: Optional[List[int]] = None,
|
106 |
+
already_has_special_tokens: bool = False,
|
107 |
+
) -> List[int]:
|
108 |
+
if already_has_special_tokens:
|
109 |
+
return super().get_special_tokens_mask(
|
110 |
+
token_ids_0=token_ids_0,
|
111 |
+
token_ids_1=token_ids_1,
|
112 |
+
already_has_special_tokens=True,
|
113 |
+
)
|
114 |
+
|
115 |
+
result = ([0] * len(token_ids_0)) + [1]
|
116 |
+
if token_ids_1 is not None:
|
117 |
+
result += ([0] * len(token_ids_1)) + [1]
|
118 |
+
return result
|
119 |
+
|
120 |
+
def build_inputs_with_special_tokens(
|
121 |
+
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
|
122 |
+
) -> List[int]:
|
123 |
+
sep = [self.sep_token_id]
|
124 |
+
# cls = [self.cls_token_id]
|
125 |
+
result = token_ids_0 + sep
|
126 |
+
if token_ids_1 is not None:
|
127 |
+
result += token_ids_1 + sep
|
128 |
+
return result
|
129 |
+
|
130 |
+
def get_vocab(self) -> Dict[str, int]:
|
131 |
+
return self._vocab_str_to_int
|
132 |
+
|
133 |
+
# Fixed vocabulary with no vocab file
|
134 |
+
def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple:
|
135 |
+
return ()
|
tokenizer_config.json
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"0": {
|
5 |
+
"content": "[CLS]",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": false,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"1": {
|
13 |
+
"content": "[SEP]",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": false,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"2": {
|
21 |
+
"content": "[BOS]",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": false,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"content": "[MASK]",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": false,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
},
|
36 |
+
"4": {
|
37 |
+
"content": "[PAD]",
|
38 |
+
"lstrip": false,
|
39 |
+
"normalized": false,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false,
|
42 |
+
"special": true
|
43 |
+
},
|
44 |
+
"6": {
|
45 |
+
"content": "[UNK]",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": false,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false,
|
50 |
+
"special": true
|
51 |
+
}
|
52 |
+
},
|
53 |
+
"auto_map": {
|
54 |
+
"AutoTokenizer": [
|
55 |
+
"tokenization_caduceus.CaduceusTokenizer",
|
56 |
+
null
|
57 |
+
]
|
58 |
+
},
|
59 |
+
"bos_token": "[BOS]",
|
60 |
+
"clean_up_tokenization_spaces": true,
|
61 |
+
"cls_token": "[CLS]",
|
62 |
+
"eos_token": "[SEP]",
|
63 |
+
"mask_token": "[MASK]",
|
64 |
+
"model_max_length": 131072,
|
65 |
+
"pad_token": "[PAD]",
|
66 |
+
"padding_side": "left",
|
67 |
+
"sep_token": "[SEP]",
|
68 |
+
"tokenizer_class": "CaduceusTokenizer",
|
69 |
+
"unk_token": "[UNK]"
|
70 |
+
}
|