Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise usererror on prediction failure. #2248

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from erroranalysis._internal.error_report import as_error_report
from responsibleai._tools.shared.state_directory_management import \
DirectoryManager
from responsibleai.exceptions import UserErrorException
from responsibleai.managers.error_analysis_manager import \
ErrorAnalysisManager as BaseErrorAnalysisManager
from responsibleai.managers.error_analysis_manager import as_error_config
Expand Down Expand Up @@ -71,8 +72,12 @@ def __init__(self, model, dataset, is_multilabel, task_type, classes=None):
ModelTask.MULTILABEL_TEXT_CLASSIFICATION]
if self.task_type in classif_tasks:
dataset = self.dataset.iloc[:, 0].tolist()
self.predictions = self.model.predict(dataset)
self.predict_proba = self.model.predict_proba(dataset)
self.predictions = self._raise_user_error_on_prediction_failure(
self.model.predict, dataset
)
self.predict_proba = self._raise_user_error_on_prediction_failure(
self.model.predict_proba, dataset
)
elif self.task_type == ModelTask.QUESTION_ANSWERING:
self.predictions = self.model.predict(
self.dataset.loc[:, ['context', 'questions']])
Expand Down Expand Up @@ -121,6 +126,15 @@ def predict_proba(self, X):
pred_proba = self.predict_proba[index]
return pred_proba

def _raise_user_error_on_prediction_failure(self, func, *args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as ex:
raise UserErrorException(
"Unable to use user model to retrieve predictions"
f" from given dataset. Original exception: {ex}"
)


class ErrorAnalysisManager(BaseErrorAnalysisManager):

Expand Down
Loading