我正在设计一个张量流模型,用lstm预测下一个单词 RNN的Tensorflow教程给出了伪代码如何将LSTM用于PTB数据集 我达到了生成批次和标签的步骤。
def generate_batches(raw_data, batch_size):
global data_index
data_len = len(raw_data)
num_batches = data_len // batch_size
#batch = dict.fromkeys([i for i in range(num_batches)])
#labels = dict.fromkeys([i for i in range(num_batches)])
batch = np.ndarray(shape=(batch_size), dtype=np.float)
labels = np.ndarray(shape=(batch_size, 1), dtype=np.float)
for i in xrange(batch_size) :
batch[i] = raw_data[i + data_index]
labels[i, 0] = raw_data[i + data_index + 1]
data_index = (data_index + 1) % len(raw_data)
return batch, labels
此代码提供批次和标签大小(batch_size X 1)。
使用tf.nn.embedding_lookup()
,这些批次和标签的大小也可以是(batch_size x vocabulary_size)。
那么,这里的问题是如何继续使用函数rnn_cell.BasicLSTMCell
或使用用户定义的lstm模型?
input dimension to LSTM cell
将是什么以及如何与{num_steps
一起使用1}}?
批处理和标签的大小在任何情况下都有用吗?