fix: update ImportError for 'metrics' dependency (#4778)

This commit is contained in:
Bilge Yücel 2023-04-28 14:42:51 +03:00 committed by GitHub
parent 645a5fe5ba
commit 5a17a40685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View File

@ -30,7 +30,7 @@ except ImportError as exc:
try: try:
from seqeval.metrics import classification_report as token_classification_report from seqeval.metrics import classification_report as token_classification_report
except ImportError as exc: 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 token_classification_report = None
@ -150,7 +150,9 @@ def compute_report_metrics(head: PredictionHead, preds, labels):
report_fn = registered_reports[head.ph_output_type] # type: ignore [index] report_fn = registered_reports[head.ph_output_type] # type: ignore [index]
elif head.ph_output_type == "per_token": elif head.ph_output_type == "per_token":
if not token_classification_report: 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 report_fn = token_classification_report
elif head.ph_output_type == "per_sequence": elif head.ph_output_type == "per_sequence":
if not classification_report: if not classification_report:

View File

@ -14,7 +14,7 @@ logger = logging.getLogger(__file__)
try: try:
from rapidfuzz import fuzz from rapidfuzz import fuzz
except ImportError as exc: 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 fuzz = None # type: ignore
@ -56,7 +56,9 @@ def calculate_context_similarity(
Thus [AB] <-> [BC] (score ~50) gets recalculated with B <-> B (score ~100) scoring ~75 in total. Thus [AB] <-> [BC] (score ~50) gets recalculated with B <-> B (score ~100) scoring ~75 in total.
""" """
if not fuzz: 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) # 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 # 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 # this has to be done after normalizing

View File

@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
try: try:
import mlflow import mlflow
except ImportError as exc: 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 mlflow = None
@ -165,7 +165,9 @@ class MLflowTrackingHead(BaseTrackingHead):
Experiment tracking head for MLflow. Experiment tracking head for MLflow.
""" """
if not 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__() super().__init__()
self.tracking_uri = tracking_uri self.tracking_uri = tracking_uri
self.auto_track_environment = auto_track_environment self.auto_track_environment = auto_track_environment