在LDA 模型中,每次我在同一个语料库上训练时都会生成不同的主题,通过设置np.random.seed(0)
,LDA 模型将始终以完全相同的方式进行初始化和训练。
来自的 Word2Vec 模型是否相同gensim
?通过将随机种子设置为常数,同一数据集上的不同运行会产生相同的模型吗?
但奇怪的是,它已经在不同的情况下给了我相同的向量。
>>> from nltk.corpus import brown
>>> from gensim.models import Word2Vec
>>> sentences = brown.sents()[:100]
>>> model = Word2Vec(sentences, size=10, window=5, min_count=5, workers=4)
>>> model[word0]
array([ 0.04985042, 0.02882229, -0.03625415, -0.03165979, 0.06049283,
0.01207791, 0.04722737, 0.01984878, -0.03026265, 0.04485954], dtype=float32)
>>> model = Word2Vec(sentences, size=10, window=5, min_count=5, workers=4)
>>> model[word0]
array([ 0.04985042, 0.02882229, -0.03625415, -0.03165979, 0.06049283,
0.01207791, 0.04722737, 0.01984878, -0.03026265, 0.04485954], dtype=float32)
>>> model = Word2Vec(sentences, size=20, window=5, min_count=5, workers=4)
>>> model[word0]
array([ 0.02596745, 0.01475067, -0.01839622, -0.01587902, 0.03079717,
0.00586761, 0.02367715, 0.00930568, -0.01521437, 0.02213679,
0.01043982, -0.00625582, 0.00173071, -0.00235749, 0.01309298,
0.00710233, -0.02270884, -0.01477827, 0.01166443, 0.00283862], dtype=float32)
>>> model = Word2Vec(sentences, size=20, window=5, min_count=5, workers=4)
>>> model[word0]
array([ 0.02596745, 0.01475067, -0.01839622, -0.01587902, 0.03079717,
0.00586761, 0.02367715, 0.00930568, -0.01521437, 0.02213679,
0.01043982, -0.00625582, 0.00173071, -0.00235749, 0.01309298,
0.00710233, -0.02270884, -0.01477827, 0.01166443, 0.00283862], dtype=float32)
>>> exit()
alvas@ubi:~$ python
Python 2.7.11 (default, Dec 15 2015, 16:46:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk.corpus import brown
>>> from gensim.models import Word2Vec
>>> sentences = brown.sents()[:100]
>>> model = Word2Vec(sentences, size=10, window=5, min_count=5, workers=4)
>>> word0 = sentences[0][0]
>>> model[word0]
array([ 0.04985042, 0.02882229, -0.03625415, -0.03165979, 0.06049283,
0.01207791, 0.04722737, 0.01984878, -0.03026265, 0.04485954], dtype=float32)
>>> model = Word2Vec(sentences, size=20, window=5, min_count=5, workers=4)
>>> model[word0]
array([ 0.02596745, 0.01475067, -0.01839622, -0.01587902, 0.03079717,
0.00586761, 0.02367715, 0.00930568, -0.01521437, 0.02213679,
0.01043982, -0.00625582, 0.00173071, -0.00235749, 0.01309298,
0.00710233, -0.02270884, -0.01477827, 0.01166443, 0.00283862], dtype=float32)
那么默认随机种子是固定的吗?如果是这样,默认的随机种子数是多少?还是因为我正在测试一个小数据集?
如果随机种子确实是固定的并且在相同数据上的不同运行返回相同的向量,那么将非常感谢指向规范代码或文档的链接。