BinClass.Trainer (BinClass v0.3.0)

Copy Markdown View Source

Trains binary text classifiers and returns complete BinClass.Classifier values.

Training includes tokenizer construction, stratified train/validation partitioning, optional class balancing, checkpoint selection, and decision-policy calibration.

Summary

Functions

Trains a binary classifier on the given data stream.

Functions

train(data_stream, opts \\ [])

Trains a binary classifier on the given data stream.

Options

  • :epochs - Positive integer number of training epochs. Defaults to 10.
  • :batch_size - Positive integer batch size for training. Defaults to 32.
  • :learning_rate - Positive initial learning rate. Defaults to 1.0e-3.
  • :decay - Non-negative AdamW weight decay. Defaults to 1.0e-2.
  • :schedule - Learning rate decay schedule. Accepts :linear (Meta FAIR warmup + linear decay), :cosine (warmup + cosine decay), :wsd (warmup-stable-decay), :constant, options tuples like {:linear, warmup_ratio: 0.1}, or a 1-argument schedule function. Defaults to :linear.
  • :labels - Output label names as a two-element list of distinct binaries or %{0 => negative_binary, 1 => positive_binary}. Defaults to ["0", "1"].
  • :target_mode - How training labels are interpreted. :hard accepts only 0 and 1; :soft accepts positive-class probabilities from 0.0 through 1.0. Defaults to :hard.
  • :target_threshold - Boundary used to turn soft targets into binary labels for balancing, validation metrics, and threshold calibration. Defaults to 0.5.
  • :balance - Boolean controlling whether to oversample the smaller class in the training partition. Validation examples are never oversampled. Soft targets are assigned to a class using :target_threshold. Defaults to true.
  • :validation_split - Fraction of full batches to use for validation. Partitions are stratified when both target classes can occur in both. Defaults to 0.1.
  • :patience - Non-negative integer number of epochs to wait for improvement before early stopping. Defaults to 5.
  • :compiler - A module implementing Nx.Defn.Compiler. Defaults to EXLA.
  • :architecture - The named architecture to use. Defaults to :parallel_cnn.
  • :dropout_rate - Dropout rate from 0.0 up to, but excluding, 1.0. Defaults to 0.2.
  • :decision_policy - How probabilities become labels. Accepts :argmax, {:positive_threshold, threshold}, :optimize_threshold, or {:optimize_threshold, options}. Threshold optimization options are :objective (:accuracy, :balanced_accuracy, or :f1) and :false_positive_cost. Defaults to :argmax.
  • :minimum_input_tokens - Inputs with fewer active tokens return :insufficient_input at inference. Defaults to 0.
  • :vector_length - Positive fixed sequence length satisfying the architecture's minimum. Defaults to 512.
  • :vocab_size - Positive maximum vocabulary size for tokenizer training. Defaults to 8_000.
  • :normalizer - Text normalizer to apply before tokenization. Accepts :nfkc_lowercase (default), :nfkc, :lowercase, :none, nil, or a Tokenizers.Normalizer struct.
  • :label_smoothing - Label smoothing factor $lpha in [0.0, 0.5]$ applied to target labels during training to regularize extreme confidence. Defaults to 0.0 (no smoothing).
  • :seed - Optional integer seed for deterministic partition ordering, model initialization, and dropout. Defaults to nondeterministic training.