Nasty.AST.Classification (Nasty v0.3.0)

View Source

Classification result representing the predicted class for a document.

Used by text classification systems to represent predictions with confidence scores and probability distributions.

Summary

Functions

Creates a new classification result.

Sorts classifications by confidence (highest first).

Types

t()

@type t() :: %Nasty.AST.Classification{
  class: atom(),
  confidence: float(),
  features: map(),
  language: Nasty.AST.Node.language(),
  probabilities: %{required(atom()) => float()}
}

Functions

new(class, confidence, language, opts \\ [])

@spec new(atom(), float(), Nasty.AST.Node.language(), keyword()) :: t()

Creates a new classification result.

Examples

iex> classification = Nasty.AST.Classification.new(:spam, 0.95, :en)
iex> classification.class
:spam
iex> classification.confidence
0.95

sort_by_confidence(classifications)

@spec sort_by_confidence([t()]) :: [t()]

Sorts classifications by confidence (highest first).

Examples

iex> classifications = [
...>   Nasty.AST.Classification.new(:low, 0.3, :en),
...>   Nasty.AST.Classification.new(:high, 0.9, :en),
...>   Nasty.AST.Classification.new(:mid, 0.6, :en)
...> ]
iex> sorted = Nasty.AST.Classification.sort_by_confidence(classifications)
iex> Enum.map(sorted, & &1.class)
[:high, :mid, :low]