eval

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package eval measures classifier accuracy against a hand-labelled corpus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Case

type Case struct {
	ID       string `json:"id"`
	Log      string `json:"log"`
	Expected string `json:"expected_category"`
	Note     string `json:"note"`
}

Case is one hand-labelled excerpt.

type CategoryScore

type CategoryScore struct {
	Category  verdict.Category `json:"category"`
	Support   int              `json:"support"`   // labelled instances of this category
	Predicted int              `json:"predicted"` // times the classifier chose it
	TruePos   int              `json:"true_positives"`
	Precision float64          `json:"precision"`
	Recall    float64          `json:"recall"`
	F1        float64          `json:"f1"`
}

CategoryScore is precision, recall and F1 for one category.

type Corpus

type Corpus struct {
	Description string `json:"description"`
	LabelPolicy string `json:"label_policy"`
	Cases       []Case `json:"cases"`
	// contains filtered or unexported fields
}

Corpus is the labelled dataset.

func LoadCorpus

func LoadCorpus(path string) (*Corpus, error)

LoadCorpus reads a labelled case file and validates every label.

func (*Corpus) Excerpt

func (c *Corpus) Excerpt(kase Case) (string, error)

Excerpt reads the log body for a case.

type Outcome

type Outcome struct {
	CaseID       string           `json:"case_id"`
	Expected     verdict.Category `json:"expected"`
	Predicted    verdict.Category `json:"predicted"`
	Confidence   float64          `json:"confidence"`
	Correct      bool             `json:"correct"`
	Hallucinated int              `json:"hallucinated"`
	Error        string           `json:"error,omitempty"`
}

Outcome is one case's result.

type Scores

type Scores struct {
	Provider string `json:"provider"`
	Model    string `json:"model"`
	// Baseline marks results from the rule-based provider so no reader can
	// mistake them for a language model's accuracy.
	Baseline bool `json:"baseline"`

	Total    int     `json:"total"`
	Correct  int     `json:"correct"`
	Errored  int     `json:"errored"`
	Accuracy float64 `json:"accuracy"`
	// MacroF1 averages per-category F1 without weighting by support, so a large
	// easy category cannot hide poor performance on a small hard one.
	MacroF1 float64 `json:"macro_f1"`

	PerCategory []CategoryScore `json:"per_category"`
	// Confusion[actual][predicted] counts.
	Confusion map[verdict.Category]map[verdict.Category]int `json:"confusion"`

	MeanConfidenceCorrect float64 `json:"mean_confidence_correct"`
	MeanConfidenceWrong   float64 `json:"mean_confidence_wrong"`
	HallucinatedCitations int     `json:"hallucinated_citations"`
}

Scores is the full evaluation result.

func Run

func Run(ctx context.Context, corpus *Corpus, provider llm.Provider, floor float64, onCase func(Outcome)) (Scores, error)

Run classifies every case and scores the results.

Each case is treated as an independent classification with no shared state, so ordering cannot leak information between cases and the score is a fair measure of single-shot accuracy.

func Score

func Score(outcomes []Outcome) Scores

Score turns a set of outcomes into aggregate metrics.

func (Scores) ConfusionMatrix

func (s Scores) ConfusionMatrix() string

ConfusionMatrix renders the matrix as a fixed-width text table.

Jump to

Keyboard shortcuts

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