pyabsa.tasks.AspectTermExtraction

Subpackages

Package Contents

Classes

ATEPCTrainer

Trainer class for training PyABSA models

ATEPCConfigManager

Simple object for storing attributes.

ATEPCModelList

Built-in mutable sequence.

ATEPCDatasetList

ATEPCDatasetList is a list of datasets for aspect term extraction and polarity classification task.

AspectExtractor

Predictor

class pyabsa.tasks.AspectTermExtraction.ATEPCTrainer(config: pyabsa.tasks.AspectTermExtraction.configuration.atepc_configuration.ATEPCConfigManager = None, dataset=None, from_checkpoint: str = None, checkpoint_save_mode: int = ModelSaveOption.SAVE_MODEL_STATE_DICT, auto_device: bool | str = DeviceTypeOption.AUTO, path_to_save=None, load_aug=False)[source]

Bases: pyabsa.framework.trainer_class.trainer_template.Trainer

Trainer class for training PyABSA models

class pyabsa.tasks.AspectTermExtraction.ATEPCConfigManager(args, **kwargs)[source]

Bases: pyabsa.framework.configuration_class.configuration_template.ConfigManager

Simple object for storing attributes.

Implements equality by attribute names and values, and provides a simple string representation.

static set_atepc_config(configType: str, newitem: dict)[source]
static set_atepc_config_template(newitem)[source]
static set_atepc_config_base(newitem)[source]
static set_atepc_config_english(newitem)[source]
static set_atepc_config_chinese(newitem)[source]
static set_atepc_config_multilingual(newitem)[source]
static get_atepc_config_template()[source]
static get_atepc_config_base()[source]
static get_atepc_config_english()[source]
static get_atepc_config_chinese()[source]
static get_atepc_config_multilingual()[source]
class pyabsa.tasks.AspectTermExtraction.ATEPCModelList[source]

Bases: list

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

BERT_BASE_ATEPC
FAST_LCF_ATEPC
FAST_LCFS_ATEPC
LCF_ATEPC
LCF_ATEPC_LARGE
LCFS_ATEPC
LCFS_ATEPC_LARGE
LCF_TEMPLATE_ATEPC
class pyabsa.tasks.AspectTermExtraction.ATEPCDatasetList[source]

Bases: list

ATEPCDatasetList is a list of datasets for aspect term extraction and polarity classification task. The datasets are collected from different sources, you can use the id to locate the dataset.

Laptop14
Restaurant14
ARTS_Laptop14
ARTS_Restaurant14
Restaurant15
Restaurant16
ACL_Twitter
MAMS
Television
TShirt
Yelp
Phone
Car
Notebook
Camera
Shampoo
MOOC
MOOC_En
Kaggle
FinNews
Chinese_Zhang
Chinese
Binary_Polarity_Chinese
Triple_Polarity_Chinese
SemEval2016Task5
Arabic_SemEval2016Task5
Dutch_SemEval2016Task5
Spanish_SemEval2016Task5
Turkish_SemEval2016Task5
Russian_SemEval2016Task5
French_SemEval2016Task5
English_SemEval2016Task5
English
SemEval
Restaurant
Multilingual
class pyabsa.tasks.AspectTermExtraction.AspectExtractor(checkpoint=None, **kwargs)[source]

Bases: pyabsa.framework.prediction_class.predictor_template.InferenceModel

task_code
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.Predictor(checkpoint=None, **kwargs)[source]

Bases: AspectExtractor