HAMModel.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:DeeplearningForTextClassification 作者: zldeng 项目源码 文件源码
def BidirectionalGRUEncoder(self,inputs,name):
        '''
        inputs: [batch,max_time,embedding_size]
        output: [batch,max_time,2*hidden_size]
        '''
        with tf.variable_scope(name):
            fw_gru_cell = rnn.GRUCell(self.hidden_size)
            bw_gru_cell = rnn.GRUCell(self.hidden_size)

            fw_gru_cell = rnn.DropoutWrapper(fw_gru_cell,output_keep_prob = self.dropout_keep_prob)
            bw_gru_cell = rnn.DropoutWrapper(bw_gru_cell,output_keep_prob = self.dropout_keep_prob)

            (fw_outputs,bw_outputs),(fw_outputs_sta,bw_outputs_sta) = tf.nn.bidirectional_dynamic_rnn(
                cell_fw = fw_gru_cell,
                cell_bw = bw_gru_cell,
                inputs = inputs,
                sequence_length = getSequenceRealLength(inputs),
                dtype = tf.float32)

            outputs = tf.concat((fw_outputs,bw_outputs),2)

            return outputs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号