python - 词嵌入的 TensorFlow 双向 LSTM 编码

标签 python tensorflow

我有一个单词嵌入矩阵,其中包含每个单词的向量。我正在尝试使用 TensorFlow 获取给定嵌入向量的每个单词的双向 LSTM 编码。不幸的是,我收到以下错误消息:

ValueError: Shapes (1, 125) and () must have the same rank Exception TypeError: TypeError("'NoneType' object is not callable",) in ignored

这是我使用的代码:

     # Declare max number of words in a sentence
    self.max_len = 100
    # Declare number of dimensions for word embedding vectors
    self.wdims = 100

     # Indices of words in the sentence
    self.wrd_holder = tf.placeholder(tf.int32, [self.max_len])
    # Embedding Matrix
    wrd_lookup = tf.Variable(tf.truncated_normal([len(vocab)+3, self.wdims], stddev=1.0 / np.sqrt(self.wdims)))

     # Declare forward and backward cells
    forward  = rnn_cell.LSTMCell(125, (self.wdims))
    backward = rnn_cell.LSTMCell(125, (self.wdims))

     # Perform lookup
    wrd_embd = tf.nn.embedding_lookup(wrd_lookup, self.wrd_holder)
    embd = tf.split(0, self.max_len, wrd_embd)

     # run bidirectional LSTM
    boutput = rnn.bidirectional_rnn(forward, backward, embd, dtype=tf.float32, sequence_length=self.max_len)

最佳答案

传递给 rnn 的序列长度必须是长度批量大小的向量。

关于python - 词嵌入的 TensorFlow 双向 LSTM 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36515648/

相关文章:

python - Keras 二元分类器教程示例仅提供 50% 的验证准确率

python - 导入 tensorflow 时出错 : NameError: name 'python' is not defined

python - 使用预训练的 Inceptionv3 的 Keras 问题

python - 算法效率——使用Pandas的数据处理效率(三个嵌套的for循环)

python - openerp 向导正在调用基本 res.partner 表单而不是我的表单

python - tcsh 中 python-shell 下划线变量的对应部分?

python - 防止为 MonitoredTrainingSession 分配 GPU 内存

python - 如何在 ubuntu 14 中安装 aws-sam-cli?

python - keras Tensorflow中InputLayer的输入形状是什么?

python - 在keras中的自定义损失函数中做一些数学计算