Construct a Moss tokenizer. Based on byte-level Byte-Pair-Encoding. This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will be encoded differently whether it is at the beginning of the sentence (without space) or not: You
| 98 | |
| 99 | |
| 100 | class MossTokenizer(PreTrainedTokenizer): |
| 101 | """ |
| 102 | Construct a Moss tokenizer. Based on byte-level Byte-Pair-Encoding. |
| 103 | |
| 104 | This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will |
| 105 | be encoded differently whether it is at the beginning of the sentence (without space) or not: |
| 106 | |
| 107 | You can get around that behavior by passing `add_prefix_space=True` when instantiating this tokenizer or when you |
| 108 | call it on some text, but since the model was not pretrained this way, it might yield a decrease in performance. |
| 109 | |
| 110 | <Tip> |
| 111 | |
| 112 | When used with `is_split_into_words=True`, this tokenizer will add a space before each word (even the first one). |
| 113 | |
| 114 | </Tip> |
| 115 | |
| 116 | This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to |
| 117 | this superclass for more information regarding those methods. |
| 118 | |
| 119 | Args: |
| 120 | vocab_file (`str`): |
| 121 | Path to the vocabulary file. |
| 122 | merges_file (`str`): |
| 123 | Path to the merges file. |
| 124 | errors (`str`, *optional*, defaults to `"replace"`): |
| 125 | Paradigm to follow when decoding bytes to UTF-8. See |
| 126 | [bytes.decode](https://docs.python.org/3/library/stdtypes.html#bytes.decode) for more information. |
| 127 | unk_token (`str`, *optional*, defaults to `<|endoftext|>`): |
| 128 | The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this |
| 129 | token instead. |
| 130 | bos_token (`str`, *optional*, defaults to `<|endoftext|>`): |
| 131 | The beginning of sequence token. |
| 132 | eos_token (`str`, *optional*, defaults to `<|endoftext|>`): |
| 133 | The end of sequence token. |
| 134 | add_prefix_space (`bool`, *optional*, defaults to `False`): |
| 135 | Whether or not to add an initial space to the input. This allows to treat the leading word just as any |
| 136 | other word. (Moss tokenizer detect beginning of words by the preceding space). |
| 137 | """ |
| 138 | |
| 139 | vocab_files_names = VOCAB_FILES_NAMES |
| 140 | pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP |
| 141 | max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES |
| 142 | model_input_names = ["input_ids", "attention_mask"] |
| 143 | |
| 144 | def __init__( |
| 145 | self, |
| 146 | vocab_file, |
| 147 | merges_file, |
| 148 | errors="replace", |
| 149 | unk_token="<|endoftext|>", |
| 150 | bos_token="<|endoftext|>", |
| 151 | eos_token="<eom>", |
| 152 | pad_token=None, |
| 153 | add_prefix_space=False, |
| 154 | add_bos_token=False, |
| 155 | **kwargs, |
| 156 | ): |
| 157 | bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token |
nothing calls this directly
no outgoing calls
no test coverage detected