word2vec tf 2训练错误-无效的参数错误

时间:2020-04-09 20:48:17

标签: python tensorflow tensorflow2.0 word2vec

我正在尝试在tensorflow 2中构建一个带有负采样的word2vec模型。

我的起点是张量流教程here。我已经使用tensorflow提供的转换脚本将代码从tf1转换为2。

我有一个已经处理过的数据集,并且正在使用Keras标记器执行标记化。

培训在108K培训步骤中一直进行到一定程度,但始终如一。我收到以下错误

    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[122] = 22894 is not in [0, 22894)
         [[node loss/nce_loss/embedding_lookup_1 (defined at c:/Users/EDMISML/pyprojects/abbv2vec/word2vectf-V2.py:146) ]]

Errors may have originated from an input operation.
Input Source operations connected to node loss/nce_loss/embedding_lookup_1:
 biases/Variable (defined at c:/Users/EDMISML/pyprojects/word2vec2vec/word2vectf-V2.py:130)

当前注意:

vocabulary_size = len(tok.word_counts)

其中tok是适合我的主体的Token对象。

还要注意,22894是我的嗓音大小。 我尝试过:

      vocabulary_size+=1  # increment vocab size by 1 

      with tf.compat.v1.name_scope('embeddings'):
        embeddings = tf.Variable(
            tf.random.uniform([vocabulary_size, embedding_size], -1.0, 1.0))
        embed = tf.nn.embedding_lookup(params=embeddings, ids=train_inputs)

但是我仍然收到相同的错误。

有人可以帮忙吗?

0 个答案:

没有答案