python - 修正伪代码编写的双重求和公式

标签 python

enter image description here

我必须在 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/

相关文章:

Python3 - 字符串的最后一个字符

python - 如何保存通过camera.capture_continuous(格式rgb)读取的图像并将其保存到文件中

python - 为什么我的 Django URL 调度程序不工作?

python - 在crawlspider中配置规则时,follow参数似乎不起作用

c++ - Python C++ : is the any python. split() 类似于 c++ 中的方法?

python - 将文件数据转换为嵌套列表

python - python中图像中特定位置的图像水印

python - 以csv或xlsx格式输出多个PDF文件及其对应文本文件的大小

Python MySQLdb 连接错误

python - 导入模块适用于 Eclipse,但不适用于命令行