pyabsa.framework.predictor_class.predictor_template

Module Contents

Classes

Predictor

class pyabsa.framework.predictor_class.predictor_template.Predictor(checkpoint=None, cal_perplexity=False, **kwargs)[source]

Bases: pyabsa.framework.prediction_class.predictor_template.InferenceModel

to(device=None)[source]

Sets the device on which the model will perform inference.

Parameters:

device – the device to use for inference

cpu()[source]

Sets the device to CPU for performing inference.

cuda(device='cuda:0')[source]

Sets the device to CUDA for performing inference.

Parameters:

device – the CUDA device to use for inference

abstract batch_infer(target_file=None, print_result=True, save_result=False, ignore_error=True, **kwargs)[source]

Runs inference on a batch of data from a file or list, and returns the results.

Parameters:
  • target_file – the path to a file containing the input data, or a list of input data

  • print_result – whether to print the results to the console

  • save_result – whether to save the results to a file

  • ignore_error – whether to ignore errors during inference and continue with the remaining data

  • kwargs – additional arguments to pass to the _run_prediction method

Returns:

a list of results from running inference on the input data

abstract infer(text: str = None, print_result=True, ignore_error=True, **kwargs)[source]

Runs inference on a single input, and returns the result.

Parameters:
  • text – the input text to run inference on

  • print_result – whether to print the result to the console

  • ignore_error – whether to ignore errors during inference and return None instead

  • kwargs – additional arguments to pass to the _run_prediction method

Returns:

the result from running inference on the input text

abstract batch_predict(target_file=None, print_result=True, save_result=False, ignore_error=True, **kwargs)[source]

Predict the sentiment from a file of sentences. param: target_file: the file path of the sentences to be predicted. param: print_result: whether to print the result. param: save_result: whether to save the result. param: ignore_error: whether to ignore the error when predicting. param: kwargs: other parameters.

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

Predict the sentiment from a sentence or a list of sentences. param: text: the sentence to be predicted. param: print_result: whether to print the result. param: ignore_error: whether to ignore the error when predicting. param: kwargs: other parameters.

abstract _run_prediction(save_path=None, print_result=True)[source]
Run prediction on the data in the dataloader, update the results list and return the results.

Args:

save_path: path to save the results in a json file. print_result: if True, print the prediction results.

clear_input_samples()[source]