使用本地保存的SetFit模型

问题描述 投票:0回答:1

我在本地保存了 SetFit 模型,现在我想使用它来进行预测(用于模型部署),我尝试了以下代码:

from setfit import SetFitModel
model = SetFitModel.from_pretrained("CyberBullying/cyberbullying-classification-setfit-model-v1")
preds = model(["i loved the spiderman movie!", "Another Idiot ...is India really Full of them. It's has nothing to do with BJP / CONgress or Hindu-Muslim, it's about Rich/Poor. You all are so uneducated , but literate ."])
print('========================Predictions========================')
print(preds)

但出现以下错误:

回溯(最近一次调用最后一次): 文件“F:\Chahinez RSI\prediction.py”,第 3 行,位于 model = SetFitModel.from_pretrained("网络欺凌/网络欺凌分类-setfit-model-v1") 文件“C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\utils_validators.py”,第 118 行,位于 _inner_fn 中 返回 fn(*args, **kwargs) 文件“C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\hub_mixin.py”,第 159 行,from_pretrained
返回 cls._from_pretrained( 文件“C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\setfit\modeling.py”,第 549 行,位于 _from_pretrained model_head = joblib.load(model_head_file) 文件“C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\joblib umpy_pickle.py”,第 587 行,加载中 obj = _unpickle(fobj, 文件名, mmap_mode) 文件“C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\joblib umpy_pickle.py”,第 506 行,在 _unpickle 中 obj = unpickler.load() 文件“C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\pickle.py”,第 1213 行,加载中 调度键[0] 按键错误:0

nlp prediction huggingface-transformers few-shot-learning
1个回答
0
投票

您可能已经弄清楚了这一点(旧帖子),但您应该使用:

model.predict(['sentence1','sentence2']).
© www.soinside.com 2019 - 2024. All rights reserved.