python - 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
解决方案
推荐阅读
- python - 在 GCP Composer 中升级 python 版本
- reactjs - 未找到模块:无法在 React 中解析“@date-io/date-fns”
- php - Laravel 通过嵌套关系列查找行
- java - onnx 模型确实有多个输入的用例
- python - 使用 playsound 同时播放多个声音
- php - 语法错误或访问冲突:1103 laravel 8
- flutter - 如何在 Flutter 中更新 SliverList 的单个项目?
- arrays - TypeError:“生成器”对象不能解释为整数
- vue.js - Vue 3 Composition API - 生命周期方法中的 Props 默认值和 DOM
- opencv - 使用 pymba open-cv cv2 imshow() 获取帧