pyabsa.utils.ensemble_prediction.ensemble_prediction

Module Contents

Classes

VoteEnsemblePredictor

class pyabsa.utils.ensemble_prediction.ensemble_prediction.VoteEnsemblePredictor(predictors: [List, dict], weights: [List, dict] = None, numeric_agg='average', str_agg='max_vote')[source]
numeric_agg(result: list)[source]

Aggregate a list of numeric values.

Parameters:

result – a list of numeric values

Returns:

the aggregated value

__ensemble(result: dict)[source]

Aggregate prediction results by calling the appropriate aggregation method.

Parameters:

result – a dictionary containing the prediction results

Returns:

the aggregated prediction result

__dict_aggregate(result: dict)[source]

Recursively aggregate a dictionary of prediction results.

Parameters:

result – a dictionary containing the prediction results

Returns:

the aggregated prediction result

__list_aggregate(result: list)[source]
predict(text, ignore_error=False, print_result=False)[source]

Predicts on a single text and returns the ensemble result.

Parameters:
  • text (str) – The text to perform prediction on

  • ignore_error (bool) – Whether to ignore any errors that occur during prediction, defaults to False

  • print_result (bool) – Whether to print the prediction result, defaults to False

Returns:

The ensemble prediction result

Return type:

dict

batch_predict(texts, ignore_error=False, print_result=False)[source]

Predicts on a batch of texts using the ensemble of predictors. :param texts: a list of strings to predict on. :param ignore_error: boolean indicating whether to ignore errors or raise exceptions when prediction fails. :param print_result: boolean indicating whether to print the raw results for each predictor. :return: a list of dictionaries, each dictionary containing the aggregated results of the corresponding text in the input list.