evaluation

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package evaluation scores the predictions of fine-tuned pipelines.

Index

Constants

View Source
const MultiLabelThreshold = 0.5

MultiLabelThreshold is the score above which EvaluateTextClassification counts a label as predicted for a multi-label pipeline (whose scores are per-label sigmoids).

Variables

This section is empty.

Functions

func PredictWordTags

func PredictWordTags(ctx context.Context, pipeline *pipelines.TokenClassificationPipeline, examples []datasets.TokenClassificationExample, batchSize int) ([][]string, error)

PredictWordTags returns the tag the pipeline's model predicts for each word of each example: the most likely label of the word's first token, the same token training assigns the word's tag to. A word that has no token (because the input was truncated) is predicted "O".

Types

type ClassScore

type ClassScore struct {
	Precision float64
	Recall    float64
	F1        float64
	Support   int // examples whose gold labels include this class
	Predicted int // examples predicted to have this class
	Correct   int // examples predicted to have this class that do
}

ClassScore holds precision, recall and F1 for one class or label.

type ClassificationReport

type ClassificationReport struct {
	Accuracy   float64
	MacroF1    float64
	WeightedF1 float64
	MicroF1    float64
	PerClass   map[string]ClassScore
}

ClassificationReport scores a classifier against gold labels.

Accuracy is the share of examples whose predicted label set equals the gold set exactly: plain accuracy for single-label data, subset accuracy for multi-label data. MacroF1 is the unweighted mean of the per-class F1, so rare classes count as much as common ones; WeightedF1 weights each class by its support; MicroF1 pools every decision, and for single-label data equals Accuracy. The averages run over every class seen in the gold or the predicted labels, as in scikit-learn.

func EvaluateTextClassification

func EvaluateTextClassification(ctx context.Context, pipeline *pipelines.TextClassificationPipeline, examples []datasets.TextClassificationExample, batchSize int) (ClassificationReport, error)

EvaluateTextClassification runs a text classification pipeline over examples and scores its predictions against their labels. A single-label pipeline is scored on its top label against each example's Label; a multi-label pipeline (see pipelines.WithMultiLabel) on the labels scoring above MultiLabelThreshold against each example's Labels.

func ScoreClassification

func ScoreClassification(gold, predicted []string) (ClassificationReport, error)

ScoreClassification scores single-label predictions, one label per example.

func ScoreMultiLabel

func ScoreMultiLabel(gold, predicted [][]string) (ClassificationReport, error)

ScoreMultiLabel scores multi-label predictions: for each example, the set of labels it has. Duplicate labels within an example count once.

type EntityReport

type EntityReport struct {
	EntityScore
	PerType map[string]EntityScore
}

EntityReport is the entity-level score over all entity types (micro-averaged), and per type.

func EvaluateTokenClassification

func EvaluateTokenClassification(ctx context.Context, pipeline *pipelines.TokenClassificationPipeline, examples []datasets.TokenClassificationExample, batchSize int) (EntityReport, error)

EvaluateTokenClassification runs a token classification pipeline over annotated examples and returns the entity-level scores of its predictions against the examples' tags. Span-annotated examples are converted to word tags as for training, and examples not answered "accept" are left out.

func ScoreEntities

func ScoreEntities(gold, predicted [][]string) (EntityReport, error)

ScoreEntities compares gold and predicted IOB tag sequences, one pair per sentence, at the entity level, as seqeval and conlleval do. Tags are "O", or a "B-" or "I-" prefix followed by the entity type. An "I-" tag that does not continue an entity of its type starts a new one, as in conlleval, so IOB1 and IOB2 tagging both score correctly.

type EntityScore

type EntityScore struct {
	Precision float64
	Recall    float64
	F1        float64
	Gold      int // entities in the gold annotation
	Predicted int // entities predicted
	Correct   int // predicted entities that match a gold entity exactly
}

EntityScore holds entity-level precision, recall and F1. An entity counts as correct only when its type and its exact span both match a gold entity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL