Nasty.Operations.Classification behaviour (Nasty v0.3.0)

View Source

Behaviour for language-agnostic text classification.

This behaviour defines the interface for training and using text classifiers that can work with any language.

Summary

Callbacks

Returns supported classification algorithms.

Classifies text or document using trained model.

Trains a classifier on labeled training data.

Types

model()

@type model() :: term()

options()

@type options() :: keyword()

training_data()

@type training_data() :: [
  {text :: String.t() | Nasty.AST.Document.t(), category :: atom()}
]

Callbacks

algorithms()

(optional)
@callback algorithms() :: [atom()]

Returns supported classification algorithms.

classify(model, input, opts)

@callback classify(
  model :: model(),
  input :: String.t() | Nasty.AST.Document.t(),
  opts :: options()
) :: {:ok, Nasty.AST.Classification.t()} | {:error, term()}

Classifies text or document using trained model.

Parameters

  • model - Trained classifier model
  • input - Text string or Document AST to classify
  • opts - Classification options

Returns

  • {:ok, classification} - Classification result with confidence
  • {:error, reason} - Classification error

train(training_data, opts)

@callback train(training_data :: training_data(), opts :: options()) ::
  {:ok, model()} | {:error, term()}

Trains a classifier on labeled training data.

Parameters

  • training_data - List of {text, category} tuples
  • opts - Training options

Returns

  • {:ok, model} - Trained model
  • {:error, reason} - Training error