我必须在 python 中实现上面的公式,但我很难完全理解它。我为此编写了一个伪代码,我确实需要有人来纠正它。
给定信息
因此,我在机器翻译的并行语料库中运行此代码,该语料库由 S 个句子对 (f
(s), e(s)),其中 1 ≤ s ≤ S。所以 f(s) 和 e(s) 分别代表 f:foreign language
和 语料库中的第 s 个句子>e:英语
。 e_x
是句子中的第 x 个单词 e(s)
我将这个公式理解为以下伪代码:
for a fixed english word e_x in all sentences:
for all foreign word f_y in the sentence where f_y and e_x appears together:
Z += apply the count in <.. I have the function for calculating this..>
我对这个公式的理解正确吗?
最佳答案
看起来 Z_{e_x}
是对 Z
的计算,无论 e_x
是什么。所以你的公式只是针对单个英文单词e_x
。因此,您可能需要每个单词都有一个矢量/ map 。
可能看起来像这样
Z = {x: 0 for x in all_english_words}
for x in Z.keys():
for y in all_foreign_words:
for s in S:
Z[x] += <your_function>
关于python - 修正伪代码编写的双重求和公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47710588/