Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```python
|
2 |
+
import tempfile
|
3 |
+
|
4 |
+
from tokenizers import Tokenizer, models, processors
|
5 |
+
from transformers.tokenization_utils_fast import PreTrainedTokenizerFast
|
6 |
+
|
7 |
+
vocab = [(chr(i), i) for i in range(256)]
|
8 |
+
tokenizer = Tokenizer(models.Unigram(vocab))
|
9 |
+
tokenizer.add_special_tokens(["<bos>", "<eos>"])
|
10 |
+
tokenizer.post_processor = processors.TemplateProcessing(
|
11 |
+
single="<bos> $0 <eos>", special_tokens=[("<bos>", 256), ("<eos>", 257)]
|
12 |
+
)
|
13 |
+
with tempfile.NamedTemporaryFile() as f:
|
14 |
+
tokenizer.save(f.name)
|
15 |
+
real_tokenizer = PreTrainedTokenizerFast(tokenizer_file=f.name, eos_token="<eos>", bos_token="<bos>")
|
16 |
+
|
17 |
+
real_tokenizer._tokenizer.save("dummy.json")
|
18 |
+
```
|