tokenizers Llama-3偏移Map需要修复,

nafvub8i  于 2个月前  发布在  其他
关注(0)|答案(6)|浏览(45)

为之前打开的问题打开一个新问题-- #1517
在这里,我们可以看到Mistral为return_offsets_mapping所期望的行为是给出与tokens对应的字符索引:

(Pdb) from transformers import AutoTokenizer
(Pdb) tok_mistral = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
(Pdb) tok_mistral(["Sample input"], return_offsets_mapping=True)
{'input_ids': [[1, 27797, 2787]], 'attention_mask': [[1, 1, 1]], 'offset_mapping': [[(0, 0), (0, 6), (6, 12)]]}
(Pdb) tok_mistral.convert_ids_to_tokens([1, 27797, 2787])
['<s>', '▁Sample', '▁input']
(Pdb) "Sample input"[0:6]
'Sample'
(Pdb) "Sample input"[6:12]
' input'

但是对于Llama-3来说,它们并不正确

(Pdb) tok_llama3 = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct") 
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
(Pdb) tok_llama3(["Sample input"], return_offsets_mapping=True)
{'input_ids': [[128000, 18031, 1988]], 'attention_mask': [[1, 1, 1]], 'offset_mapping': [[(0, 0), (0, 0), (6, 6)]]}

我们还可以看到Llama-2和GPT-2的工作方式与Mistral相同,因此Llama-3绝对是执行出乎意料的行为的那个

(Pdb) tok_llama2 = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-hf")
(Pdb) tok_llama2(["Sample input"], return_offsets_mapping=True)
{'input_ids': [[1, 21029, 1881]], 'attention_mask': [[1, 1, 1]], 'offset_mapping': [[(0, 0), (0, 6), (6, 12)]]}
(Pdb) tok_gpt2 = AutoTokenizer.from_pretrained("openai-community/gpt2") 
(Pdb) tok_gpt2(["Sample input"], return_offsets_mapping=True)
{'input_ids': [[36674, 5128]], 'attention_mask': [[1, 1]], 'offset_mapping': [[(0, 6), (6, 12)]]}
g6baxovj

g6baxovj1#

tokenizers中,是否有可能修复这个问题?

7dl7o3gd

7dl7o3gd2#

是的,你是对的,我会深入了解一下为什么我们会有这个!

rkttyhzu

rkttyhzu3#

太棒了,谢谢你!

jhiyze9q

jhiyze9q4#

@ArthurZucker 有没有临时的解决办法?

qfe3c7zg

qfe3c7zg5#

抱歉,暂时还没有!我正在修复一堆东西,也许会是#1568?

相关问题