【发布时间】:2016-01-10 21:03:21
【问题描述】:
我正在尝试使用 Tensorflow 中的 LSTM 模块在时间 (t-1) 使用单热字母预测作为时间 (t) 下一个状态的输入。我正在做一些事情:
one_hot_dictionary = {0:np.array([1.,0.,0.]),1:np.array([0.,1.,0.]),\
2:np.array([0.,0.,1.])}
state = init_state
for time in xrange(sequence_length):
#run the cell
output, state = rnn_cell.cell(input,state)
#transform the output so they are of the one-hot letter dimension
transformed_val = tf.nn.xw_plus_b(output, W_o, b_o)
#take the softmax to normalize
softmax_val = tf.nn.softmax(transformed_val)
#then get the argmax of these to know what the predicted letter is
argmax_val = tf.argmax(softmax_val,1)
#finally, turn these back into one-hots with a number to numpy
# array dictionary
input = [one_hot_dictionary[argmax_val[i]] for i in xrange(batch_size)]
但是,我得到了错误:
input = [one_hot_dictionary[argmax_val[i]] for i in xrange(batch_size)]
KeyError: <tensorflow.python.framework.ops.Tensor object at 0x7f772991ce50>
有没有什么方法可以用我的字典从 argmax 值动态创建这些 one-hot 字母编码?
【问题讨论】:
标签: python machine-learning tensorflow