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

标签 error-handling neural-network nlp tar word-embedding

我正在尝试使用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/

    相关文章:

    c - C 库应如何提醒用户错误的输入以及其他介绍库问题

    c# - 跳过自定义错误页面的身份验证

    php - 即使session_start()已经在最前面,“session_start(): Cannot send session cache limiter - headers already sent”仍会继续出现

    neural-network - Tensorflow tf.train.Saver 保存可疑的大 .ckpt 文件?

    python - count() 和 concordance() 给出不同的计数

    php - 如何在 PHP 中获取有用的错误消息?

    neural-network - `No such file or directory` 只能表示有 `No such file or directory` 吗?

    java - dl4j 不包含文本和模型模块

    java - Mallet 中每个主题 p(w|t) 的单词分布

    machine-learning - Api.ai 语音识别和 NLU 合一请求