pyabsa.tasks.AspectSentimentTripletExtraction.prediction.predictor¶
Classes¶
Predictor for Aspect Sentiment Triplet Extraction (ASTE). |
|
Predictor for Aspect Sentiment Triplet Extraction (ASTE). |
Module Contents¶
- class pyabsa.tasks.AspectSentimentTripletExtraction.prediction.predictor.AspectSentimentTripletExtractor(checkpoint=None, **kwargs)¶
Bases:
pyabsa.framework.prediction_class.predictor_template.InferenceModelPredictor for Aspect Sentiment Triplet Extraction (ASTE).
Loads an ASTE checkpoint and provides utilities to extract aspect-opinion pairs and their sentiments from text, supporting both single-text and file-based batch prediction. When gold annotations exist in the input, the predictor can also compute reference triplets for comparison.
- task_code = 'ASTE'¶
- dataset¶
- batch_infer(target_file=None, print_result=True, save_result=False, ignore_error=True, **kwargs)¶
Deprecated alias of batch_predict for file-based inference.
- Parameters:
target_file – Path to the input file or directory.
print_result – Whether to print results (kept for parity).
save_result – Whether to save results (kept for parity).
ignore_error – Skip malformed lines instead of raising.
**kwargs – Additional inference options.
- Returns:
Extracted triplets and optional references.
- Return type:
List[dict]
- infer(text: str = None, print_result=True, ignore_error=True, **kwargs)¶
Deprecated alias of predict for a single string input.
- Parameters:
text – Input sentence to extract triplets from.
print_result – Whether to print results (kept for parity).
ignore_error – Skip parsing errors.
**kwargs – Additional inference options.
- Returns:
Prediction result for the input text, or an error dict.
- Return type:
dict
- batch_predict(target_file=None, print_result=True, save_result=False, ignore_error=True, **kwargs)¶
Run ASTE inference on a dataset file or directory.
- Parameters:
target_file – Path to a file or directory to infer.
print_result – Whether to print results (kept for parity).
save_result – Whether to save results (kept for parity).
ignore_error – Skip malformed lines instead of raising errors.
**kwargs – Additional inference options, e.g., eval_batch_size.
- Returns:
Extracted triplets and optional references.
- Return type:
List[dict]
- predict(text: str | list = None, print_result=True, ignore_error=True, **kwargs)¶
Extract aspect-opinion-sentiment triplets from text.
- Parameters:
text – A single string or list of strings.
print_result – Whether to print results (kept for parity).
ignore_error – Skip parsing errors.
**kwargs – Additional inference options.
- Returns:
Single or batched ASTE results.
- Return type:
dict or List[dict]
- _run_prediction(save_path=None, print_result=True, **kwargs)¶
Internal ASTE inference loop.
Iterates over prepared features, runs the model, decodes the tag sequences into triplets via Metric, and returns structured outputs. If golden labels exist, also parses and returns reference triplets under the “True Triplets” field.
- Parameters:
save_path – Optional result output path (kept for parity).
print_result – Whether to print intermediate results.
**kwargs – Additional control flags.
- Returns:
Extracted triplets for each input sample.
- Return type:
List[dict]
- clear_input_samples()¶
Clear any previously prepared ASTE inference samples.
- class pyabsa.tasks.AspectSentimentTripletExtraction.prediction.predictor.Predictor(checkpoint=None, **kwargs)¶
Bases:
AspectSentimentTripletExtractorPredictor for Aspect Sentiment Triplet Extraction (ASTE).
Loads an ASTE checkpoint and provides utilities to extract aspect-opinion pairs and their sentiments from text, supporting both single-text and file-based batch prediction. When gold annotations exist in the input, the predictor can also compute reference triplets for comparison.