(self)
| 27 | tokenizer_class = CTRLTokenizer |
| 28 | |
| 29 | def setUp(self): |
| 30 | super().setUp() |
| 31 | |
| 32 | # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt |
| 33 | vocab = ["adapt", "re@@", "a@@", "apt", "c@@", "t", "<unk>"] |
| 34 | vocab_tokens = dict(zip(vocab, range(len(vocab)))) |
| 35 | merges = ["#version: 0.2", "a p", "ap t</w>", "r e", "a d", "ad apt</w>", ""] |
| 36 | self.special_tokens_map = {"unk_token": "<unk>"} |
| 37 | |
| 38 | self.vocab_file = os.path.join(self.tmpdirname, VOCAB_FILES_NAMES["vocab_file"]) |
| 39 | self.merges_file = os.path.join(self.tmpdirname, VOCAB_FILES_NAMES["merges_file"]) |
| 40 | with open(self.vocab_file, "w", encoding="utf-8") as fp: |
| 41 | fp.write(json.dumps(vocab_tokens) + "\n") |
| 42 | with open(self.merges_file, "w", encoding="utf-8") as fp: |
| 43 | fp.write("\n".join(merges)) |
| 44 | |
| 45 | def get_tokenizer(self, **kwargs): |
| 46 | kwargs.update(self.special_tokens_map) |
nothing calls this directly
no outgoing calls
no test coverage detected