Add BlenderbotTokenizerFast (#13720)
* Add the support for the fast (rust) implementation of BlenbderbotTokenizer * Fix a converter and a typo in a doc * Apply the patil-suraj's suggestion * (Nitpick) Fast tokenization -> Fast Tokenization in doc * Apply the SaulLu's suggestion * Apply Narsil's suggestion to fix test pipelines * Add encoder_no_repeat_ngram_size according to the Narsil's suggestion * Revert the last (unnecessary) commit * Override pipeline config for Blenderbot to allow for larger pos. emb. * make fix-copies
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
"""Tests for Blenderbot Tokenizers, including common tests for BlenderbotSmallTokenizer."""
|
||||
import unittest
|
||||
|
||||
from transformers import BlenderbotTokenizer, BlenderbotTokenizerFast
|
||||
from transformers.file_utils import cached_property
|
||||
from transformers.models.blenderbot.tokenization_blenderbot import BlenderbotTokenizer
|
||||
|
||||
|
||||
class Blenderbot3BTokenizerTests(unittest.TestCase):
|
||||
@@ -25,6 +25,10 @@ class Blenderbot3BTokenizerTests(unittest.TestCase):
|
||||
def tokenizer_3b(self):
|
||||
return BlenderbotTokenizer.from_pretrained("facebook/blenderbot-3B")
|
||||
|
||||
@cached_property
|
||||
def rust_tokenizer_3b(self):
|
||||
return BlenderbotTokenizerFast.from_pretrained("facebook/blenderbot-3B")
|
||||
|
||||
def test_encode_decode_cycle(self):
|
||||
tok = self.tokenizer_3b
|
||||
src_text = " I am a small frog."
|
||||
@@ -32,6 +36,17 @@ class Blenderbot3BTokenizerTests(unittest.TestCase):
|
||||
decoded = tok.batch_decode(encoded, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
||||
assert src_text == decoded
|
||||
|
||||
def test_encode_decode_cycle_rust_tokenizer(self):
|
||||
tok = self.rust_tokenizer_3b
|
||||
src_text = " I am a small frog."
|
||||
encoded = tok([src_text], padding=False, truncation=False)["input_ids"]
|
||||
decoded = tok.batch_decode(encoded, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
||||
assert src_text == decoded
|
||||
|
||||
def test_3B_tokenization_same_as_parlai(self):
|
||||
assert self.tokenizer_3b.add_prefix_space
|
||||
assert self.tokenizer_3b([" Sam", "Sam"]).input_ids == [[5502, 2], [5502, 2]]
|
||||
|
||||
def test_3B_tokenization_same_as_parlai_rust_tokenizer(self):
|
||||
assert self.rust_tokenizer_3b.add_prefix_space
|
||||
assert self.rust_tokenizer_3b([" Sam", "Sam"]).input_ids == [[5502, 2], [5502, 2]]
|
||||
|
||||
Reference in New Issue
Block a user