假设我有一个loop
,其执行方式如下:-
for i in range(len(X_test)):
_, _, ref, hyp = result([X_test[i]],y_test.iloc[i])
hyp = hyp.replace('<end>', '')
bleu_score = bleu([ref], hyp, smoothing_function=cc.method3)
print("Associated BLEU score:",bleu_score,"\n")
overall_bleu.append(bleu_score)
我想做的是创建一个新的CSV文件,该文件有2列,即Reference (Stands for ref variable in the loop)
和Predicted (Stands for hyp variable in the loop)
,这样对于每一行,在循环的每个连续迭代中,字符串{{1 }}和hyp
写入新CSV文件(我要创建)的相应列中。有什么干净的方法吗?我本来打算使用ref
,但似乎每次在循环中编写都是多余的。