标签: sentencepiece

系统中未安装句子库

在使用过程中pip install tf-models-official,我在安装库时发现了以下问题:-

\n
Collecting tf-models-official\n  Using cached tf_models_official-2.8.0-py2.py3-none-any.whl (2.2 MB)\nRequirement already satisfied: Pillow in c:\\users\\user\\documents\\python scripts\\number_plate_recognition\\anprsys\\lib\\site-packages (from tf-models-official) (9.0.1)\nCollecting gin-config\n  Using cached gin_config-0.5.0-py3-none-any.whl (61 kB)\nCollecting seqeval\n  Using cached seqeval-1.2.2-py3-none-any.whl\nRequirement already satisfied: tensorflow~=2.8.0 in c:\\users\\user\\documents\\python scripts\\number_plate_recognition\\anprsys\\lib\\site-packages (from tf-models-official) (2.8.0)\nCollecting tensorflow-datasets\n  Using cached tensorflow_datasets-4.5.2-py3-none-any.whl (4.2 MB)\nRequirement already satisfied: six in c:\\users\\user\\documents\\python scripts\\number_plate_recognition\\anprsys\\lib\\site-packages (from tf-models-official) (1.16.0)\nRequirement already satisfied: scipy>=0.19.1 in c:\\users\\user\\documents\\python scripts\\number_plate_recognition\\anprsys\\lib\\site-packages (from tf-models-official) (1.8.0)\nCollecting pandas>=0.22.0\n  Using cached pandas-1.4.1-cp310-cp310-win_amd64.whl (10.6 MB)\nCollecting py-cpuinfo>=3.3.0\n  Using cached py_cpuinfo-8.0.0-py3-none-any.whl\nCollecting google-api-python-client>=1.6.7\n  Downloading google_api_python_client-2.42.0-py2.py3-none-any.whl (8.3 MB)\n …
Run Code Online (Sandbox Code Playgroud)

python python-wheel tensorflow automatic-license-plate-recognition sentencepiece

14
推荐指数
1
解决办法
2万
查看次数

如何向标记器添加新的特殊标记?

我想构建一个多类分类模型,将会话数据作为 BERT 模型的输入(使用 bert-base-uncased)。

提问:我想问一个问题。
答:当然可以,问吧。
询问:今天天气怎么样?
答:天气很好,阳光明媚。
问题:好的,很高兴知道。
回答:您还想了解其他信息吗?

除此之外,我还有两个输入。

我想知道是否应该在对话中添加特殊标记,以使其对 BERT 模型更有意义,例如:

[CLS]QUERY:我想问一个问题。[EOT]
答案:当然可以,问吧。[EOT]
查询:今天天气怎么样?[EOT]
答案:天气很好,阳光明媚。[EOT]
查询:好的,很高兴知道。[EOT]
解答:您还想了解其他信息吗?[九月]

但我无法添加新的 [EOT] 特殊令牌。
或者我应该为此使用 [SEP] 令牌?

编辑:重现步骤

from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")

print(tokenizer.all_special_tokens) # --> ['[UNK]', '[SEP]', '[PAD]', '[CLS]', '[MASK]']
print(tokenizer.all_special_ids)    # --> [100, 102, 0, 101, 103]

num_added_toks = tokenizer.add_tokens(['[EOT]'])
model.resize_token_embeddings(len(tokenizer))  # --> Embedding(30523, 768)

tokenizer.convert_tokens_to_ids('[EOT]')  # --> 30522

text_to_encode = '''QUERY: I want to ask a question. [EOT]
ANSWER: Sure, ask away. …
Run Code Online (Sandbox Code Playgroud)

bert-language-model huggingface-tokenizers sentencepiece

10
推荐指数
1
解决办法
2万
查看次数

为什么 Huggingface t5 分词器会忽略一些空格?

我正在使用 T5 模型和分词器来执行下游任务。我想向标记生成器添加某些空格,例如行结尾(\\t)和制表符(\\t)。添加这些标记可以工作,但不知何故标记器总是忽略第二个空格。因此,它将序列标记\xe2\x80\x9c\\n\\n\xe2\x80\x9d为单行结尾,并将序列"\\n\\n\\n\\n"标记为两个行结尾,依此类推。请参阅下文进行重现。

\n
from transformers import T5Tokenizer\ntokenizer = T5Tokenizer.from_pretrained("t5-large")\ntokenizer.add_tokens(["\\n"])\n\ntokenizer.encode("\\n") # returns [32100, 1] as expected\ntokenizer.encode("\\n\\n") # returns [32100, 1] but expected would be [32100, 32100, 1]\ntokenizer.encode("\\n\\n\\n\\n") # returns [32100, 32100, 1] but expected would be [32100, 32100, 32100, 32100, 1]\n
Run Code Online (Sandbox Code Playgroud)\n

这种行为背后的原因是什么?这是一个错误还是与分词器工作原理相关的东西?我注意到这只发生在添加的空格上,而不会发生在其他字符上。

\n

有没有办法防止分词器忽略重复的空格?

\n

huggingface-transformers huggingface-tokenizers sentencepiece

7
推荐指数
1
解决办法
2542
查看次数