微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python,快速专家,使用预先训练的模型进行预测

如何解决Python,快速专家,使用预先训练的模型进行预测

我正在使用快速的Bert软件包来训练Bert模型。 快速的bert保存模型输出以下文件

-Resources
-- config.json
-- pytorch_model.bin
-- specail_tokens_map.json
-- tokenizer_config.json
-- vocab.txt
-- events.out.tfevents.1601151257 (1).ffce4853f2c9

我正尝试通过快速bert加载模型并使用它进行预测:

from fast_bert.prediction import BertClassificationPredictor
def predictor(texts,MODEL_PATH=None):
        """
        :param MODEL_PATH: path to trained model
        :type texts: list
        :param: texts: texts to run prediction on
        """
        MODEL_PATH = '/content/Resources/' 
        LABEL_DATA = '/content/data/' # same path as when trained so it's valid

        if MODEL_PATH is None:
            raise LookupError("This Path is either wrong or No Trained Model exists")
        predictor = BertClassificationPredictor(
            model_path=MODEL_PATH,label_path=LABEL_DATA,# location for labels.csv file
            multi_label=False,model_type='xlnet',do_lower_case=False)

        # Batch predictions
        multiple_predictions = predictor.predict_batch(texts)
        pprint(("Predicting texts accuracy",) multiple_predictions)
        return multiple_predictions

因此,出现以下错误

OSError: Unable to load weights from pytorch checkpoint file. If you tried to load a PyTorch model from a TF 2.0 checkpoint,please set from_tf=True. 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。