Skip to content

Commit

Permalink
fix: update ImportError for 'metrics' dependency (#4778)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilgeyucel authored Apr 28, 2023
1 parent 645a5fe commit 5a17a40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions haystack/modeling/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
try:
from seqeval.metrics import classification_report as token_classification_report
except ImportError as exc:
logger.debug("seqeval could not be imported. Run 'pip install farm-haystack[eval]' to fix this issue.")
logger.debug("seqeval could not be imported. Run 'pip install farm-haystack[metrics]' to fix this issue.")
token_classification_report = None


Expand Down Expand Up @@ -150,7 +150,9 @@ def compute_report_metrics(head: PredictionHead, preds, labels):
report_fn = registered_reports[head.ph_output_type] # type: ignore [index]
elif head.ph_output_type == "per_token":
if not token_classification_report:
raise ImportError("seqeval could not be imported. Run 'pip install farm-haystack[eval]' to fix this issue.")
raise ImportError(
"seqeval could not be imported. Run 'pip install farm-haystack[metrics]' to fix this issue."
)
report_fn = token_classification_report
elif head.ph_output_type == "per_sequence":
if not classification_report:
Expand Down
6 changes: 4 additions & 2 deletions haystack/utils/context_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
try:
from rapidfuzz import fuzz
except ImportError as exc:
logger.debug("rapidfuzz could not be imported. Run 'pip install farm-haystack[eval]' to fix this issue.")
logger.debug("rapidfuzz could not be imported. Run 'pip install farm-haystack[metrics]' to fix this issue.")
fuzz = None # type: ignore


Expand Down Expand Up @@ -56,7 +56,9 @@ def calculate_context_similarity(
Thus [AB] <-> [BC] (score ~50) gets recalculated with B <-> B (score ~100) scoring ~75 in total.
"""
if not fuzz:
raise ImportError("rapidfuzz could not be imported. Run 'pip install farm-haystack[eval]' to fix this issue.")
raise ImportError(
"rapidfuzz could not be imported. Run 'pip install farm-haystack[metrics]' to fix this issue."
)
# we need to handle short contexts/contents (e.g single word)
# as they produce high scores by matching if the chars of the word are contained in the other one
# this has to be done after normalizing
Expand Down
6 changes: 4 additions & 2 deletions haystack/utils/experiment_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
try:
import mlflow
except ImportError as exc:
logger.debug("mlflow could not be imported. Run 'pip install farm-haystack[eval]' to fix this issue.")
logger.debug("mlflow could not be imported. Run 'pip install farm-haystack[metrics]' to fix this issue.")
mlflow = None


Expand Down Expand Up @@ -165,7 +165,9 @@ def __init__(self, tracking_uri: str, auto_track_environment: bool = True) -> No
Experiment tracking head for MLflow.
"""
if not mlflow:
raise ImportError("mlflow could not be imported. Run 'pip install farm-haystack[eval]' to fix this issue.")
raise ImportError(
"mlflow could not be imported. Run 'pip install farm-haystack[metrics]' to fix this issue."
)
super().__init__()
self.tracking_uri = tracking_uri
self.auto_track_environment = auto_track_environment
Expand Down

0 comments on commit 5a17a40

Please sign in to comment.