pyabsa.tasks.AspectTermExtraction.prediction.aspect_extractor

Module Contents

Classes

AspectExtractor

Predictor

class pyabsa.tasks.AspectTermExtraction.prediction.aspect_extractor.AspectExtractor(checkpoint=None, **kwargs)[source]

Bases: pyabsa.framework.prediction_class.predictor_template.InferenceModel

task_code[source]
merge_result(sentence_res, results)[source]

merge ate sentence result and apc results, and restore to original sentence order :param sentence_res: list of ate sentence results, which has (tokens, iobs) :type sentence_res: [tuple] :param results: list of apc results :type results: [dict]

Returns:

merged extraction/polarity results for each input example

Return type:

[dict]

extract_aspect(inference_source: List[pathlib.Path] | list | str, save_result=True, print_result=True, pred_sentiment=True, **kwargs)[source]

Extract aspects and their corresponding polarities from a list of input files.

Parameters:
  • self – An instance of the model class.

  • inference_source – A list of file paths, or a directory containing files to be processed.

  • save_result (bool) – Whether to save the output to a file. Default is True.

  • print_result (bool) – Whether to print the output to the console. Default is True.

  • pred_sentiment (bool) – Whether to predict the sentiment of each aspect. Default is True.

  • **kwargs – Additional keyword arguments to be passed to the batch_predict method.

Returns:

The predicted aspects and their corresponding polarities.

predict(text: str | List[str], save_result=True, print_result=True, pred_sentiment=True, **kwargs)[source]
Parameters:
  • text (str) – input example

  • save_result (bool) – whether to save the result to file

  • print_result (bool) – whether to print the result to console

  • pred_sentiment (bool) – whether to predict sentiment

batch_predict(target_file: List[pathlib.Path] | list | str, save_result=True, print_result=True, pred_sentiment=True, **kwargs)[source]
Parameters:
  • target_file (list) – list of input examples or a list of files to be predicted

  • save_result (bool, optional) – save result to file. Defaults to True.

  • print_result (bool, optional) – print result to console. Defaults to True.

  • pred_sentiment (bool, optional) – predict sentiment. Defaults to True.

Returns:

_extract(examples)[source]
_run_prediction(examples)[source]

This method should be implemented in the subclass for running predictions using the trained model.

Parameters:

kwargs – additional keyword arguments

Returns:

predicted labels or other prediction outputs

class pyabsa.tasks.AspectTermExtraction.prediction.aspect_extractor.Predictor(checkpoint=None, **kwargs)[source]

Bases: AspectExtractor