capreolus-ir / capreolus

A toolkit for end-to-end neural ad hoc retrieval
https://capreolus.ai
Apache License 2.0
95 stars 32 forks source link

Better Error Description #161

Closed crystina-z closed 3 years ago

crystina-z commented 3 years ago

Currently some error messages are not quite helpful to identify the problem, say:

  1. when the runfile is somehow broken (e.g. if anserini was interrupted during the searching and left the runfile halfly written)

    File "~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/capreolus/evaluator.py", line 131, in search_best_run
    runs = Searcher.load_trec_run(runfile)
    File "~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/capreolus/searcher/__init__.py", line 38, in load_trec_run
    qid, _, docid, rank, score, desc = line.split(" ")
    ValueError: not enough values to unpack (expected 6, got 1)
  2. when runfile does not contain any qid in test set:

    ~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/capreolus/evaluator.py:56: RuntimeWarning: Mean of empty slice.
    scores = np.array(scores).mean(axis=0).tolist()
    ~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/numpy/core/_methods.py:170: RuntimeWarning: invalid value encountered in double_scalars
    ret = ret.dtype.type(ret / rcount)
    Traceback (most recent call last):
    ...
    File "~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/capreolus/task/rerank.py", line 42, in train
    rank_results = self.rank.evaluate()
    File "~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/capreolus/task/rank.py", line 55, in evaluate
    self.get_results_path(), self.benchmark, primary_metric=self.config["optimize"], metrics=metrics
    File "~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/capreolus/evaluator.py", line 138, in search_best_run
    benchmark.relevance_level,
    File "~/anaconda3/envs/MyCapreolus/lib/python3.7/site-packages/capreolus/evaluator.py", line 57, in _eval_runs
    scores = dict(zip(metrics, scores))
    TypeError: zip argument #2 must support iteration

Todo: handle these errors in a way that even first time users would know what's happening

andrewyates commented 3 years ago

This is also related to #99. Maybe what we need is some validation of the file format, so that we can raise our own exception?

andrewyates commented 3 years ago

Was this handled by #174?

crystina-z commented 3 years ago

u mean #178? Yup I think so