Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to configure result_count #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions diffir/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def main():
"--metric", dest="metric", type=str, default="nDCG@10", help="metric to report and used with qrel measure"
)
parser.add_argument("--topk", dest="topk", type=int, default=50, help="number of queries to compare")
parser.add_argument("--result_count", dest="result_count", type=int, default=10, help="number of documents to compare for each query")
parser.add_argument("--weights_1", dest="weights_1", type=str, default=None, required=False)
parser.add_argument("--weights_2", dest="weights_2", type=str, default=None, required=False)
args = parser.parse_args()
Expand All @@ -41,6 +42,7 @@ def main():
"metric": args.metric,
"topk": args.topk,
"weight": {"weights_1": args.weights_1, "weights_2": args.weights_2},
"result_count": args.result_count,
}
if not (args.cli or args.web):
args.cli = True # default
Expand Down Expand Up @@ -69,7 +71,7 @@ class MainTask:
module_type = "task"
module_name = "main"

def __init__(self, dataset="none", queries="none", measure="topk", metric="weighted_tau", topk=3, weight={}):
def __init__(self, dataset="none", queries="none", measure="topk", metric="weighted_tau", topk=3, weight={}, result_count=10):
self.dataset = dataset
self.queries = queries
if measure == "qrel":
Expand All @@ -80,11 +82,12 @@ def __init__(self, dataset="none", queries="none", measure="topk", metric="weigh
raise ValueError("Measure {} is not supported".format(measure))

self.weight = WeightBuilder(weight["weights_1"], weight["weights_2"])
self.result_count = result_count

def compute_qrel_metrics(self):
pass

def create_query_objects(self, run_1, run_2, qids, qid2diff, metric_name, dataset, qid2qrelscores=None):
def create_query_objects(self, run_1, run_2, qids, qid2diff, metric_name, dataset, qid2qrelscores=None, result_count=10):
"""
TODO: Need a better name
This method takes in 2 runs and a set of qids, and constructs a dict for each qid (format specified below)
Expand Down Expand Up @@ -126,11 +129,10 @@ def create_query_objects(self, run_1, run_2, qids, qid2diff, metric_name, datase
if query.query_id not in qids_set:
continue

RESULT_COUNT = 10
doc_ids = (
set(list(run_1[query.query_id])[:RESULT_COUNT] + list(run_2[query.query_id])[:RESULT_COUNT])
set(list(run_1[query.query_id])[:result_count] + list(run_2[query.query_id])[:result_count])
if run_2
else list(run_1[query.query_id])[:RESULT_COUNT]
else list(run_1[query.query_id])[:result_count]
)

fields = query._asdict()
Expand Down Expand Up @@ -383,7 +385,7 @@ def json(self, run_1_fn, run_2_fn=None):
diff_queries, qid2diff, metric_name, qid2qrelscores = self.measure.query_differences(run_1, run_2, dataset=dataset)
# _logger.info(diff_queries)
diff_query_objects = self.create_query_objects(
run_1, run_2, diff_queries, qid2diff, metric_name, dataset, qid2qrelscores=qid2qrelscores
run_1, run_2, diff_queries, qid2diff, metric_name, dataset, qid2qrelscores=qid2qrelscores, result_count=self.result_count
)
doc_objects = self.create_doc_objects(diff_query_objects, dataset)

Expand Down