我正在尝试在纸张空间上使用 pytorch 和 torchtext 进行文本分类。
\n我明白了
\nRuntimeError: \xe2\x80\x98lengths\xe2\x80\x99 argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor\nRun Code Online (Sandbox Code Playgroud)\n我的PyTorch版本是1.10.1+cu102
\n我想使用 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) 的大小匹配
huggingface-transformers huggingface-tokenizers huggingface-datasets
我正在包含requirement.txt 和所有内容的目录中运行以下命令。
sudo docker build -t flask-container .
但我收到这个错误。
Running command git clone -q https://github.com/pysentimiento/pysentimiento /tmp/pip-install-5crn_ko5/pysentimiento_472d6d991b204e42acc02194d0e3b813
ERROR: Error [Errno 2] No such file or directory: 'git' while executing command git clone -q https://github.com/pysentimiento/pysentimiento /tmp/pip-install-5crn_ko5/pysentimiento_472d6d991b204e42acc02194d0e3b813
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?
Run Code Online (Sandbox Code Playgroud)
Dockerfile -----------------
# Set base image (host OS)
FROM python:3.8-alpine
# By default, listen on port 5000
EXPOSE 5000/tcp
# Set the working directory in the container
WORKDIR /app
# Copy …Run Code Online (Sandbox Code Playgroud)