Exemplo n.º 1
0
    def build_model(self):
        input_word = Input(shape=(int(self.max_len / 5),))
        x_word = Embedding(len(self.embeddings),
                           300,
                           weights=[self.embeddings],
                           trainable=False)(input_word)
        x_word = Bidirectional(LSTM(128, return_sequences=True))(x_word)
        x_word = VanillaRNNAttention(256)(x_word)
        model_word = Model(input_word, x_word)

        # Sentence part
        inputs = Input(shape=(self.max_len,))  # (5, self.max_len) :(篇章最多包含的句子,每句包含的最大词数)
        reshape = Reshape((5, int(self.max_len / 5)))(inputs)
        x_sentence = TimeDistributed(model_word)(reshape)
        x_sentence = Bidirectional(LSTM(128, return_sequences=True))(x_sentence)
        x_sentence = VanillaRNNAttention(256)(x_sentence)

        output = Dense(1, activation='sigmoid')(x_sentence)
        model = Model(inputs=inputs, outputs=output)
        model.compile('adam', 'binary_crossentropy', metrics=['accuracy'])
        return model
Exemplo n.º 2
0
 def build_model(self):
     inputs = Input(shape=(self.max_len,))
     output = Embedding(len(self.embeddings),
                        300,
                        weights=[self.embeddings],
                        trainable=False)(inputs)
     output = Bidirectional(LSTM(150, return_sequences=True, dropout=0.25, recurrent_dropout=0.25))(output)
     output = VanillaRNNAttention(300)(output)
     output = Dense(128, activation="relu")(output)
     output = Dropout(0.25)(output)
     output = Dense(1, activation="sigmoid")(output)
     model = Model(inputs=inputs, outputs=output)
     model.compile(loss='binary_crossentropy',
                   optimizer='adam',
                   metrics=['accuracy'])
     model.summary()
     return model