Rez*_*fra 3 huggingface-transformers huggingface-tokenizers huggingface-datasets
我想使用 Huggingface 来预测数千个句子的情绪。
from transformers import pipeline
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
pipe = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
from datasets import load_dataset
data_files = {
"train": "/content/data_customer.csv"
}
dataset = load_dataset("csv", data_files=data_files)
dataset = dataset.map(lambda examples: dict(pipe(examples['text'])))
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误。
RuntimeError: The expanded size of the tensor (585) must match the existing size (514) at non-singleton dimension 1. Target sizes: [1, 585]. Tensor sizes: [1, 514]
Run Code Online (Sandbox Code Playgroud)
这篇文章提出了一种解决该问题的方法,但没有说明如何在管道中解决它。 在非单一维度 1 处,张量 a (707) 的大小必须与张量 b (512) 的大小匹配
joe*_*140 21
只需在初始化管道时添加标记器参数即可。
pipe = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path, max_length=512, truncation=True)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10550 次 |
| 最近记录: |