我正在研究基于bigram的LSTM。
自从我介绍嵌入以来,我不得不选择正确的损失功能。这里 是我的选择:
loss=tf.reduce_mean(tf.nn.sampled_softmax_loss(weights=softmax_weights,\
biases=softmax_biases, \
labels=tf.concat(train_labels,0),\
inputs=logits,\
num_sampled=num_sampled,\
num_classes=vocabulary_size))
我正面临标签Tensor维度问题错误:
logits具有以下形状:(640,13)
标签有这种形状Tensor(“concat_2:0”,shape =(640,27),dtype = float32)
我也试过
labels==tf.reshape(tf.concat(train_labels,0),[-1])
对于这两种情况,我都会收到错误:
对于第一种情况,错误是:
Dimension must be 1 but is 27 for
'sampled_softmax_loss/ComputeAccidentalHits' (op:
'ComputeAccidentalHits') with input shapes: [640,27], [20].
对于第二种情况,错误是:
Shape must be rank 2 but is rank 1 for
'sampled_softmax_loss/LogUniformCandidateSampler' (op:
'LogUniformCandidateSampler') with input shapes: [17280].
这是我的参数:
640 = batch_size *num_enrollings =64*10
27 = vocabulary_size (I am implementing first Embedding on single character as vocabulary.
20 is num_sampled of the loss function.
13 = embedding_size
为什么tf.nn.sampled_softmax_loss不接受1维标签?
版本是1.0.1 python版本:2.7
答案 0 :(得分:1)
找到解决方案。
我正在使用带有单热格式的标签来提供sampled_softmax_loss。 通过将简单的argmax功能应用于标签
,事情就顺利进行了