gpt4 book ai didi

error-handling - 如何用pytorch实现SciBERT;加载时出错

转载 作者:行者123 更新时间:2023-12-03 08:44:13 33 4
gpt4 key购买 nike

我正在尝试使用SciBERT预先训练的模型,即:scibert-scivocab-uncased以下方式:

    !pip install pytorch-pretrained-bert 
import torch
from pytorch_pretrained_bert import BertTokenizer, BertModel, BertForMaskedLM
import logging
import matplotlib.pyplot as plt
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
indexed_tokens = tokenizer.convert_tokens_to_ids(tokenized_text)
segments_ids = [1] * len(tokenized_text)
tokens_tensor = torch.tensor([indexed_tokens])
segments_tensors = torch.tensor([segments_ids])
model = BertModel.from_pretrained('/Users/.../Downloads/scibert_scivocab_uncased-3.tar.gz')

我收到以下错误:
EOFError: Compressed file ended before the end-of-stream marker was reached
  • 我从网站(https://github.com/allenai/scibert)上下载了文件
  • 我将其从“tar”转换为gzip

  • 没事。

    关于如何处理此问题的任何提示?

    谢谢!

    最佳答案

    在新版本的pytorch-pretrained-BERT中,即在变压器中,您可以执行以下操作以在解压缩后加载预训练的模型:

    导入AutoModelForTokenClassification,AutoTokenizer

    模型= AutoModelForTokenClassification.from_pretrained(“/您的/本地/路径/到/scibert_scivocab_uncased”)

    关于error-handling - 如何用pytorch实现SciBERT;加载时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58350213/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com