Skip to content

Sure, I can organize the API reference using the format you've suggested. Here is the complete API reference with each class and method listed:

API Reference

textpredict.initialize

Initialize the TextPredict model for a specific task.

Parameters

  • task (str): The task to perform (e.g., 'sentiment', 'emotion', 'zeroshot', 'ner', 'sequence_classification', 'token_classification', 'seq2seq').
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.
  • model_name (str, optional): The model name. Defaults to None.
  • source (str, optional): The source of the model ('huggingface' or 'local'). Defaults to 'huggingface'.

Returns

An initialized TextPredict model.

textpredict.TextPredict.analyze

Analyze the provided texts using the initialized model.

Parameters

  • text (str or list of str): The text(s) to analyze.
  • return_probs (bool, optional): Whether to return probabilities along with predictions. Defaults to False.
  • candidate_labels (list of str, optional): The candidate labels for zero-shot classification. Defaults to None.

Returns

Analysis results for the provided texts.

textpredict.SequenceClassificationTrainer

Trainer class for sequence classification models.

Parameters

  • model_name (str): The name of the model to use.
  • output_dir (str): The directory to save the trained model.
  • config (dict, optional): Configuration dictionary. Defaults to None.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.

Methods

  • textpredict.SequenceClassificationTrainer.train(from_checkpoint=True): Train the model.

Parameters: - from_checkpoint (bool, optional): Whether to train from a checkpoint. Defaults to True.

  • textpredict.SequenceClassificationTrainer.save(): Save the trained model.

  • textpredict.SequenceClassificationTrainer.evaluate(test_dataset, evaluation_config=None): Evaluate the model on the test dataset.

Parameters: - test_dataset (Dataset): The dataset to evaluate the model on. - evaluation_config (dict, optional): Configuration for evaluation. Defaults to None.

Example

from textpredict import SequenceClassificationTrainer
trainer = SequenceClassificationTrainer(model_name='bert-base-uncased', output_dir='./model')
trainer.train()
trainer.save()
results = trainer.evaluate(test_dataset)
print(results)

textpredict.Seq2seqTrainer

Trainer class for sequence-to-sequence models.

Parameters

  • model_name (str): The name of the model to use.
  • output_dir (str): The directory to save the trained model.
  • config (dict, optional): Configuration dictionary. Defaults to None.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.

Methods

  • textpredict.Seq2seqTrainer.train(from_checkpoint=False): Train the model.

Parameters: - from_checkpoint (bool, optional): Whether to train from a checkpoint. Defaults to False.

  • textpredict.Seq2seqTrainer.save(): Save the trained model.

  • textpredict.Seq2seqTrainer.evaluate(test_dataset, evaluation_config=None): Evaluate the model on the test dataset.

Parameters: - test_dataset (Dataset): The dataset to evaluate the model on. - evaluation_config (dict, optional): Configuration for evaluation. Defaults to None.

Example

from textpredict import Seq2seqTrainer
trainer = Seq2seqTrainer(model_name='t5-small', output_dir='./model')
trainer.train()
trainer.save()
results = trainer.evaluate(test_dataset)
print(results)

textpredict.TokenClassificationTrainer

Trainer class for token classification models.

Parameters

  • model_name (str): The name of the model to use.
  • output_dir (str): The directory to save the trained model.
  • config (dict, optional): Configuration dictionary. Defaults to None.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.

Methods

  • textpredict.TokenClassificationTrainer.train(from_checkpoint=False): Train the model.

Parameters: - from_checkpoint (bool, optional): Whether to train from a checkpoint. Defaults to False.

  • textpredict.TokenClassificationTrainer.save(): Save the trained model.

  • textpredict.TokenClassificationTrainer.evaluate(test_dataset, evaluation_config=None): Evaluate the model on the test dataset.

Parameters: - test_dataset (Dataset): The dataset to evaluate the model on. - evaluation_config (dict, optional): Configuration for evaluation. Defaults to None.

