forked from castorini/birch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated searcher and cv scripts (castorini#20)
- Loading branch information
1 parent
dca1cd3
commit 1c8041b
Showing
4 changed files
with
104 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,52 @@ | ||
from utils import * | ||
from searcher import * | ||
from shutil import copyfileobj | ||
from args import get_args | ||
|
||
if __name__ == '__main__': | ||
args, _ = get_args() | ||
collection = args.collection | ||
anserini_path = args.anserini_path | ||
index_path = args.index_path | ||
output_fn = args.output_path | ||
folds_path = os.path.join(anserini_path, 'src', 'main', 'resources', 'fine_tuning', args.folds_file) | ||
cv_fold = args.cv_fold | ||
|
||
fqrel = os.path.join(anserini_path, 'src', 'main', 'resources', 'topics-and-qrels', 'qrels.' + collection + '.txt') | ||
ftopic = os.path.join(anserini_path, 'src', 'main', 'resources', 'topics-and-qrels', 'topics.' + collection + '.301-450.601-700.txt') | ||
|
||
qid2docid = get_relevant_docids(fqrel) | ||
qid2text = get_query(ftopic, collection='robust04') | ||
|
||
with open(os.path.join(folds_path)) as f: | ||
folds = json.load(f) | ||
output_fn = os.path.join(args.data_path, 'datasets', "robust04_" + str(cv_fold) + "cv") | ||
|
||
# TODO: dynamic params | ||
if cv_fold == '5': | ||
folds_file = "robust04-paper2-folds.json" | ||
params = ["0.9 0.5 47 9 0.30", | ||
"0.9 0.5 47 9 0.30", | ||
"0.9 0.5 47 9 0.30", | ||
"0.9 0.5 47 9 0.30", | ||
"0.9 0.5 26 8 0.30"] | ||
else: | ||
folds_file = "robust04-paper1-folds.json" | ||
params = ["0.9 0.5 50 17 0.20", | ||
"0.9 0.5 26 8 0.30"] | ||
|
||
folds_path = os.path.join(anserini_path, 'src', 'main', 'resources', 'fine_tuning', folds_file) | ||
|
||
fqrel = os.path.join(anserini_path, 'src', 'main', 'resources', 'topics-and-qrels', 'qrels.robust2004.txt') | ||
ftopic = os.path.join(anserini_path, 'src', 'main', 'resources', 'topics-and-qrels', 'topics.robust04.301-450.601-700.txt') | ||
|
||
qid2docid = get_relevant_docids(fqrel) | ||
qid2text = get_query(ftopic, collection='robust04') | ||
|
||
with open(os.path.join(folds_path)) as f: | ||
folds = json.load(f) | ||
|
||
folder_idx = 1 | ||
docsearch = Searcher(anserini_path) | ||
for topics, param in zip(folds, params): | ||
print(folder_idx) | ||
# Extract each parameter | ||
k1, b, fb_terms, fb_docs, original_query_weight = map(float, param.strip().split()) | ||
searcher = build_searcher(k1=k1, b=b, fb_terms=fb_terms, fb_docs=fb_docs, | ||
original_query_weight=original_query_weight, | ||
index_path=index_path, rm3=True) | ||
search_document(searcher, qid2docid, qid2text, | ||
output_fn + str(folder_idx), | ||
'robust04', 1000, topics) | ||
searcher = docsearch.build_searcher(k1=k1, b=b, fb_terms=fb_terms, fb_docs=fb_docs, | ||
original_query_weight=original_query_weight,index_path=index_path, rm3=True) | ||
docsearch.search_document(searcher, qid2docid, qid2text, output_fn + str(folder_idx), | ||
'robust04', 1000, topics) | ||
|
||
folder_idx += 1 | ||
|
||
with open(output_fn + ".csv", 'w') as outfile: | ||
for infile in [output_fn + str(n) for n in range(1, folder_idx)]: | ||
copyfileobj(open(infile), outfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters