Skip to content

Commit 736efb5

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Fix bug with explainability tokenizer validation
1 parent 4b36213 commit 736efb5

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

unboxapi/__init__.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -597,31 +597,32 @@ def add_model(
597597
) from None
598598

599599
# explainability tokenizer
600-
if not isinstance(explainability_tokenizer, Callable):
601-
raise UnboxValidationError(
602-
f"- `{explainability_tokenizer}` specified as `explainability_tokenizer` is not callable. \n"
603-
) from None
604-
605-
if model_type != ModelType.custom:
606-
try:
607-
if task_type in [TaskType.TextClassification]:
608-
test_input = [
609-
"Unbox is great!",
610-
"Let's see if this function is ready for some error analysis",
611-
]
612-
with HidePrints():
613-
function(model, test_input, **kwargs)
614-
except Exception as e:
615-
exception_stack = "".join(
616-
traceback.format_exception(type(e), e, e.__traceback__)
617-
)
618-
raise UnboxResourceError(
619-
context="There is an issue with the specified `explainability_tokenizer`. \n",
620-
message=f"It is failing with the following error: \n{exception_stack}",
621-
mitigation="Make sure your `explainability_tokenizer` receives a list of sentences as input and returns a list of lists of tokens "
622-
+ "as output. Additionally, you may find it useful to debug it on the Jupyter notebook, to ensure it is working correctly before uploading it.",
600+
if explainability_tokenizer:
601+
if not isinstance(explainability_tokenizer, Callable):
602+
raise UnboxValidationError(
603+
f"- `{explainability_tokenizer}` specified as `explainability_tokenizer` is not callable. \n"
623604
) from None
624605

606+
if model_type != ModelType.custom:
607+
try:
608+
if task_type in [TaskType.TextClassification]:
609+
test_input = [
610+
"Unbox is great!",
611+
"Let's see if this function is ready for some error analysis",
612+
]
613+
with HidePrints():
614+
function(model, test_input, **kwargs)
615+
except Exception as e:
616+
exception_stack = "".join(
617+
traceback.format_exception(type(e), e, e.__traceback__)
618+
)
619+
raise UnboxResourceError(
620+
context="There is an issue with the specified `explainability_tokenizer`. \n",
621+
message=f"It is failing with the following error: \n{exception_stack}",
622+
mitigation="Make sure your `explainability_tokenizer` receives a list of sentences as input and returns a list of lists of tokens "
623+
+ "as output. Additionally, you may find it useful to debug it on the Jupyter notebook, to ensure it is working correctly before uploading it.",
624+
) from None
625+
625626
# Transformers resources
626627
if model_type is ModelType.transformers:
627628
if "tokenizer" not in kwargs:

0 commit comments

Comments
 (0)