Привет! Есть у меня значит два предложения:
"why isn't Alex's text tokenizing? The house on the left is the Smiths' house"
Давайте сделаем с ними tokenize и decode:
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
tokenizer.decode(tokenizer.convert_tokens_to_ids(tokenizer.tokenize("why isn't Alex's text tokenizing? The house on the left is the Smiths' house")))
Получим:
"why isn't alex's text tokenizing? the house on the left is the smiths'house"
Видим что BERT не справился с задачей. Как можно решить проблему слипания слов по типу smiths'house?
Лично мне кажется что токенизация в Transformers сделана просто неправильно. Давайте посотрим на неё в данном примере:
tokenizer.tokenize("why isn't Alex's text tokenizing? The house on the left is the Smiths' house")
Получим:
['why', 'isn', "'", 't', 'alex', "'", 's', 'text', 'token', '##izing', '?', 'the', 'house', 'on', 'the', 'left', 'is', 'the', 'smith', '##s', "'", 'house']
Таким образом мы потеряли важную информацию об апострофах на этом шаге. Если бы токенизация была бы проведена иным образом:
['why', 'isn', "##'", '##t', 'alex', "##'", '##s', 'text', 'token', '##izing', '?', 'the', 'house', 'on', 'the', 'left', 'is', 'the', 'smith', '##s', "##'", 'house']
Вся информация об апострофах была бы сохранена. Вопрос почему так сделано и как исправить ситуацию?