Exemplo n.º 1
0
def copy_move(src_path, dest_path):
    '''
    :param src_path 源文件
    :param dest_path 需要剪切到的路径
    将文件剪切到另一个文件夹
    '''
    try:
        check_utils.check_path(dest_path)
        shutil.move(src_path, dest_path)
    except:
        pass
Exemplo n.º 2
0
def run(model_name):
    '''
    根据模型的不同选择使用的模型代码
    :param model: 模型类型 bilstm_crf    bert_bilstm_crf   lstm_crf     wordvec_bilstm_crf
    :return:
    '''
    if model_name == 'bilstm_crf':
        x_train, y_train, x_test, y_test, vocab_length, labels_to_ix_length = process_data_for_keras.process_data(
            embeding="bilstm")
        model = keras_BILSTM_CEF.build_embedding_bilstm2_crf_model(
            vocab_length, labels_to_ix_length, 0)
        save_path = normal_param.save_path_bilstm
    elif model_name == "rnn_crf":
        x_train, y_train, x_test, y_test, vocab_length, labels_to_ix_length = process_data_for_keras.process_data(
            embeding="rnn")
        model = keras_RNN_CRF.build_embedding_lstm2_crf_model(
            vocab_length, labels_to_ix_length, 0)
        save_path = normal_param.save_path_gru
    elif model_name == 'bert_bilstm_crf':
        x_train, y_train, x_test, y_test, vocab_length, labels_to_ix_length = process_data_for_keras.process_data(
            embeding="bert")
        model = keras_Bert_bilstm_crf.build_bilstm_crf_model(
            labels_to_ix_length)
        save_path = normal_param.save_path_bert_bilstm
    elif model_name == 'lstm_crf':
        x_train, y_train, x_test, y_test, vocab_length, labels_to_ix_length = process_data_for_keras.process_data(
            embeding="lstm")
        model = keras_LSTM_CRF.build_embedding_lstm2_crf_model(
            vocab_length, labels_to_ix_length, 0)
        save_path = normal_param.save_path_lstm
    else:
        embeddings_matrix, vocab = process_data_for_keras.txtpad_use_word2vec()
        x_train, y_train, x_test, y_test, vocab_length, labels_to_ix_length = process_data_for_keras.process_data(
            embeding="wordvec", vocab2=vocab)

        model = keras_word2vec_bilstm_crf.build_embedding_bilstm2_crf_model(
            labels_to_ix_length, embeddings_matrix, normal_param.max_length)
        save_path = normal_param.save_path_wordVEC_bilstm

    if check_utils.check_path(save_path):
        model.load_weights(save_path)
    model.fit(x_train,
              y_train,
              batch_size=18,
              epochs=20,
              validation_data=(x_test, y_test),
              shuffle=False,
              validation_split=0.2,
              verbose=1)
    keras_BILSTM_CEF.save_embedding_bilstm2_crf_model(model, save_path)
Exemplo n.º 3
0
def read_path(head_path):
    '''
    根据头路径获取不同路径下对应的txt和label文件路径信息
    :param head_path: 头路径的文件信息
    :return: label_path, content_path
    '''
    content_head_path = os.path.join(head_path, "txt")
    label_head_path = os.path.join(head_path, "label")
    names = os.listdir(content_head_path)
    content_paths = []
    label_paths = []
    for name in names:
        content_path = os.path.join(content_head_path, name)
        label_path = os.path.join(label_head_path, name)
        if not check_utils.check_path(label_path):
            continue
        content_paths.append(content_path)
        label_paths.append(label_path)
    return label_paths, content_paths