pyabsa.tasks.TextAdversarialDefense.prediction.tad_classifier¶
Classes¶
Functions¶
|
Module Contents¶
- pyabsa.tasks.TextAdversarialDefense.prediction.tad_classifier.init_attacker(tad_classifier, defense)¶
- class pyabsa.tasks.TextAdversarialDefense.prediction.tad_classifier.TADTextClassifier(checkpoint=None, cal_perplexity=False, **kwargs)¶
Bases:
pyabsa.framework.prediction_class.predictor_template.InferenceModel- task_code = 'TAD'¶
- infer_dataloader = None¶
- cal_perplexity = False¶
- _log_write_args()¶
- batch_infer(target_file=None, print_result=True, save_result=False, ignore_error=True, defense: str = None, **kwargs)¶
Batch prediction on an input file. :param target_file: the path of the input file :param print_result: whether to print the prediction results to the console :param save_result: whether to save the prediction results to a file :param ignore_error: whether to ignore errors during inference :param defense: adversarial defense technique to use during inference
- infer(text: str | list = None, print_result=True, ignore_error=True, defense: str = None, **kwargs)¶
Perform prediction on a single text or a list of texts. :param text: the text(s) to perform prediction on :param print_result: whether to print the prediction results to the console :param ignore_error: whether to ignore errors during inference :param defense: adversarial defense technique to use during inference
- batch_predict(target_file=None, print_result=True, save_result=False, ignore_error=True, defense: str = None, **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: str | list = None, print_result=True, ignore_error=True, defense: str = None, **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, defense=None)¶
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.TextAdversarialDefense.prediction.tad_classifier.Predictor(checkpoint=None, cal_perplexity=False, **kwargs)¶
Bases:
TADTextClassifier