📊 Metrics#
- class text_machina.src.metrics.base.Metric(task_type, name)[source]#
Bases:
ABC
Base class for metrics.
- run(dataset, path, **kwargs)[source]#
Calls _run, _save and _log to compute a metric, store and log its outputs.
- Parameters:
dataset (Dataset) – A labeled dataset on which to compute the metric.
path (Path) – A path where to save results.
**kwargs – Additional arguments to pass to _run.
- Return type:
- class text_machina.src.metrics.mauve.MAUVEMetric(task_type, name)[source]#
Bases:
Metric
Implements the MAUVE metric: https://arxiv.org/abs/2102.01454
Supported tasks: detection.
- class text_machina.src.metrics.perplexity.PerplexityMetric(task_type, name)[source]#
Bases:
Metric
Implements the perplexity metric.
Supported tasks: detection, attribution, and boundary.
- class text_machina.src.metrics.repetition_diversity.RepetitionDiversityMetric(task_type, name)[source]#
Bases:
Metric
Implements the repetition and diversity metrics. See Sec. 4.1.2: https://arxiv.org/pdf/2202.06417.pdf
Supported tasks: detection, attribution, and boundary.
- class text_machina.src.metrics.simple_model.SimpleModelMetric(task_type, name)[source]#
Bases:
Metric
Implements simple baseline models evaluated with stratified k-fold validation.
Supported tasks: detection, attribution, and boundary.
- text_machina.src.metrics.simple_model.regression_report(y_true, y_pred)[source]#
Computes a regression report similarly to the classification report offered by scikit-learn.
- Parameters:
y_true (np.ndarray) – the true labels.
y_pred (np.ndarray) – the predicted labels.
- Returns:
the report.
- Return type:
pd.DataFrame
- class text_machina.src.metrics.token_classification.TokenClassificationMetric(task_type, name)[source]#
Bases:
Metric
Implements a HF token classification model for evaluating a mixcase dataset.
Supported tasks: boundary and mixcase.
- text_machina.src.metrics.token_classification.eval(predictions, references, label_mapping)[source]#
Evaluates using seqeval from HF metrics.
- Parameters:
- Return type:
- Returns:
Dict[str, float] -> dictionary with metric values.
- text_machina.src.metrics.token_classification.fit(model, dataset, tokenizer, training_args)[source]#
Fits a model on a dataset.
- Parameters:
model (AutoModelForTokenClassification) – a model.
dataset (Dataset) – a training dataset.
tokenizer (AutoTokenizer) – a tokenizer.
training_args (Dict) – args to be passed to the HF’s Trainer.
- Return type:
- text_machina.src.metrics.token_classification.predict(model, dataset, tokenizer)[source]#
Predicts a dataset using a model.
- Parameters:
model (AutoModelForTokenClassification) – a model.
dataset (Dataset) – a test dataset.
tokenizer (AutoTokenizer) – a tokenizer.
- Returns:
list of predicted labels for each example.
- Return type:
List[List[int]]
- text_machina.src.metrics.token_classification.prepare_dataset(dataset, task_type, tokenizer, test_size, label_mapping)[source]#
Prepares the dataset (tokenization, prepare labels, splitting, etc.).
- text_machina.src.metrics.token_classification.prepare_tags_for_boundary(offset_mappings, labels, label_mapping)[source]#
Prepares the labels for boundary tasks to be addressed as token classification tasks.
This fn is designed to work with the map HF’s function using batched=True.