使用Keras处理Tensorflow 2.0负采样的最佳方法

2024-05-20 09:09:32 发布

您现在位置:Python中文网/ 问答频道 /正文

Tensorflow发布了在TF2.0Keras中实现word2vec的官方指南

https://www.tensorflow.org/tutorials/text/word_embeddings

然而,它缺少负采样,这在word2vec中非常重要,这是不幸的,因为原始的张量流有一些很好的候选采样函数。你知道吗

我最想做的就是扩充模型

model = keras.Sequential([
  layers.Embedding(encoder.vocab_size, embedding_dim),
  layers.GlobalAveragePooling1D(),
  layers.Dense(1, activation='sigmoid')
])

或许可以使用函数API而不是顺序API。你知道吗

我看到c++tf2.0有候选采样操作https://www.tensorflow.org/api_docs/cc/group/candidate-sampling-ops

这些可以并入Keras吗?你知道吗


Tags: 函数texthttpsorgapi官方layerstensorflow