Exemplo n.º 1
0
def load_data_for_segmentation(doc_num):
    print('Interview:', doc_num)
    path = './data/segmentation/sentence/interview-text_' + doc_num + '.txt'
    # ans
    # path = './data/eval/interview-text_sentence_' + doc_num + '.txt'

    return utils.load_data_segment(path)
Exemplo n.º 2
0
def load_data_for_segmentation(doc_num, *, ans=False):
    print('Interview:', doc_num)
    path = './data/segmentation/sentence/interview-text_' + doc_num + '.txt'
    # path = './data/segmentation/utterance/interview-text_' + doc_num + '.txt'
    if ans:
        path = './data/eval/interview-text_sentence_' + doc_num + '.txt'

    return utils.load_data_segment(path)
Exemplo n.º 3
0
def evaluation(res, segmentation_model, segmentation_type, model_type,
               doc_type, doc_num):
    count = 0
    label_for_eval = []
    path_for_eval = './data/eval/interview-text_' + doc_type + '_' + doc_num + '.txt'
    sentence = False
    if doc_type == 'sentence':
        sentence = True
    data_for_eval = utils.load_data_segment(path_for_eval, sentence=sentence)
    label_for_eval = [
        item[0] for item in data_for_eval.items() if '____' in item[1][0]
    ]

    print('予測:', res.index.values)
    print('正解:', label_for_eval)

    # 精度、再現率
    plus_label_for_eval = [val + 1 for val in label_for_eval]
    minas_label_for_eval = [val - 1 for val in label_for_eval]
    approx_label_for_eval = copy.deepcopy(label_for_eval)
    approx_label_for_eval.extend(plus_label_for_eval)
    approx_label_for_eval.extend(minas_label_for_eval)
    for i in res.index.values:
        i = float(i)
        # 前後許容
        if i in approx_label_for_eval or i + 1 in approx_label_for_eval or i - 1 in approx_label_for_eval:
            count += 1

    p = count / len(res.index.values)
    r = count / len(label_for_eval)
    f_score = 2 * 1 / (1 / r + 1 / p)
    print("Precision:", p)
    print("Recall:", r)
    print("F score:", f_score)

    save_path = './result/segmentation/' + segmentation_type + '/' + model_type + '/' + doc_type + '/evaluation/' + 'doc_num_' + doc_num + '_' + model_type + '_window_size_' + str(
        segmentation_model.window_size) + '_' + str(datetime.date.today())

    with open(save_path + '.txt', 'w') as f:
        print('予測:', res.index.values, file=f)
        print('正解:', label_for_eval, file=f)
        print("Precision:", p, file=f)
        print("Recall:", r, file=f)
        print("F score:", f_score, file=f)

    return count, label_for_eval, f_score