pyabsa.tasks.UniversalSentimentAnalysis.prediction.predictor

Classes

USAPredictor

Predictor for Universal Sentiment Analysis (sequence-to-sequence).

Predictor

Predictor for Universal Sentiment Analysis (sequence-to-sequence).

Module Contents

class pyabsa.tasks.UniversalSentimentAnalysis.prediction.predictor.USAPredictor(checkpoint=None, **kwargs)

Bases: pyabsa.framework.prediction_class.predictor_template.InferenceModel

Predictor for Universal Sentiment Analysis (sequence-to-sequence).

Loads a generative model checkpoint and runs decoding over inputs to obtain structured sentiment outputs defined by the USA task design. Provides single-text and batch prediction convenience methods and dataset auto-detection for file-based inference.

task_code = 'USA'
dataset
batch_infer(target_file=None, print_result=True, save_result=False, ignore_error=True, **kwargs)

Deprecated alias of batch_predict.

Parameters:
  • target_file – Path to the input file or directory.

  • print_result – Whether to print the result (kept for parity).

  • save_result – Whether to save predictions (kept for parity).

  • ignore_error – Skip malformed lines instead of raising errors.

  • **kwargs – Additional inference options.

Returns:

Decoded outputs.

Return type:

List[str]

infer(text: str = None, print_result=True, ignore_error=True, **kwargs)

Deprecated alias of predict for a single string.

Parameters:
  • text – The input text to decode.

  • print_result – Unused; kept for API compatibility.

  • ignore_error – Skip parsing errors.

  • **kwargs – Additional inference options.

Returns:

On success, the decoded string is returned via predict; on error, a dict describing the error is returned.

Return type:

dict

batch_predict(target_file=None, print_result=True, save_result=False, ignore_error=True, **kwargs)

Run USA inference on a dataset file or directory.

Parameters:
  • target_file – Path to a file or directory to infer.

  • print_result – Unused; kept for API compatibility.

  • save_result – Unused; kept for API compatibility.

  • ignore_error – Skip malformed lines instead of raising errors.

  • **kwargs – Additional inference options, e.g., eval_batch_size.

Returns:

Decoded outputs for all inputs.

Return type:

List[str]

predict(text: str | list = None, print_result=True, ignore_error=True, **kwargs)

Decode sentiment outputs for a string or list of strings.

Parameters:
  • text – Single input or a list of inputs.

  • print_result – Unused; kept for API compatibility.

  • ignore_error – Skip malformed inputs.

  • **kwargs – Additional inference options.

Returns:

A single decoded string for single input, otherwise a list of decoded strings.

Return type:

str or List[str]

_run_prediction(save_path=None, print_result=True, **kwargs)

Internal decoding loop for the USA generative model.

Prepares a dataloader over tokenized inputs, generates output sequences on the configured device, and decodes them to strings.

Parameters:
  • save_path – Unused; kept for API compatibility.

  • print_result – Unused; kept for API compatibility.

  • **kwargs – Additional generation options.

Returns:

Decoded outputs for the current dataset split.

Return type:

List[str]

clear_input_samples()
class pyabsa.tasks.UniversalSentimentAnalysis.prediction.predictor.Predictor(checkpoint=None, **kwargs)

Bases: USAPredictor

Predictor for Universal Sentiment Analysis (sequence-to-sequence).

Loads a generative model checkpoint and runs decoding over inputs to obtain structured sentiment outputs defined by the USA task design. Provides single-text and batch prediction convenience methods and dataset auto-detection for file-based inference.