-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtokenization_mflag.py
44 lines (33 loc) · 1.43 KB
/
tokenization_mflag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding:utf-8 _*-
"""
Most code for this implementation is borrowed from transformers
"""
from transformers import logging, BartTokenizer
from transformers import BartTokenizerFast
logger = logging.get_logger(__name__)
VOCAB_FILES_NAMES = {"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}
# See all BART models at https://huggingface.co/models?filter=bart
PRETRAINED_VOCAB_FILES_MAP = {
"vocab_file": {
"laihuiyuan/mFLAG": "https://huggingface.co/laihuiyuan/mFLAG/resolve/main/vocab.json",
},
"merges_file": {
"laihuiyuan/mFLAG": "https://huggingface.co/laihuiyuan/mFLAG/resolve/main/merges.txt",
},
"tokenizer_file": {
"laihuiyuan/mFLAG": "https://huggingface.co/laihuiyuan/mFLAG/resolve/main/tokenizer.json",
},
}
PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {
"laihuiyuan/mFLAG": 1024,
}
class MFlagTokenizerFast(BartTokenizerFast):
r"""
Construct an mFLAG tokenizer based on BartTokenizerFast. [`MFlagTokenizerFast`] is the
same as [`BartTokenizerFast`] with the addition of six figurative codes to the vocabulary.
{50265:<literal>, 50266:<hyperbole>, 50267:<idiom>, 50268:<sarcasm>, 50269:<metaphor>, 50270:<simile>}
"""
vocab_files_names = VOCAB_FILES_NAMES
pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
slow_tokenizer_class = BartTokenizer