Nasty.Language.Spanish.TextClassifier (Nasty v0.3.0)

View Source

Classifies Spanish text into categories using Naive Bayes.

Supports multi-class and multi-label classification with TF-IDF feature extraction and Naive Bayes classification.

Features

  • Bag-of-words with Spanish stop words
  • TF-IDF weighting
  • N-gram features (unigrams, bigrams)
  • Training on labeled examples

Example

iex> classifier = TextClassifier.train([
...>   {"Este producto es excelente", :positive},
...>   {"No me gusta nada", :negative}
...> ])
iex> TextClassifier.classify("Me encanta este producto", classifier)
{:ok, :positive, 0.87}

Summary

Functions

Classifies a Spanish text using a trained model.

Trains a Spanish text classifier on labeled examples.

Functions

classify(text, model)

@spec classify(String.t(), map()) :: {:ok, atom(), float()} | {:error, String.t()}

Classifies a Spanish text using a trained model.

Parameters

  • text - Text to classify
  • model - Trained classifier from train/2

Returns

{:ok, label, confidence} or {:error, reason}

train(examples, opts \\ [])

@spec train(
  [{String.t(), atom()}],
  keyword()
) :: map()

Trains a Spanish text classifier on labeled examples.

Parameters

  • examples - List of {text, label} tuples
  • opts - Options:
    • :ngrams - N-gram size (default: 1)
    • :min_freq - Minimum term frequency (default: 1)

Returns

A trained classifier model.