Example

from textpredict import TokenClassificationTrainer
trainer = TokenClassificationTrainer(model_name='bert-base-uncased', output_dir='./model')
trainer.train()
trainer.save()
results = trainer.evaluate(test_dataset)
print(results)

textpredict.SequenceClassificationEvaluator

Evaluator class for sequence classification models.

Parameters

  • model_name (str): The name of the model to evaluate.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.
  • evaluation_config (dict, optional): Configuration dictionary. Defaults to None.

Methods

  • textpredict.SequenceClassificationEvaluator.evaluate(): Evaluate the model on the provided dataset.

  • textpredict.SequenceClassificationEvaluator.get_detailed_metrics(): Retrieve detailed evaluation metrics.

  • textpredict.SequenceClassificationEvaluator.save_results(file_path): Save evaluation results to a file.

Example

from textpredict import SequenceClassificationEvaluator
evaluator = SequenceClassificationEvaluator(model_name='./model')
results = evaluator.evaluate(test_dataset)
print(results)

textpredict.Seq2seqEvaluator

Evaluator class for sequence-to-sequence models.

Parameters

  • model_name (str): The name of the model to evaluate.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.
  • evaluation_config (dict, optional): Configuration dictionary. Defaults to None.

Methods

  • textpredict.Seq2seqEvaluator.evaluate(): Evaluate the model on the provided dataset.

  • textpredict.Seq2seqEvaluator.get_detailed_metrics(): Retrieve detailed evaluation metrics.

  • textpredict.Seq2seqEvaluator.save_results(file_path): Save evaluation results to a file.

Example

from textpredict import Seq2seqEvaluator
evaluator = Seq2seqEvaluator(model_name='./model')
results = evaluator.evaluate(test_dataset)
print(results)

textpredict.TokenClassificationEvaluator

Evaluator class for token classification models.

Parameters

  • model_name (str): The name of the model to evaluate.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.
  • evaluation_config (dict, optional): Configuration dictionary. Defaults to None.

Methods

  • textpredict.TokenClassificationEvaluator.evaluate(): Evaluate the model on the provided dataset.

  • textpredict.TokenClassificationEvaluator.get_detailed_metrics(): Retrieve detailed evaluation metrics.

  • textpredict.TokenClassificationEvaluator.save_results(file_path): Save evaluation results to a file.

Example

from textpredict import TokenClassificationEvaluator
evaluator = TokenClassificationEvaluator(model_name='./model')
results = evaluator.evaluate(test_dataset)
print(results)

textpredict.Benchmarking

Class for benchmarking models.

Parameters

  • model_name (str): The name of the model to use.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.

Methods

  • textpredict.Benchmarking.benchmark(dataset): Benchmark the model using the provided dataset.

  • textpredict.Benchmarking.measure_inference_time(dataset): Measure inference time on the provided dataset.

  • textpredict.Benchmarking.measure_memory_usage(dataset): Measure memory usage on the provided dataset.

Example

from textpredict import Benchmarking
benchmark = Benchmarking(model_name='bert-base-uncased')
metrics = benchmark.benchmark(test_dataset)
inference_time = benchmark.measure_inference_time(test_dataset)
memory_usage = benchmark.measure_memory_usage(test_dataset)
print(metrics, inference_time, memory_usage)

textpredict.Explainability

Class for model explainability and feature importance.

Parameters

  • model_name (str): The name of the model to use.
  • task (str): The task to perform.
  • device (str, optional): The device to run the model on. Defaults to 'cpu'.

Methods

  • textpredict.Explainability.feature_importance(text): Get feature importance for the given text.

Example

from textpredict import initialize, Explainability

# Initialize the predictor
predictor = initialize(task='sentiment', device='cpu', model_name='bert-base-uncased')

# Explainability instance
explain = Explainability(model_name='bert-base-uncased', task='sentiment')

# Get feature importance
importance = explain.feature_importance("This is a great product!")
print(importance)