Skip to content

Commit

Permalink
Prevent crash if id2label is None
Browse files Browse the repository at this point in the history
This may be the case on old models
  • Loading branch information
tomaarsen committed Dec 4, 2023
1 parent f4cfc3e commit 0f460a2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docker_images/setfit/app/pipelines/text_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __call__(self, inputs: str) -> List[Dict[str, float]]:
"""
probs = self.model.predict_proba([inputs], as_numpy=True)
if probs.ndim == 2:
id2label = getattr(self.model, "id2label", {})
id2label = getattr(self.model, "id2label", {}) or {}
return [
[
{"label": id2label.get(idx, idx), "score": prob}
Expand Down

0 comments on commit 0f460a2

Please sign in to comment.