为什么Doc2Vec.scale_vocab(...)['memory']['vocab']除以700得到词汇量?
Why is Doc2Vec.scale_vocab(...)['memory']['vocab'] divided by 700 to obtain vocabulary size?
来自 https://github.com/RaRe-Technologies/gensim/blob/master/docs/notebooks/doc2vec-wikipedia.ipynb
的 Doc2Vec 维基百科教程
for num in range(0, 20):
print('min_count: {}, size of vocab: '.format(num),
pre.scale_vocab(min_count=num, dry_run=True)['memory']['vocab']/700)
输出为:
min_count: 0, size of vocab: 8545782.0
min_count: 1, size of vocab: 8545782.0
min_count: 2, size of vocab: 4227783.0
min_count: 3, size of vocab: 3008772.0
min_count: 4, size of vocab: 2439367.0
min_count: 5, size of vocab: 2090709.0
min_count: 6, size of vocab: 1856609.0
min_count: 7, size of vocab: 1681670.0
min_count: 8, size of vocab: 1546914.0
min_count: 9, size of vocab: 1437367.0
min_count: 10, size of vocab: 1346177.0
min_count: 11, size of vocab: 1267916.0
min_count: 12, size of vocab: 1201186.0
min_count: 13, size of vocab: 1142377.0
min_count: 14, size of vocab: 1090673.0
min_count: 15, size of vocab: 1043973.0
min_count: 16, size of vocab: 1002395.0
min_count: 17, size of vocab: 964684.0
min_count: 18, size of vocab: 930382.0
min_count: 19, size of vocab: 898725.0
In the original paper, they set the vocabulary size 915,715. It seems similar size of vocabulary if we set min_count = 19. (size of vocab = 898,725)
700
似乎相当武断,我在 docs 中没有看到任何提及。
没有意义,但原因如下:
scale_vocab()
(通过使用内部 estimate_memory()
函数)returns 一个包含模型所需内存量的粗略估计值的字典,在字节,对于给定的 min_count
。这些估计是基于模型的 vocab
字典中的每个单词在 HS 模型中将占用大约 700 个字节(其中包含一些额外的霍夫曼编码信息)或在负采样模型中仅占用 500 个字节的想法。参见:
(这些是基于我 运行 的一系列临时测试的非常粗略的估计,在其他环境中可能会有很大差异 – 但通常 vocab
不是最大的因素模型内存使用,因此这里的精度并不那么重要。)
这本笔记本似乎正试图根据内存估计值,根据 dry_run=True
试验次数,反算出准确保留的词汇量是多少。
但是,它真的不必那样做。 scale_vocab()
中包含内存估计的相同结果字典还包括在顶级 retain_total
键中精确计算的保留词汇量。参见:
所以,笔记本可以改进。
来自 https://github.com/RaRe-Technologies/gensim/blob/master/docs/notebooks/doc2vec-wikipedia.ipynb
的 Doc2Vec 维基百科教程for num in range(0, 20):
print('min_count: {}, size of vocab: '.format(num),
pre.scale_vocab(min_count=num, dry_run=True)['memory']['vocab']/700)
输出为:
min_count: 0, size of vocab: 8545782.0
min_count: 1, size of vocab: 8545782.0
min_count: 2, size of vocab: 4227783.0
min_count: 3, size of vocab: 3008772.0
min_count: 4, size of vocab: 2439367.0
min_count: 5, size of vocab: 2090709.0
min_count: 6, size of vocab: 1856609.0
min_count: 7, size of vocab: 1681670.0
min_count: 8, size of vocab: 1546914.0
min_count: 9, size of vocab: 1437367.0
min_count: 10, size of vocab: 1346177.0
min_count: 11, size of vocab: 1267916.0
min_count: 12, size of vocab: 1201186.0
min_count: 13, size of vocab: 1142377.0
min_count: 14, size of vocab: 1090673.0
min_count: 15, size of vocab: 1043973.0
min_count: 16, size of vocab: 1002395.0
min_count: 17, size of vocab: 964684.0
min_count: 18, size of vocab: 930382.0
min_count: 19, size of vocab: 898725.0
In the original paper, they set the vocabulary size 915,715. It seems similar size of vocabulary if we set min_count = 19. (size of vocab = 898,725)
700
似乎相当武断,我在 docs 中没有看到任何提及。
没有意义,但原因如下:
scale_vocab()
(通过使用内部 estimate_memory()
函数)returns 一个包含模型所需内存量的粗略估计值的字典,在字节,对于给定的 min_count
。这些估计是基于模型的 vocab
字典中的每个单词在 HS 模型中将占用大约 700 个字节(其中包含一些额外的霍夫曼编码信息)或在负采样模型中仅占用 500 个字节的想法。参见:
(这些是基于我 运行 的一系列临时测试的非常粗略的估计,在其他环境中可能会有很大差异 – 但通常 vocab
不是最大的因素模型内存使用,因此这里的精度并不那么重要。)
这本笔记本似乎正试图根据内存估计值,根据 dry_run=True
试验次数,反算出准确保留的词汇量是多少。
但是,它真的不必那样做。 scale_vocab()
中包含内存估计的相同结果字典还包括在顶级 retain_total
键中精确计算的保留词汇量。参见:
所以,笔记本可以改进。