pyabsa.tasks.AspectPolarityClassification

Subpackages

Package Contents

Classes

APCTrainer

Trainer class for training PyABSA models

APCConfigManager

Simple object for storing attributes.

APCModelList

Built-in mutable sequence.

BERTBaselineAPCModelList

Built-in mutable sequence.

GloVeAPCModelList

Built-in mutable sequence.

LCFAPCModelList

Built-in mutable sequence.

PLMAPCModelList

Built-in mutable sequence.

ClassicAPCModelList

Built-in mutable sequence.

APCDatasetList

The following datasets are for aspect polarity classification task.

SentimentClassifier

Predictor

class pyabsa.tasks.AspectPolarityClassification.APCTrainer(config: pyabsa.tasks.AspectPolarityClassification.configuration.apc_configuration.APCConfigManager = 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.AspectPolarityClassification.APCConfigManager(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_apc_config(configType: str, newitem: dict)[source]
static set_apc_config_template(newitem)[source]
static set_apc_config_base(newitem)[source]
static set_apc_config_english(newitem)[source]
static set_apc_config_chinese(newitem)[source]
static set_apc_config_multilingual(newitem)[source]
static set_apc_config_glove(newitem)[source]
static set_apc_config_bert_baseline(newitem)[source]
static get_apc_config_template()[source]
static get_apc_config_base()[source]
static get_apc_config_english()[source]
static get_apc_config_chinese()[source]
static get_apc_config_multilingual()[source]
static get_apc_config_glove()[source]
static get_apc_config_bert_baseline()[source]
class pyabsa.tasks.AspectPolarityClassification.APCModelList[source]

Bases: LCFAPCModelList

Built-in mutable sequence.

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

class pyabsa.tasks.AspectPolarityClassification.BERTBaselineAPCModelList[source]

Bases: PLMAPCModelList

Built-in mutable sequence.

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

class pyabsa.tasks.AspectPolarityClassification.GloVeAPCModelList[source]

Bases: ClassicAPCModelList

Built-in mutable sequence.

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

class pyabsa.tasks.AspectPolarityClassification.LCFAPCModelList[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.

SLIDE_LCF_BERT
SLIDE_LCFS_BERT
LSA_T
LSA_S
FAST_LSA_T
FAST_LSA_S
FAST_LSA_T_V2
FAST_LSA_S_V2
DLCF_DCA_BERT
DLCFS_DCA_BERT
LCF_BERT
FAST_LCF_BERT
LCF_DUAL_BERT
LCFS_BERT
FAST_LCFS_BERT
LCFS_DUAL_BERT
LCA_BERT
BERT_MLP
BERT_SPC
BERT_SPC_V2
FAST_LCF_BERT_ATT
LCF_TEMPLATE_BERT
class pyabsa.tasks.AspectPolarityClassification.PLMAPCModelList[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.

AOA_BERT
ASGCN_BERT
ATAE_LSTM_BERT
Cabasc_BERT
IAN_BERT
LSTM_BERT
MemNet_BERT
MGAN_BERT
RAM_BERT
TC_LSTM_BERT
TD_LSTM_BERT
TNet_LF_BERT
__str__()[source]

Return str(self).

class pyabsa.tasks.AspectPolarityClassification.ClassicAPCModelList[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.

AOA
ASGCN
ATAE_LSTM
Cabasc
IAN
LSTM
MemNet
MGAN
RAM
TC_LSTM
TD_LSTM
TNet_LF
class pyabsa.tasks.AspectPolarityClassification.APCDatasetList[source]

Bases: list

The following datasets are for aspect 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
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.AspectPolarityClassification.SentimentClassifier(checkpoint=None, **kwargs)[source]

Bases: pyabsa.framework.prediction_class.predictor_template.InferenceModel

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

A deprecated version of batch_predict method.

Parameters:
  • target_file (str) – the path to the target file for inference

  • print_result (bool) – whether to print the result

  • save_result (bool) – whether to save the result

  • ignore_error (bool) – whether to ignore the error

Returns:

a dictionary of the results

Return type:

result (dict)

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

A deprecated version of the predict method.

Parameters:
  • text (str) – the text to predict

  • print_result (bool) – whether to print the result

  • ignore_error (bool) – whether to ignore the error

Returns:

a dictionary of the results

Return type:

result (dict)

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.

predict(text: str | list = 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.

merge_results(results)[source]

merge APC results have the same input text

_run_prediction(save_path=None, print_result=True, **kwargs)[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

clear_input_samples()[source]
class pyabsa.tasks.AspectPolarityClassification.Predictor(checkpoint=None, **kwargs)[source]

Bases: SentimentClassifier