Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindformers.core.EmF1Metric

View Source On Gitee
class mindformers.core.EmF1Metric[source]

Calculate the Em and F1 scores for each example to evaluate the model's performance in prediction tasks.

Em Score: The Em score measures the accuracy of predictions that exactly match the labels, ignoring punctuation. For example, if the question is "河南的省会是哪里?" and the label is "郑州市":

When the prediction is "郑州市", the Em score is 100. When the prediction is "郑州市。", the Em score is 100. When the prediction is "郑州", the Em score is 0.

F1 Score: The F1 score is the harmonic mean of precision and recall, calculated as follows:

F1=2×precision×recallprecision+recall

Where precision and recall are calculated as:

precision=lcs_lengthlen(prediction_segment),recall=lcs_lengthlen(label_segment)

In the above formulas, lcs_length represents the length of the longest common subsequence (LCS).

Calculation Process:

First, calculate the longest common subsequence (LCS) between the prediction and the label to measure the degree of matching. Then, compute the precision and recall based on the respective formulas. Finally, use the F1 score formula to calculate the final F1 value. This evaluation metric comprehensively measures the accuracy and completeness of the model, providing data support for model optimization and debugging.

Examples

>>> from mindformers.core.metric.metric import EmF1Metric
>>>
>>> str_pre = ["I love Beijing, because it's beautiful", "Hello world。"]
>>> str_label = ["I love Beijing.", "Hello world"]
>>> metric = EmF1Metric()
>>> metric.clear()
>>> for pre, label in zip(str_pre, str_label):
...    metric.update([pre], [label])
>>> result = metric.eval()
>>> print(result)
The F1/Em of this example is:  {'F1': 100.0, 'Em': 100.0}
F1 score: 75.0, Em score: 50.0, total_count: 2
{'F1': 75.0, 'Em': 50.0}