def test_tokens_to_ids(self, test_data_dir): tokenizer = YouTokenToMeTokenizer(test_data_dir + self.model_name) tokens = [ "<BOS>", "a", "b", "c", "<UNK>", "e", "f", "<UNK>", "g", "h", "i", "<EOS>" ] ids = tokenizer.tokens_to_ids(tokens) assert len(ids) == len(tokens) assert ids.count(tokenizer.bos_id) == 1 assert ids.count(tokenizer.eos_id) == 1 assert ids.count(tokenizer.unk_id) == 2
def test_ids_to_tokens(self, test_data_dir): tokenizer = YouTokenToMeTokenizer(test_data_dir + self.model_name) tokens = [ "<BOS>", "a", "b", "c", "<UNK>", "e", "f", "<UNK>", "g", "h", "i", "<EOS>" ] ids = tokenizer.tokens_to_ids(tokens) result = tokenizer.ids_to_tokens(ids) assert len(result) == len(tokens) for i in range(len(result)): assert result[i] == tokens[i]