小编Rez*_*fra的帖子

RuntimeError:“lengths”参数应该是 1D CPU int64 张量,但得到 1D cuda:0 Long 张量

我正在尝试在纸张空间上使用 pytorch 和 torchtext 进行文本分类。

\n

我明白了

\n
RuntimeError: \xe2\x80\x98lengths\xe2\x80\x99 argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor\n
Run Code Online (Sandbox Code Playgroud)\n

我的PyTorch版本是1.10.1+cu102

\n

pytorch

6
推荐指数
1
解决办法
5179
查看次数

运行时错误:张量 (585) 的扩展大小必须与非单一维度 1 处的现有大小 (514) 匹配

我想使用 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

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

由于找不到 git,Docker 构建失败

我正在包含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)

python flask docker

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