def inference(self,X,reuse = None,trainMode=True):
word_verctors = tf.nn.embedding_lookup(self.words,X)
length = self.length(word_verctors)
length_64 = tf.cast(length,tf.int64)
if trainMode:
word_verctors = tf.nn.dropout(word_verctors,0.5)
with tf.variable_scope('rnn_fwbw',reuse =reuse) as scope:
lstm_fw = rnn.LSTMCell(self.numHidden)
lsmt_bw = rnn.LSTMCell(self.numHidden)
inputs = tf.unstack(word_verctors,nlp_segment.flags.max_sentence_len,1)
output,_,_ = rnn.static_bidirectional_rnn(lstm_fw,lsmt_bw,inputs,sequence_length=length_64,dtype=tf.float32)
output = tf.reshape(output,[-1,self.numHidden * 2])
matricized_unary_scores = tf.matmul(output,self.W) + self.b
unary_scores = tf.reshape(matricized_unary_scores,
[-1,nlp_segment.flags.max_sentence_len,self.distinctTagNum])
return unary_scores,length
评论列表
文章目录