首页 > 解决方案 > SpaCy 评估结果为 0 或 1

问题描述

我运行以下代码在训练集 (75%) 上训练我的 NER 模型,并在验证集 (25%) 上评估总共 20 次迭代。

other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner']
val_score = []
with nlp.disable_pipes(*other_pipes):  # only train NER
    optimizer = nlp.begin_training()
    for itn in range(n_iter):
        print(itn, '/', n_iter)
        random.shuffle(train_doc)
        losses = {}
        nlp.update(
            [Example.from_dict(nlp(text), annotations) for text, annotations in tqdm(train_doc)],
            drop=0.5,  
            sgd=optimizer,
            losses=losses)
        curr_score = nlp.evaluate( [Example.from_dict(nlp.make_doc(text), annotations) for text, annotations in val_doc])
        val_score.append(curr_score)
        print(losses, curr_score)

但是,评估结果看起来不太正常。它不是 0 就是 1,感觉我的模型并没有真正做出任何预测。什么地方出了错?非常感谢。

以下是迭代的结果之一:

{'ner':3545.82652258873} {'token_acc':1.0,'token_p':1.0,'token_r':1.0,'token_f':1.0,'ents_p':0.0,'ents_r':0.0,'ents_f':0.0, 'ents_per_type': {'location': {'p': 0.0, 'r': 0.0, 'f': 0.0}, 'group': {'p': 0.0, 'r': 0.0, 'f': 0.0}, '创意工作': {'p': 0.0, 'r': 0.0, 'f': 0.0}, 'person': {'p': 0.0, 'r': 0.0, 'f': 0.0},“公司”:{“p”:0.0,“r”:0.0,“f”:0.0},“产品”:{“p”:0.0,“r”:0.0,“f”:0.0} },“速度”:29769.152836530662} 12 / 20

标签: pythonvalidationspacynamed-entity-recognition

解决方案


推荐阅读