예제 #1
0
파일: model.py 프로젝트: nghuyong/MTL-SLAM
    def _add_word_level_context_encoder(self):
        # en_es
        self.en_es_word_level_encoder = bilstm_layer(
            inputs=self.en_es_word_embedded,
            inputs_length=self.en_es_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.word_layers,
            name_scope='en_es_word_level_bi_lstm')

        # es_en
        self.es_en_word_level_encoder = bilstm_layer(
            inputs=self.es_en_word_embedded,
            inputs_length=self.es_en_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.word_layers,
            name_scope='es_en_word_level_bi_lstm')

        # fr_en
        self.fr_en_word_level_encoder = bilstm_layer(
            inputs=self.fr_en_word_embedded,
            inputs_length=self.fr_en_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.word_layers,
            name_scope='fr_en_word_level_bi_lstm')
예제 #2
0
파일: model.py 프로젝트: nghuyong/MTL-SLAM
 def _add_word_level_context_encoder(self):
     # word embedding
     self.word_level_encoder = bilstm_layer(
         inputs=self.word_embedded,
         inputs_length=self.word_length_input,
         hidden_dim=self.config.context_hidden_dim,
         keep_prob=self.keep_prob,
         layers=self.config.word_layers,
         name_scope='word_level_bi_lstm'
     )
예제 #3
0
파일: model.py 프로젝트: nghuyong/MTL-SLAM
    def _add_char_level_cnn_context_encoder(self):
        # en_es
        en_es_char_cnn_encoder = self.cnn(name_scope='en_es_char_cnn',
                                          char_embedded=tf.nn.embedding_lookup(
                                              self.en_es_char_embedding,
                                              self.en_es_chars))

        self.en_es_char_cnn_context_encoder = bilstm_layer(
            inputs=en_es_char_cnn_encoder,
            inputs_length=self.en_es_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.char_cnn_bilstm_layers,
            name_scope='en_es_char_level_cnn_bi_lstm')

        # es_en
        es_en_char_cnn_encoder = self.cnn(name_scope='es_en_char_cnn',
                                          char_embedded=tf.nn.embedding_lookup(
                                              self.es_en_char_embedding,
                                              self.es_en_chars))
        self.es_en_char_cnn_context_encoder = bilstm_layer(
            inputs=es_en_char_cnn_encoder,
            inputs_length=self.es_en_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.char_cnn_bilstm_layers,
            name_scope='es_en_char_level_cnn_bi_lstm')

        # fr_en
        fr_en_char_cnn_encoder = self.cnn(name_scope='fr_en_char_cnn',
                                          char_embedded=tf.nn.embedding_lookup(
                                              self.fr_en_char_embedding,
                                              self.fr_en_chars))
        self.fr_en_char_cnn_context_encoder = bilstm_layer(
            inputs=fr_en_char_cnn_encoder,
            inputs_length=self.fr_en_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.char_cnn_bilstm_layers,
            name_scope='fr_en_char_level_cnn_bi_lstm')
예제 #4
0
파일: model.py 프로젝트: nghuyong/MTL-SLAM
 def _add_char_level_lstm_context_encoder(self):
     self.chars = tf.reshape(self.char_input, [-1, self.config.char_max_len])
     char_len = tf.reshape(self.char_length_input, [-1, ])
     self.char_embedding = tf.get_variable(name='char_embedding',
                                           shape=[self.config.char_size_dic[self.config.data_set],
                                                  self.config.char_embedding_dim],
                                           initializer=tf.contrib.layers.xavier_initializer())
     char_lstm_encoder = self.char_lstm(name_scope='char_lstm',
                                        char_embedded=tf.nn.embedding_lookup(self.char_embedding,
                                                                             self.chars),
                                        char_len=char_len
                                        )
     self.char_lstm_context_encoder = bilstm_layer(
         inputs=char_lstm_encoder,
         inputs_length=self.word_length_input,
         hidden_dim=self.config.context_hidden_dim,
         keep_prob=self.keep_prob,
         layers=self.config.char_lstm_bilstm_layers,
         name_scope='char_level_lstm_bi_lstm'
     )
예제 #5
0
파일: model.py 프로젝트: nghuyong/MTL-SLAM
    def _add_char_level_lstm_context_encoder(self):
        # en_es
        self.en_es_chars = tf.reshape(self.en_es_char_input,
                                      [-1, self.config.char_max_len])
        en_es_char_len = tf.reshape(self.en_es_char_length_input, [
            -1,
        ])
        self.en_es_char_embedding = tf.get_variable(
            name='en_es_char_embedding',
            shape=[
                self.config.char_size_dic['en_es'],
                self.config.char_embedding_dim
            ],
            initializer=tf.contrib.layers.xavier_initializer())
        en_es_char_lstm_encoder = self.char_lstm(
            name_scope='en_es_char_lstm',
            char_embedded=tf.nn.embedding_lookup(self.en_es_char_embedding,
                                                 self.en_es_chars),
            char_len=en_es_char_len)
        self.en_es_char_lstm_context_encoder = bilstm_layer(
            inputs=en_es_char_lstm_encoder,
            inputs_length=self.en_es_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.char_lstm_bilstm_layers,
            name_scope='en_es_char_level_lstm_bi_lstm')

        # es_en
        self.es_en_chars = tf.reshape(self.es_en_char_input,
                                      [-1, self.config.char_max_len])
        es_en_char_len = tf.reshape(self.es_en_char_length_input, [
            -1,
        ])
        self.es_en_char_embedding = tf.get_variable(
            name='es_en_char_embedding',
            shape=[
                self.config.char_size_dic['es_en'],
                self.config.char_embedding_dim
            ],
            initializer=tf.contrib.layers.xavier_initializer())
        es_en_char_lstm_encoder = self.char_lstm(
            name_scope='es_en_char_lstm',
            char_embedded=tf.nn.embedding_lookup(self.es_en_char_embedding,
                                                 self.es_en_chars),
            char_len=es_en_char_len)
        self.es_en_char_lstm_context_encoder = bilstm_layer(
            inputs=es_en_char_lstm_encoder,
            inputs_length=self.es_en_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.char_lstm_bilstm_layers,
            name_scope='es_en_char_level_lstm_bi_lstm')

        # fr_en
        self.fr_en_chars = tf.reshape(self.fr_en_char_input,
                                      [-1, self.config.char_max_len])
        fr_en_char_len = tf.reshape(self.fr_en_char_length_input, [
            -1,
        ])
        self.fr_en_char_embedding = tf.get_variable(
            name='fr_en_char_embedding',
            shape=[
                self.config.char_size_dic['fr_en'],
                self.config.char_embedding_dim
            ],
            initializer=tf.contrib.layers.xavier_initializer())
        fr_en_char_lstm_encoder = self.char_lstm(
            name_scope='fr_en_char_lstm',
            char_embedded=tf.nn.embedding_lookup(self.fr_en_char_embedding,
                                                 self.fr_en_chars),
            char_len=fr_en_char_len)
        self.fr_en_char_lstm_context_encoder = bilstm_layer(
            inputs=fr_en_char_lstm_encoder,
            inputs_length=self.fr_en_word_length_input,
            hidden_dim=self.config.context_hidden_dim,
            keep_prob=self.keep_prob,
            layers=self.config.char_lstm_bilstm_layers,
            name_scope='fr_en_char_level_lstm_bi_lstm')