我一直在关注一个教程,该教程展示了如何制作 word2vec
模型。
本教程使用这段代码:similarity = merge([target, context], mode='cos', dot_axes=0)
(没有提供其他信息,但我想这来自 keras.layers
)
现在,我对 merge
进行了一些研究。方法,但我找不到太多关于它的信息。
据我了解,它已经被很多类似layers.Add(), layers.Concat()...
的功能所取代。 .
我应该使用什么?有.Dot()
,它有一个 axis
参数(似乎是正确的)但没有 mode
范围。
在这种情况下我可以使用什么?
最佳答案
Dot
Keras 中的层现在支持内置 余弦相似度使用 normalize = True
范围。
来自 Keras 文档:
keras.layers.Dot(axes, normalize=True)
normalize: Whether to L2-normalize samples along the dot product axis before taking the dot product. If set to True, then the output of the dot product is the cosine proximity between the two samples.
Source
关于python - 计算 Keras 中两个张量之间的余弦相似度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51003027/