Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单词嵌入的TensorFlow双向LSTM编码_Python_Tensorflow - Fatal编程技术网

Python 单词嵌入的TensorFlow双向LSTM编码

Python 单词嵌入的TensorFlow双向LSTM编码,python,tensorflow,Python,Tensorflow,我有一个单词嵌入矩阵,每个单词包含一个向量。我试图使用TensorFlow来获得给定嵌入向量的每个单词的双向LSTM编码。很遗憾,我收到以下错误消息: ValueError:形状(1125)和()必须具有相同的等级 异常TypeError:忽略中的TypeError(“'NoneType'对象不可调用“,”) 以下是我使用的代码: # Declare max number of words in a sentence self.max_len = 100 # Decla

我有一个单词嵌入矩阵,每个单词包含一个向量。我试图使用TensorFlow来获得给定嵌入向量的每个单词的双向LSTM编码。很遗憾,我收到以下错误消息:

ValueError:形状(1125)和()必须具有相同的等级 异常TypeError:忽略中的TypeError(“'NoneType'对象不可调用“,”)

以下是我使用的代码:

     # 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的序列长度必须是长度批量大小的向量。

这并不能回答该问题。一旦你有足够的钱,你将能够;相反为了澄清,您使用max_len作为序列长度。这是一个标量。要么不通过,要么通过[max_len]*batch_size,这是预期的向量。