ChunkEvaluator

class paddle.fluid.metrics. ChunkEvaluator ( name=None ) [源代码]

该接口使用mini-batch的chunk_eval累计的counter numbers,来计算准确率、召回率和F1值。ChunkEvaluator有三个状态num_infer_chunks,num_label_chunks和num_correct_chunks,分别对应语块数目、标签中的语块数目、正确识别的语块数目。对于chunking的基础知识,请参考 https://www.aclweb.org/anthology/N01-1025 。ChunkEvalEvaluator计算块检测(chunk detection)的准确率,召回率和F1值,支持IOB, IOE, IOBES和IO标注方案。

参数

  • name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

返回

初始化后的 ChunkEvaluator 对象

返回类型

ChunkEvaluator

代码示例

import paddle.fluid as fluid
# init the chunk-level evaluation manager
metric = fluid.metrics.ChunkEvaluator()

# suppose the model predict 10 chucks, while 8 ones are correct and the ground truth has 9 chucks.
num_infer_chunks = 10
num_label_chunks = 9
num_correct_chunks = 8

metric.update(num_infer_chunks, num_label_chunks, num_correct_chunks)
numpy_precision, numpy_recall, numpy_f1 = metric.eval()

print("precision: %.2f, recall: %.2f, f1: %.2f" % (numpy_precision, numpy_recall, numpy_f1))

# the next batch, predicting 3 perfectly correct chucks.
num_infer_chunks = 3
num_label_chunks = 3
num_correct_chunks = 3

metric.update(num_infer_chunks, num_label_chunks, num_correct_chunks)
numpy_precision, numpy_recall, numpy_f1 = metric.eval()

print("precision: %.2f, recall: %.2f, f1: %.2f" % (numpy_precision, numpy_recall, numpy_f1))

方法

update(num_infer_chunks, num_label_chunks, num_correct_chunks)

该函数使用输入的(num_infer_chunks, num_label_chunks, num_correct_chunks)来累计更新ChunkEvaluator对象的对应状态,更新方式如下:

\[\begin{split}\\ \begin{array}{l}{\text { self. num_infer_chunks }+=\text { num_infer_chunks }} \\ {\text { self. num_Label_chunks }+=\text { num_label_chunks }} \\ {\text { self. num_correct_chunks }+=\text { num_correct_chunks }}\end{array} \\\end{split}\]

参数

  • num_infer_chunks (int|numpy.array) – 给定mini-batch的语块数目。

  • num_label_chunks (int|numpy.array) - 给定mini-batch的标签中的语块数目。

  • num_correct_chunks (int|numpy.array)— 给定mini-batch的正确识别的语块数目。

返回

eval()

该函数计算并返回准确率,召回率和F1值。

返回 准确率,召回率和F1值

返回类型 float