コード例 #1
0
            },
            sentences_vector.classifications_vec,
            batch_size=sentences_vector.sentence_vec.shape[1],
            epochs=100,
            # validation_split=0.2,
            # validation_data=({'sequence_input': x_test, 'posi_input': x_test_posi}, y_test),
            callbacks=callbacks_list)
        return model


if __name__ == '__main__':
    config = Configuration(
        word_segmentor=EnSegmentor(),
        EMBEDDING_DIM=128,
        position_matrix_file_path="../data/posi_matrix.npy",
        word2vec_file_path="../data/needed_word2vec.bin",
        POS_list_file_path="../data/pos_list.txt",
        types_file_path="../data/relations_en.txt",
        corpus_file_path="../data/train_en.txt",
        model_file_path="../data/model/re_sem_eval_en_model.cnn.hdf5",
    )
    inputer = Inputer(config)
    trainer = Trainer(inputer, CnnTrainerEn())
    outputer = Outputer(trainer)
    predict_texts = [
        " <e1>level</e1> of experience has already been mentioned in the previous <e2>chapter</e2>.",
        " <e1>level</e1> of experience has already been mentioned in the previous <e2>chapter</e2>."
    ]
    import json

    print(
        json.dumps(outputer.getDescription(predict_texts), ensure_ascii=False))
コード例 #2
0
    def predict(self, sentence_vector: SentencesVector):
        classVector = np.ones(sentence_vector.classifications_vec.shape)
        prop = self.model.predict({
            'sequence_input': sentence_vector.embedded_sequences,
            "posi_input": sentence_vector.position_vec,
            "typeInput": classVector
        })
        return sentence_vector.prop2index(prop)


if __name__ == '__main__':
    config = Configuration(
        position_matrix_file_path="../data/posi_matrix.npy",
        word2vec_file_path="../data/needed_zh_word2vec.bin",
        POS_list_file_path="../data/military/pos_list.txt",
        types_file_path="../data/military/relations_zh.txt",
        corpus_file_path="../data/military/train_zh.txt",
        model_file_path="../data/model/re_military_zh_model.bilstm.hdf5",
    )
    inputer = Inputer(config)
    trainer = Trainer(inputer, BiLstmTrainer())
    outputer = Outputer(trainer)
    predict_texts = [
        "<loc>美国</loc>目前共有2级11艘航空母舰,包括企业级核动力航母1艘,尼米兹级核动力航母10<loc>艘,</loc>全部采用核动力发动机",
        "<loc>美国</loc>经过多年航空母舰的发<loc>展,</loc>一直以来都是全球拥有最多、排水量和体积最大、舰载机搭载数量最多、作战效率最强大、而且全部使用核动力航空母舰的国家"
    ]
    import json
    print(
        json.dumps(outputer.getDescription(predict_texts), ensure_ascii=False))
コード例 #3
0
            batch_size=50,
            epochs=50000,
            validation_split=0.2,
            # validation_data=({'sequence_input': x_test, 'posi_input': x_test_posi}, y_test),
            callbacks=callbacks_list)
        return model


if __name__ == '__main__':
    testType = input("CNN?RNN:")
    config = Configuration(
        word_segmentor=EnSegmentor(),
        EMBEDDING_DIM=300,
        position_matrix_file_path="../data/posi_matrix.npy",
        word2vec_file_path="../data/needed_word2vec.pkl",
        POS_list_file_path="../data/pos_list.txt",
        types_file_path="../data/relations_en.txt",
        corpus_file_path="../data/train_en.txt",
        model_file_path="../data/model/re_sem_eval_en_model_" + testType +
        ".hdf5",
        n_gram_size=1,
    )
    inputer = Inputer(config)
    trainer = Trainer(inputer, testType)
    outputer = Outputer(trainer)
    outputer.getEvaluation(testType)
    predict_texts = [
        " <e1>level</e1> of experience has already been mentioned in the previous <e2>chapter</e2>.",
        " <e1>level</e1> of experience has already been mentioned in the previous <e2>chapter</e2>."
    ]
    import json
    # print(json.dumps(outputer.getDescription(predict_texts, testType), ensure_ascii=False))