我想预测文本中每个句子的得分。我已经写了这个测试方法:
def test(sent):
# Predict for a given sentence
if sent != "":
input, seq_lengths, target = make_variables([sent], [])
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
score = pred.cpu().numpy()[0][0]
print("The sentence is:",sent, "The score is:", score)
return
print("evaluating trained model ...")
total_mse=0
for sents, scores in test_loader:
input, seq_lengths, target = make_variables(sents, scores)
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
error=mean_squared_error(pred,target.data.view_as(pred.float()))
total_mse +=error
print(" ********** Total MSE is **********",total_mse)
return
在main方法的一部分中,我有:
# Testing
test("")
# Testing for a given sample _a sentence_
test("For instance, wolves prey on moose, which are too big for coyotes.")
但是我收到此错误:
错误回溯(最近一次通话最近):文件 “ /home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py”, 第59行,在testPartExecutor中 产生文件“ /home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py”, 601行,正在运行 testMethod()文件“ /home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py”, 198行,在runTest中 self.test(* self.arg)异常:test()缺少1个必需的位置参数:'sent' -------------------- >>开始捕获日志<< -------------------- gensim.models .doc2vec:调试:gensim.models.doc2vec的快速版本是 正在使用summa.preprocessing.cleaner:信息:“模式”包不 发现;标签过滤器不适用于英语gensim.utils:信息: 从中加载KeyedVectors对象 / home / mahsa / PycharmProjects / PyTorch_env_project / Thesis / proj2 / glove_saved gensim.utils:信息:从中加载syn0 /home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy 使用mmap = None gensim.utils:信息:设置忽略的属性syn0norm 到无gensim.utils:信息:已加载 / home / mahsa / PycharmProjects / PyTorch_env_project / Thesis / proj2 / glove_saved --------------------- >>结束捕获的日志<< --------------------- < / p>
E ================================================== ===================错误:mahsa_rnn_sent_classification.test -------------------------------------------------- --------------------追溯(最近一次通话):文件 “ /home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py”, 198行,在runTest中 self.test(* self.arg)TypeError:test()缺少1个必需的位置参数:'sent' -------------------- >>开始捕获日志<< -------------------- gensim.models .doc2vec:调试:gensim.models.doc2vec的快速版本是 正在使用summa.preprocessing.cleaner:信息:“模式”包不 发现;标签过滤器不适用于英语gensim.utils:信息: 从中加载KeyedVectors对象 / home / mahsa / PycharmProjects / PyTorch_env_project / Thesis / proj2 / glove_saved gensim.utils:信息:从中加载syn0 /home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy 使用mmap = None gensim.utils:信息:设置忽略的属性syn0norm 到无gensim.utils:信息:已加载 / home / mahsa / PycharmProjects / PyTorch_env_project / Thesis / proj2 / glove_saved --------------------- >>结束捕获的日志<< --------------------- < / p>
-------------------------------------------------- -----------------------在0.004秒内进行了1次测试
失败(错误= 1)
我认为test()的参数为“已发送”。我该如何纠正此错误?