pyabsa.tasks.TextClassification
Subpackages
pyabsa.tasks.TextClassification.configuration
pyabsa.tasks.TextClassification.dataset_utils
pyabsa.tasks.TextClassification.instructor
pyabsa.tasks.TextClassification.models
pyabsa.tasks.TextClassification.prediction
pyabsa.tasks.TextClassification.trainer
Package Contents
Classes
Trainer class for training PyABSA models |
|
Simple object for storing attributes. |
|
Built-in mutable sequence. |
|
Built-in mutable sequence. |
|
Text Classification or Sentiment analysis datasets |
|
- class pyabsa.tasks.TextClassification.TCTrainer(config: pyabsa.tasks.TextClassification.configuration.tc_configuration.TCConfigManager = None, dataset=None, from_checkpoint: str = None, checkpoint_save_mode: int = ModelSaveOption.SAVE_MODEL_STATE_DICT, auto_device: Union[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.TextClassification.TCConfigManager(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_tc_config(configType: str, newitem: dict)
- static set_tc_config_template(newitem)
- static set_tc_config_base(newitem)
- static set_tc_config_english(newitem)
- static set_tc_config_chinese(newitem)
- static set_tc_config_multilingual(newitem)
- static set_tc_config_glove(newitem)
- static get_tc_config_template()
- static get_tc_config_base()
- static get_tc_config_english()
- static get_tc_config_chinese()
- static get_tc_config_multilingual()
- static get_tc_config_glove()
- class pyabsa.tasks.TextClassification.BERTTCModelList[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_MLP
- BERT
- class pyabsa.tasks.TextClassification.GloVeTCModelList[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.
- LSTM
- class pyabsa.tasks.TextClassification.TCDatasetList[source]
Bases:
list
Text Classification or Sentiment analysis datasets
- SST1
- SST5
- SST2
- AGNews10K
- IMDB10K
- SST
- class pyabsa.tasks.TextClassification.TextClassifier(checkpoint=None, cal_perplexity=False, **kwargs)[source]
Bases:
pyabsa.framework.prediction_class.predictor_template.InferenceModel
- task_code
- _log_write_args()
- batch_infer(target_file=None, print_result=True, save_result=False, ignore_error=True, defense: str = None, **kwargs)
Batch predicts the sentiment of a target file using the model. :param target_file: The path to the target file. :param print_result: Whether to print the result. :param save_result: Whether to save the result. :param ignore_error: Whether to ignore errors and continue. :param defense: The adversarial defense to apply to the input text. :param **kwargs: Additional keyword arguments. :return: The predicted sentiment labels.
- infer(text: Union[str, list] = None, print_result=True, ignore_error=True, defense: str = None, **kwargs)
Predicts the sentiment of a text using the model. :param text: The input text. :param print_result: Whether to print the result. :param ignore_error: Whether to ignore errors and continue. :param defense: The adversarial defense to apply to the input text. :param **kwargs: Additional keyword arguments. :return: The predicted sentiment labels.
- batch_predict(target_file=None, print_result=True, save_result=False, ignore_error=True, **kwargs)
Predict 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: Union[str, list] = None, print_result=True, ignore_error=True, **kwargs)
Predict from a sentence or a list of sentences. param: text: the sentence or a list of 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.
- _run_prediction(save_path=None, print_result=True)
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()
- class pyabsa.tasks.TextClassification.Predictor(checkpoint=None, cal_perplexity=False, **kwargs)[source]
Bases:
TextClassifier