lyua1225 commited on
Commit
54ba542
1 Parent(s): 5dd8b14

Upload 9 files

Browse files
added_tokens.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
clip_tokenizer_roberta.py ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.models.bert.tokenization_bert import *
2
+ import os
3
+
4
+
5
+ class CLIPTokenizerRoberta(PreTrainedTokenizer):
6
+ r"""
7
+ Construct a BERT tokenizer. Based on WordPiece.
8
+
9
+ This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to
10
+ this superclass for more information regarding those methods.
11
+
12
+ Args:
13
+ vocab_file (`str`):
14
+ File containing the vocabulary.
15
+ do_lower_case (`bool`, *optional*, defaults to `True`):
16
+ Whether or not to lowercase the input when tokenizing.
17
+ do_basic_tokenize (`bool`, *optional*, defaults to `True`):
18
+ Whether or not to do basic tokenization before WordPiece.
19
+ never_split (`Iterable`, *optional*):
20
+ Collection of tokens which will never be split during tokenization. Only has an effect when
21
+ `do_basic_tokenize=True`
22
+ unk_token (`str`, *optional*, defaults to `"[UNK]"`):
23
+ The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
24
+ token instead.
25
+ sep_token (`str`, *optional*, defaults to `"[SEP]"`):
26
+ The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
27
+ sequence classification or for a text and a question for question answering. It is also used as the last
28
+ token of a sequence built with special tokens.
29
+ pad_token (`str`, *optional*, defaults to `"[PAD]"`):
30
+ The token used for padding, for example when batching sequences of different lengths.
31
+ cls_token (`str`, *optional*, defaults to `"[CLS]"`):
32
+ The classifier token which is used when doing sequence classification (classification of the whole sequence
33
+ instead of per-token classification). It is the first token of the sequence when built with special tokens.
34
+ mask_token (`str`, *optional*, defaults to `"[MASK]"`):
35
+ The token used for masking values. This is the token used when training this model with masked language
36
+ modeling. This is the token which the model will try to predict.
37
+ tokenize_chinese_chars (`bool`, *optional*, defaults to `True`):
38
+ Whether or not to tokenize Chinese characters.
39
+
40
+ This should likely be deactivated for Japanese (see this
41
+ [issue](https://github.com/huggingface/transformers/issues/328)).
42
+ strip_accents (`bool`, *optional*):
43
+ Whether or not to strip all accents. If this option is not specified, then it will be determined by the
44
+ value for `lowercase` (as in the original BERT).
45
+ """
46
+
47
+ vocab_files_names = VOCAB_FILES_NAMES
48
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
49
+ pretrained_init_configuration = PRETRAINED_INIT_CONFIGURATION
50
+ max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
51
+
52
+ def __init__(
53
+ self,
54
+ vocab_file,
55
+ do_lower_case=True,
56
+ do_basic_tokenize=True,
57
+ never_split=None,
58
+ unk_token="[UNK]",
59
+ sep_token="[SEP]",
60
+ pad_token="[PAD]",
61
+ cls_token="[CLS]",
62
+ mask_token="[MASK]",
63
+ tokenize_chinese_chars=True,
64
+ strip_accents=None,
65
+ **kwargs
66
+ ):
67
+ super().__init__(
68
+ do_lower_case=do_lower_case,
69
+ do_basic_tokenize=do_basic_tokenize,
70
+ never_split=never_split,
71
+ unk_token=unk_token,
72
+ sep_token=sep_token,
73
+ pad_token=pad_token,
74
+ cls_token=cls_token,
75
+ mask_token=mask_token,
76
+ tokenize_chinese_chars=tokenize_chinese_chars,
77
+ strip_accents=strip_accents,
78
+ **kwargs,
79
+ )
80
+
81
+ if not os.path.isfile(vocab_file):
82
+ raise ValueError(
83
+ f"Can't find a vocabulary file at path '{vocab_file}'. To load the vocabulary from a Google pretrained"
84
+ " model use `tokenizer = BertTokenizer.from_pretrained(PRETRAINED_MODEL_NAME)`"
85
+ )
86
+ self.vocab = load_vocab(vocab_file)
87
+ self.ids_to_tokens = collections.OrderedDict([(ids, tok) for tok, ids in self.vocab.items()])
88
+ self.do_basic_tokenize = do_basic_tokenize
89
+ if do_basic_tokenize:
90
+ self.basic_tokenizer = BasicTokenizer(
91
+ do_lower_case=do_lower_case,
92
+ never_split=never_split,
93
+ tokenize_chinese_chars=tokenize_chinese_chars,
94
+ strip_accents=strip_accents,
95
+ )
96
+ self.wordpiece_tokenizer = WordpieceTokenizer(vocab=self.vocab, unk_token=self.unk_token)
97
+
98
+ @property
99
+ def do_lower_case(self):
100
+ return self.basic_tokenizer.do_lower_case
101
+
102
+ @property
103
+ def vocab_size(self):
104
+ return len(self.vocab)
105
+
106
+ def get_vocab(self):
107
+ return dict(self.vocab, **self.added_tokens_encoder)
108
+
109
+ def _tokenize(self, text):
110
+ split_tokens = []
111
+ if self.do_basic_tokenize:
112
+ for token in self.basic_tokenizer.tokenize(text, never_split=self.all_special_tokens):
113
+
114
+ # If the token is part of the never_split set
115
+ if token in self.basic_tokenizer.never_split:
116
+ split_tokens.append(token)
117
+ else:
118
+ split_tokens += self.wordpiece_tokenizer.tokenize(token)
119
+ else:
120
+ split_tokens = self.wordpiece_tokenizer.tokenize(text)
121
+ return split_tokens
122
+
123
+ def _convert_token_to_id(self, token):
124
+ """Converts a token (str) in an id using the vocab."""
125
+ return self.vocab.get(token, self.vocab.get(self.unk_token))
126
+
127
+ def _convert_id_to_token(self, index):
128
+ """Converts an index (integer) in a token (str) using the vocab."""
129
+ return self.ids_to_tokens.get(index, self.unk_token)
130
+
131
+ def convert_tokens_to_string(self, tokens):
132
+ """Converts a sequence of tokens (string) in a single string."""
133
+ out_string = " ".join(tokens).replace(" ##", "").strip()
134
+ return out_string
135
+
136
+ def build_inputs_with_special_tokens(
137
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
138
+ ) -> List[int]:
139
+ """
140
+ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
141
+ adding special tokens. A BERT sequence has the following format:
142
+
143
+ - single sequence: `[CLS] X [SEP]`
144
+ - pair of sequences: `[CLS] A [SEP] B [SEP]`
145
+
146
+ Args:
147
+ token_ids_0 (`List[int]`):
148
+ List of IDs to which the special tokens will be added.
149
+ token_ids_1 (`List[int]`, *optional*):
150
+ Optional second list of IDs for sequence pairs.
151
+
152
+ Returns:
153
+ `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
154
+ """
155
+ sep = [49407]
156
+ cls = [49406]
157
+
158
+ if token_ids_1 is None:
159
+ return cls + token_ids_0 + sep
160
+ # return [self.cls_token_id] + token_ids_0 + [self.sep_token_id]
161
+ # cls = [self.cls_token_id]
162
+ # sep = [self.sep_token_id]
163
+
164
+ return cls + token_ids_0 + sep + token_ids_1 + sep
165
+
166
+ def get_special_tokens_mask(
167
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None,
168
+ already_has_special_tokens: bool = False
169
+ ) -> List[int]:
170
+ """
171
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
172
+ special tokens using the tokenizer `prepare_for_model` method.
173
+
174
+ Args:
175
+ token_ids_0 (`List[int]`):
176
+ List of IDs.
177
+ token_ids_1 (`List[int]`, *optional*):
178
+ Optional second list of IDs for sequence pairs.
179
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
180
+ Whether or not the token list is already formatted with special tokens for the model.
181
+
182
+ Returns:
183
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
184
+ """
185
+
186
+ if already_has_special_tokens:
187
+ return super().get_special_tokens_mask(
188
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
189
+ )
190
+
191
+ if token_ids_1 is not None:
192
+ return [1] + ([0] * len(token_ids_0)) + [1] + ([0] * len(token_ids_1)) + [1]
193
+ return [1] + ([0] * len(token_ids_0)) + [1]
194
+
195
+ def create_token_type_ids_from_sequences(
196
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
197
+ ) -> List[int]:
198
+ """
199
+ Create a mask from the two sequences passed to be used in a sequence-pair classification task. A BERT sequence
200
+ pair mask has the following format:
201
+
202
+ ```
203
+ 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
204
+ | first sequence | second sequence |
205
+ ```
206
+
207
+ If `token_ids_1` is `None`, this method only returns the first portion of the mask (0s).
208
+
209
+ Args:
210
+ token_ids_0 (`List[int]`):
211
+ List of IDs.
212
+ token_ids_1 (`List[int]`, *optional*):
213
+ Optional second list of IDs for sequence pairs.
214
+
215
+ Returns:
216
+ `List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s).
217
+ """
218
+ # sep = [self.sep_token_id]
219
+ # cls = [self.cls_token_id]
220
+ sep = [49407]
221
+ cls = [49406]
222
+ if token_ids_1 is None:
223
+ return len(cls + token_ids_0 + sep) * [0]
224
+ return len(cls + token_ids_0 + sep) * [0] + len(token_ids_1 + sep) * [1]
225
+
226
+ def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
227
+ index = 0
228
+ if os.path.isdir(save_directory):
229
+ vocab_file = os.path.join(
230
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
231
+ )
232
+ else:
233
+ vocab_file = (filename_prefix + "-" if filename_prefix else "") + save_directory
234
+ with open(vocab_file, "w", encoding="utf-8") as writer:
235
+ for token, token_index in sorted(self.vocab.items(), key=lambda kv: kv[1]):
236
+ if index != token_index:
237
+ logger.warning(
238
+ f"Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive."
239
+ " Please check that the vocabulary is not corrupted!"
240
+ )
241
+ index = token_index
242
+ writer.write(token + "\n")
243
+ index += 1
244
+ return (vocab_file,)
245
+
246
+
config.json ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_commit_hash": "58a1e03a7acfacbe6b95ebc24ae0394eda6a14fc",
3
+ "_name_or_path": "laion/CLIP-ViT-H-14-laion2B-s32B-b79K",
4
+ "architectures": [
5
+ "CLIPModel"
6
+ ],
7
+ "initializer_factor": 1.0,
8
+ "logit_scale_init_value": 2.6592,
9
+ "model_type": "clip",
10
+ "projection_dim": 1024,
11
+ "text_config": {
12
+ "_name_or_path": "",
13
+ "add_cross_attention": false,
14
+ "architectures": null,
15
+ "attention_dropout": 0.0,
16
+ "bad_words_ids": null,
17
+ "begin_suppress_tokens": null,
18
+ "bos_token_id": 0,
19
+ "chunk_size_feed_forward": 0,
20
+ "cross_attention_hidden_size": null,
21
+ "decoder_start_token_id": null,
22
+ "diversity_penalty": 0.0,
23
+ "do_sample": false,
24
+ "dropout": 0.0,
25
+ "early_stopping": false,
26
+ "encoder_no_repeat_ngram_size": 0,
27
+ "eos_token_id": 2,
28
+ "exponential_decay_length_penalty": null,
29
+ "finetuning_task": null,
30
+ "forced_bos_token_id": null,
31
+ "forced_eos_token_id": null,
32
+ "hidden_act": "gelu",
33
+ "hidden_size": 1024,
34
+ "id2label": {
35
+ "0": "LABEL_0",
36
+ "1": "LABEL_1"
37
+ },
38
+ "initializer_factor": 1.0,
39
+ "initializer_range": 0.02,
40
+ "intermediate_size": 4096,
41
+ "is_decoder": false,
42
+ "is_encoder_decoder": false,
43
+ "label2id": {
44
+ "LABEL_0": 0,
45
+ "LABEL_1": 1
46
+ },
47
+ "layer_norm_eps": 1e-05,
48
+ "length_penalty": 1.0,
49
+ "max_length": 20,
50
+ "max_position_embeddings": 77,
51
+ "min_length": 0,
52
+ "model_type": "clip_text_model",
53
+ "no_repeat_ngram_size": 0,
54
+ "num_attention_heads": 16,
55
+ "num_beam_groups": 1,
56
+ "num_beams": 1,
57
+ "num_hidden_layers": 24,
58
+ "num_return_sequences": 1,
59
+ "output_attentions": false,
60
+ "output_hidden_states": false,
61
+ "output_scores": false,
62
+ "pad_token_id": 1,
63
+ "prefix": null,
64
+ "problem_type": null,
65
+ "pruned_heads": {},
66
+ "remove_invalid_values": false,
67
+ "repetition_penalty": 1.0,
68
+ "return_dict": true,
69
+ "return_dict_in_generate": false,
70
+ "sep_token_id": null,
71
+ "suppress_tokens": null,
72
+ "task_specific_params": null,
73
+ "temperature": 1.0,
74
+ "tf_legacy_loss": false,
75
+ "tie_encoder_decoder": false,
76
+ "tie_word_embeddings": true,
77
+ "tokenizer_class": null,
78
+ "top_k": 50,
79
+ "top_p": 1.0,
80
+ "torch_dtype": null,
81
+ "torchscript": false,
82
+ "transformers_version": "4.23.1",
83
+ "typical_p": 1.0,
84
+ "use_bfloat16": false,
85
+ "vocab_size": 49408
86
+ },
87
+ "text_config_dict": {
88
+ "hidden_act": "gelu",
89
+ "hidden_size": 1024,
90
+ "intermediate_size": 4096,
91
+ "num_attention_heads": 16,
92
+ "num_hidden_layers": 24
93
+ },
94
+ "torch_dtype": "float32",
95
+ "transformers_version": null,
96
+ "vision_config": {
97
+ "_name_or_path": "",
98
+ "add_cross_attention": false,
99
+ "architectures": null,
100
+ "attention_dropout": 0.0,
101
+ "bad_words_ids": null,
102
+ "begin_suppress_tokens": null,
103
+ "bos_token_id": null,
104
+ "chunk_size_feed_forward": 0,
105
+ "cross_attention_hidden_size": null,
106
+ "decoder_start_token_id": null,
107
+ "diversity_penalty": 0.0,
108
+ "do_sample": false,
109
+ "dropout": 0.0,
110
+ "early_stopping": false,
111
+ "encoder_no_repeat_ngram_size": 0,
112
+ "eos_token_id": null,
113
+ "exponential_decay_length_penalty": null,
114
+ "finetuning_task": null,
115
+ "forced_bos_token_id": null,
116
+ "forced_eos_token_id": null,
117
+ "hidden_act": "gelu",
118
+ "hidden_size": 1280,
119
+ "id2label": {
120
+ "0": "LABEL_0",
121
+ "1": "LABEL_1"
122
+ },
123
+ "image_size": 224,
124
+ "initializer_factor": 1.0,
125
+ "initializer_range": 0.02,
126
+ "intermediate_size": 5120,
127
+ "is_decoder": false,
128
+ "is_encoder_decoder": false,
129
+ "label2id": {
130
+ "LABEL_0": 0,
131
+ "LABEL_1": 1
132
+ },
133
+ "layer_norm_eps": 1e-05,
134
+ "length_penalty": 1.0,
135
+ "max_length": 20,
136
+ "min_length": 0,
137
+ "model_type": "clip_vision_model",
138
+ "no_repeat_ngram_size": 0,
139
+ "num_attention_heads": 16,
140
+ "num_beam_groups": 1,
141
+ "num_beams": 1,
142
+ "num_channels": 3,
143
+ "num_hidden_layers": 32,
144
+ "num_return_sequences": 1,
145
+ "output_attentions": false,
146
+ "output_hidden_states": false,
147
+ "output_scores": false,
148
+ "pad_token_id": null,
149
+ "patch_size": 14,
150
+ "prefix": null,
151
+ "problem_type": null,
152
+ "pruned_heads": {},
153
+ "remove_invalid_values": false,
154
+ "repetition_penalty": 1.0,
155
+ "return_dict": true,
156
+ "return_dict_in_generate": false,
157
+ "sep_token_id": null,
158
+ "suppress_tokens": null,
159
+ "task_specific_params": null,
160
+ "temperature": 1.0,
161
+ "tf_legacy_loss": false,
162
+ "tie_encoder_decoder": false,
163
+ "tie_word_embeddings": true,
164
+ "tokenizer_class": null,
165
+ "top_k": 50,
166
+ "top_p": 1.0,
167
+ "torch_dtype": null,
168
+ "torchscript": false,
169
+ "transformers_version": "4.23.1",
170
+ "typical_p": 1.0,
171
+ "use_bfloat16": false
172
+ },
173
+ "vision_config_dict": {
174
+ "hidden_act": "gelu",
175
+ "hidden_size": 1280,
176
+ "intermediate_size": 5120,
177
+ "num_attention_heads": 16,
178
+ "num_hidden_layers": 32,
179
+ "patch_size": 14
180
+ }
181
+ }
preprocessor_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": 224,
3
+ "do_center_crop": true,
4
+ "do_convert_rgb": true,
5
+ "do_normalize": true,
6
+ "do_resize": true,
7
+ "feature_extractor_type": "CLIPFeatureExtractor",
8
+ "image_mean": [
9
+ 0.48145466,
10
+ 0.4578275,
11
+ 0.40821073
12
+ ],
13
+ "image_std": [
14
+ 0.26862954,
15
+ 0.26130258,
16
+ 0.27577711
17
+ ],
18
+ "resample": 3,
19
+ "size": 224
20
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a74f702c5989af46ad56722c97444f6d70d666918d13ae8a4d6ee5853f772eb7
3
+ size 3944812955
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+
3
+ "cls_token": "[CLS]",
4
+ "mask_token": "[MASK]",
5
+ "unk_token": "[UNK]",
6
+ "tokenizer_class": "CLIPTokenizerRoberta",
7
+ "use_fast": true,
8
+ "auto_map": {
9
+ "AutoTokenizer": [
10
+ "clip_tokenizer_roberta.CLIPTokenizerRoberta",
11
+ null
12
+ ]
13
+ }
14
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff