【问题标题】:AutoModelForSequenceClassification requires the PyTorch library but it was not found in your environmentAutoModelForSequenceClassification 需要 PyTorch 库,但在您的环境中未找到
【发布时间】:2021-07-19 15:06:17
【问题描述】:

我正在尝试使用 roberta 转换器和预训练模型,但我不断收到此错误:

    ImportError: 
AutoModelForSequenceClassification requires the PyTorch library but it was not found in your environment. Checkout the instructions on the
installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment.

这是我的代码:

# Tasks:
# emoji, emotion, hate, irony, offensive, sentiment
# stance/abortion, stance/atheism, stance/climate, stance/feminist, stance/hillary

task='sentiment'
MODEL = f"cardiffnlp/twitter-roberta-base-{task}"

tokenizer = AutoTokenizer.from_pretrained(MODEL)
# download label mapping
labels=[]
mapping_link = f"https://raw.githubusercontent.com/cardiffnlp/tweeteval/main/datasets/{task}/mapping.txt"
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
model.save_pretrained(MODEL)
labels=[]
mapping_link = f"https://raw.githubusercontent.com/cardiffnlp/tweeteval/main/datasets/{task}/mapping.txt"
with urllib.request.urlopen(mapping_link) as f:
    html = f.read().decode('utf-8').split("\n")
    csvreader = csv.reader(html, delimiter='\t')
labels = [row[1] for row in csvreader if len(row) > 1]

我确保 PyTorch 已安装并正常工作:

【问题讨论】:

  • 该错误表示在您的环境中找不到它。你在运行一个venv吗?如果有,是否安装了 PyTorch?
  • 不,我没有运行 venv

标签: python pytorch roberta


【解决方案1】:

我遇到了同样的问题。通过重新启动内核为我解决了这个问题。

【讨论】:

    【解决方案2】:

    在导入 HuggingFace Transformer 之前,您需要先安装 Pytorch。

    否则你将不得不重新启动内核

    【讨论】:

      猜你喜欢
      • 2021-04-03
      • 2021-04-09
      • 2022-08-23
      • 2019-07-15
      • 2021-09-28
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多