我正在尝试使用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
没事。
关于如何处理此问题的任何提示?
谢谢!
最佳答案
在新版本的pytorch-pretrained-BERT中,即在变压器中,您可以执行以下操作以在解压缩后加载预训练的模型:
导入AutoModelForTokenClassification,AutoTokenizer
模型= AutoModelForTokenClassification.from_pretrained(“/您的/本地/路径/到/scibert_scivocab_uncased”)
关于error-handling - 如何用pytorch实现SciBERT;加载时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58350213/