seqeval: Sequence Labeling Evaluation

1.2.2 · active · verified Sun Apr 12

seqeval is a Python framework for sequence labeling evaluation. It provides metrics like F1 score, precision, recall, and a detailed classification report for tasks such as named-entity recognition and part-of-speech tagging. It is currently at version 1.2.2 and maintains an active release cadence, with updates often focusing on performance improvements and additional evaluation schemes.

Warnings

Install

Imports

Quickstart

Calculate the F1-score and generate a detailed classification report for sequence labeling predictions.

from seqeval.metrics import f1_score
from seqeval.metrics import classification_report

y_true = [['O', 'O', 'B-MISC', 'I-MISC', 'B-MISC', 'O', 'O'], ['B-PER', 'I-PER', 'O']]
y_pred = [['O', 'O', 'B-MISC', 'I-MISC', 'B-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]

# Compute F1-score (micro average by default)
print(f"F1 Score (micro): {f1_score(y_true, y_pred):.2f}")

# Compute F1-score with different averaging methods
print(f"F1 Score (average=None): {f1_score(y_true, y_pred, average=None)}")

# Generate a full classification report
report = classification_report(y_true, y_pred, digits=2)
print("\nClassification Report:\n", report)

view raw JSON →