-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrec_preferences.py
171 lines (154 loc) · 4.12 KB
/
trec_preferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from dataclasses import dataclass
from pathlib import Path
from pyterrier import started, init
from tqdm import tqdm
from ir_axioms.axiom import (
ArgUC, QTArg, QTPArg, aSL, LNC1, TF_LNC, LB1, PROX1, PROX2, PROX3, PROX4,
PROX5, REG, REG_f, ANTI_REG, ANTI_REG_fastText, ASPECT_REG,
ASPECT_REG_fastText, AND, LEN_AND, M_AND, LEN_M_AND, DIV, LEN_DIV, RS_TF,
RS_TF_IDF, RS_BM25, RS_PL2, RS_QL, TFC1, TFC3, M_TDC, LEN_M_TDC, STMC1,
STMC1_fastText, STMC2, STMC2_fastText
)
if not started():
init(tqdm="auto")
from pyterrier import Transformer
from pyterrier.datasets import get_dataset
from pyterrier.index import IterDictIndexer
from pyterrier.io import read_results
from ir_axioms.backend.pyterrier.experiment import AxiomaticExperiment
@dataclass(frozen=True)
class Track:
edition: int
track: str
dataset: str
contents_field: str
tracks = [
# Track(
# edition=28,
# track="deep.documents",
# dataset="msmarco-document/trec-dl-2019/judged",
# contents_field="body",
# ),
# Track(
# edition=28,
# track="deep.passages",
# dataset="msmarco-passage/trec-dl-2019/judged",
# contents_field="text",
# ),
Track(
edition=29,
track="deep.documents",
dataset="msmarco-document/trec-dl-2020/judged",
contents_field="body",
),
# Track(
# edition=29,
# track="deep.passages",
# dataset="msmarco-passage/trec-dl-2020/judged",
# contents_field="text",
# ),
]
depths = [
10,
20,
# 50,
]
configurations = [
(track, depth)
for depth in depths
for track in tracks
]
axioms = [
ArgUC(),
QTArg(),
QTPArg(),
aSL(),
LNC1(),
TF_LNC(),
LB1(),
PROX1(),
PROX2(),
PROX3(),
PROX4(),
PROX5(),
REG(),
REG_f(),
ANTI_REG(),
ANTI_REG_fastText(),
ASPECT_REG(),
ASPECT_REG_fastText(),
AND(),
LEN_AND(),
M_AND(),
LEN_M_AND(),
DIV(),
LEN_DIV(),
RS_TF(),
RS_TF_IDF(),
RS_BM25(),
RS_PL2(),
RS_QL(),
TFC1(),
TFC3(),
M_TDC(),
LEN_M_TDC(),
STMC1(),
STMC1_fastText(),
STMC2(),
STMC2_fastText(),
]
results_dir = Path(__file__).parent
cache_dir = Path(__file__).parent / "cache"
indices_dir = cache_dir / "indices"
runs_base_dir = Path(
"/mnt/ceph/storage/data-in-progress/data-research/"
"web-search/web-search-trec/trec-system-runs"
)
cache_dir.mkdir(exist_ok=True)
indices_dir.mkdir(exist_ok=True)
print(f"Reading runs from {runs_base_dir.absolute()}")
print(f"Storing results in {results_dir.absolute()}")
print(f"Storing cache in {cache_dir.absolute()}")
print(f"Storing indices in {indices_dir.absolute()}")
for track, depth in configurations:
dataset = get_dataset(f"irds:{track.dataset}")
index_dir = indices_dir / track.dataset.split("/")[0]
runs_dir = runs_base_dir / f"trec{track.edition}" / track.track
run_files = list(runs_dir.iterdir())
if not index_dir.exists():
indexer = IterDictIndexer(str(index_dir.absolute()))
indexer.index(
dataset.get_corpus_iter(),
fields=[track.contents_field]
)
run = [
Transformer.from_df(read_results(result_file))
for result_file in tqdm(run_files, desc="Load runs")
]
run_name = [
result_file.stem.replace("input.", "")
for result_file in run_files
]
axioms_cached = [~axiom for axiom in axioms]
axiom_names = [axiom.name for axiom in axioms]
experiment = AxiomaticExperiment(
retrieval_systems=run,
topics=dataset.get_topics(),
qrels=dataset.get_qrels(),
index=index_dir,
dataset=track.dataset,
contents_accessor=track.contents_field,
axioms=axioms,
axiom_names=axiom_names,
depth=depth,
filter_by_qrels=False,
filter_by_topics=False,
verbose=True,
cache_dir=cache_dir,
)
preferences = experiment.preferences
result_file = results_dir / (
f"trec-{track.edition}-{track.track}-preferences-"
f"all-axioms-depth-{depth}.csv"
)
preferences.to_csv(result_file)