【发布时间】:2017-06-18 13:37:42
【问题描述】:
我正在研究基于二元组的 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))
我面临标签张量维度问题错误:
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 不接受一维标签?
tf 版本为 1.0.1 蟒蛇版本:2.7
【问题讨论】: