GinnM commited on
Commit
7443ad7
·
verified ·
1 Parent(s): 86e6569

Upload tokenizer

Browse files
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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]
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "<cls>",
3
+ "eos_token": "<eos>",
4
+ "mask_token": "<mask>",
5
+ "pad_token": "<pad>",
6
+ "unk_token": "<unk>"
7
+ }
tokenization_thermoformer.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import List, Optional
3
+ from pathlib import Path
4
+ from transformers.tokenization_utils import PreTrainedTokenizer
5
+ from transformers.utils import logging
6
+
7
+
8
+ logger = logging.get_logger(__name__)
9
+
10
+ VOCAB_FILES_NAMES = {"vocab_file": "vocab.txt"}
11
+
12
+
13
+ def load_vocab_file(vocab_file):
14
+ with open(vocab_file, "r") as f:
15
+ lines = f.read().splitlines()
16
+ return [l.strip() for l in lines]
17
+
18
+
19
+ class ThermoFormerTokenizer(PreTrainedTokenizer):
20
+ vocab_files_names = VOCAB_FILES_NAMES
21
+ model_input_names = ["input_ids", "attention_mask"]
22
+
23
+ def __init__(
24
+ self,
25
+ vocab_file=None,
26
+ unk_token="<unk>",
27
+ cls_token="<cls>",
28
+ pad_token="<pad>",
29
+ mask_token="<mask>",
30
+ eos_token="<eos>",
31
+ **kwargs,
32
+ ):
33
+ if vocab_file is None:
34
+ vocab_file = Path(__file__).parent / "vocab.txt"
35
+ self.all_tokens = load_vocab_file(vocab_file)
36
+ self._id_to_token = dict(enumerate(self.all_tokens))
37
+ self._token_to_id = {tok: ind for ind, tok in enumerate(self.all_tokens)}
38
+ super().__init__(
39
+ unk_token=unk_token,
40
+ cls_token=cls_token,
41
+ pad_token=pad_token,
42
+ mask_token=mask_token,
43
+ eos_token=eos_token,
44
+ **kwargs,
45
+ )
46
+
47
+ # TODO, all the tokens are added? But they are also part of the vocab... bit strange.
48
+ # none of them are special, but they all need special splitting.
49
+
50
+ self.unique_no_split_tokens = self.all_tokens
51
+ self._update_trie(self.unique_no_split_tokens)
52
+
53
+ def _convert_id_to_token(self, index: int) -> str:
54
+ return self._id_to_token.get(index, self.unk_token)
55
+
56
+ def _convert_token_to_id(self, token: str) -> int:
57
+ return self._token_to_id.get(token, self._token_to_id.get(self.unk_token))
58
+
59
+ def _tokenize(self, text, **kwargs):
60
+ return text.split()
61
+
62
+ def get_vocab(self):
63
+ base_vocab = self._token_to_id.copy()
64
+ base_vocab.update(self.added_tokens_encoder)
65
+ return base_vocab
66
+
67
+ def token_to_id(self, token: str) -> int:
68
+ return self._token_to_id.get(token, self._token_to_id.get(self.unk_token))
69
+
70
+ def id_to_token(self, index: int) -> str:
71
+ return self._id_to_token.get(index, self.unk_token)
72
+
73
+ def build_inputs_with_special_tokens(
74
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
75
+ ) -> List[int]:
76
+ cls = [self.cls_token_id]
77
+ sep = [self.eos_token_id]
78
+ if token_ids_1 is None:
79
+ if self.eos_token_id is None:
80
+ return cls + token_ids_0
81
+ else:
82
+ return cls + token_ids_0 + sep
83
+ elif self.eos_token_id is None:
84
+ raise ValueError(
85
+ "Cannot tokenize multiple sequences when EOS token is not set!"
86
+ )
87
+ return (
88
+ cls + token_ids_0 + sep + token_ids_1 + sep
89
+ ) # Multiple inputs always have an EOS token
90
+
91
+ def get_special_tokens_mask(
92
+ self,
93
+ token_ids_0: List,
94
+ token_ids_1: Optional[List] = None,
95
+ already_has_special_tokens: bool = False,
96
+ ) -> List[int]:
97
+ """
98
+ Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding
99
+ special tokens using the tokenizer `prepare_for_model` or `encode_plus` methods.
100
+
101
+ Args:
102
+ token_ids_0 (`List[int]`):
103
+ List of ids of the first sequence.
104
+ token_ids_1 (`List[int]`, *optional*):
105
+ List of ids of the second sequence.
106
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
107
+ Whether or not the token list is already formatted with special tokens for the model.
108
+
109
+ Returns:
110
+ A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
111
+ """
112
+ if already_has_special_tokens:
113
+ if token_ids_1 is not None:
114
+ raise ValueError(
115
+ "You should not supply a second sequence if the provided sequence of "
116
+ "ids is already formatted with special tokens for the model."
117
+ )
118
+
119
+ return [1 if token in self.all_special_ids else 0 for token in token_ids_0]
120
+ mask = [1] + ([0] * len(token_ids_0)) + [1]
121
+ if token_ids_1 is not None:
122
+ mask += [0] * len(token_ids_1) + [1]
123
+ return mask
124
+
125
+ def save_vocabulary(self, save_directory, filename_prefix):
126
+ vocab_file = os.path.join(
127
+ save_directory,
128
+ (filename_prefix + "-" if filename_prefix else "") + "vocab.txt",
129
+ )
130
+ with open(vocab_file, "w") as f:
131
+ f.write("\n".join(self.all_tokens))
132
+ return (vocab_file,)
133
+
134
+ @property
135
+ def vocab_size(self) -> int:
136
+ return len(self.all_tokens)
137
+
138
+
139
+ ThermoFormerTokenizer.register_for_auto_class("AutoTokenizer")
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<cls>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "<eos>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "32": {
36
+ "content": "<mask>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "auto_map": {
45
+ "AutoTokenizer": [
46
+ "tokenization_thermoformer.ThermoFormerTokenizer",
47
+ null
48
+ ]
49
+ },
50
+ "clean_up_tokenization_spaces": false,
51
+ "cls_token": "<cls>",
52
+ "eos_token": "<eos>",
53
+ "mask_token": "<mask>",
54
+ "model_max_length": 1000000000000000019884624838656,
55
+ "pad_token": "<pad>",
56
+ "tokenizer_class": "ThermoFormerTokenizer",
57
+ "unk_token": "<unk>"
58
+ }
vocab.txt ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <cls>
2
+ <pad>
3
+ <eos>
4
+ <unk>
5
+ L
6
+ A
7
+ G
8
+ V
9
+ S
10
+ E
11
+ R
12
+ T
13
+ I
14
+ D
15
+ P
16
+ K
17
+ Q
18
+ N
19
+ F
20
+ Y
21
+ M
22
+ H
23
+ W
24
+ C
25
+ X
26
+ B
27
+ U
28
+ Z
29
+ O
30
+ .
31
+ -
32
+ <null_1>
33
+ <mask>