Commit
·
f06e4c9
1
Parent(s):
7428fe2
update relevance filtering to allow non relevant only mode
Browse files- README.md +4 -8
- bordirlines.py +25 -31
README.md
CHANGED
@@ -134,11 +134,7 @@ The **control** language is English, and contains the queries for all 251 territ
|
|
134 |
|
135 |
The dataset contains two types of relevance annotations:
|
136 |
|
137 |
-
1. **Human Annotations**:
|
138 |
-
|
139 |
-
- Provided by three annotators for a subset of query-document pairs.
|
140 |
-
- Relevance is determined by majority vote across annotators.
|
141 |
-
- Territories are listed per annotator, capturing individual perspectives.
|
142 |
|
143 |
2. **LLM Annotations**:
|
144 |
- Includes two modes:
|
@@ -227,10 +223,10 @@ ds_m3_zhs1 = load_dataset("borderlines/bordirlines", "zhs", split="m3.en")
|
|
227 |
ds_m3_zhs2 = load_dataset("borderlines/bordirlines", "zhs", split="m3.qlang")
|
228 |
|
229 |
# Load Dataset for English, relevant-only with human annotations
|
230 |
-
ds_human_en = load_dataset("borderlines/bordirlines", "en",
|
231 |
|
232 |
-
# Load Dataset for Simplified Chinese, few-shot LLM mode
|
233 |
-
ds_llm_fewshot_zhs = load_dataset("borderlines/bordirlines", "zhs",
|
234 |
```
|
235 |
|
236 |
## Citation
|
|
|
134 |
|
135 |
The dataset contains two types of relevance annotations:
|
136 |
|
137 |
+
1. **Human Annotations**: Provided by multiple annotators for a subset of query-document pairs and relevance is determined by majority vote across annotators.
|
|
|
|
|
|
|
|
|
138 |
|
139 |
2. **LLM Annotations**:
|
140 |
- Includes two modes:
|
|
|
223 |
ds_m3_zhs2 = load_dataset("borderlines/bordirlines", "zhs", split="m3.qlang")
|
224 |
|
225 |
# Load Dataset for English, relevant-only with human annotations
|
226 |
+
ds_human_en = load_dataset("borderlines/bordirlines", "en", relevance_filter="relevant", annotation_type="human")
|
227 |
|
228 |
+
# Load Dataset for Simplified Chinese, few-shot LLM mode, only non-relevant
|
229 |
+
ds_llm_fewshot_zhs = load_dataset("borderlines/bordirlines", "zhs", relevance_filter="non-relevant", annotation_type="llm", llm_mode="fewshot")
|
230 |
```
|
231 |
|
232 |
## Citation
|
bordirlines.py
CHANGED
@@ -95,11 +95,11 @@ class BordIRLinesDataset(datasets.GeneratorBasedBuilder):
|
|
95 |
for lang in SUPPORTED_LANGUAGES
|
96 |
]
|
97 |
|
98 |
-
def __init__(self, *args,
|
99 |
super().__init__(*args, **kwargs)
|
100 |
-
self.
|
101 |
self.annotation_type = annotation_type
|
102 |
-
self.llm_mode = llm_mode #
|
103 |
|
104 |
def _info(self):
|
105 |
return datasets.DatasetInfo(
|
@@ -116,7 +116,7 @@ class BordIRLinesDataset(datasets.GeneratorBasedBuilder):
|
|
116 |
"doc_text": datasets.Value("string"),
|
117 |
"doc_lang": datasets.Value("string"),
|
118 |
"relevant_human": datasets.Value("bool"),
|
119 |
-
"territory_human": datasets.
|
120 |
"relevant_llm_zeroshot": datasets.Value("bool"),
|
121 |
"relevant_llm_fewshot": datasets.Value("bool"),
|
122 |
}
|
@@ -195,27 +195,12 @@ class BordIRLinesDataset(datasets.GeneratorBasedBuilder):
|
|
195 |
|
196 |
# Get Human Data
|
197 |
human_data = human_map.get((query_id, doc_id), {})
|
198 |
-
# Parse relevant_human_votes manually
|
199 |
-
raw_votes = human_data.get("relevant_human", "[]")
|
200 |
-
relevant_human_votes = [
|
201 |
-
True if v.strip() == "True" else False if v.strip() == "False" else False
|
202 |
-
for v in raw_votes.strip("[]").split(",")
|
203 |
-
if v.strip()
|
204 |
-
]
|
205 |
-
|
206 |
-
# Parse territory_human manually
|
207 |
-
raw_territories = human_data.get("territory_human", "[]")
|
208 |
-
territory_human = [
|
209 |
-
v.strip().strip("'").strip('"') # Remove extra quotes and whitespace
|
210 |
-
for v in raw_territories.strip("[]").split(",")
|
211 |
-
if v.strip()
|
212 |
-
]
|
213 |
-
|
214 |
-
# Calculate majority relevance
|
215 |
-
majority_relevant_human = (
|
216 |
-
sum(relevant_human_votes) > len(relevant_human_votes) / 2 if relevant_human_votes else False
|
217 |
-
)
|
218 |
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
# Get LLM Data
|
221 |
llm_data = llm_map.get((query_id, doc_id), {})
|
@@ -224,15 +209,25 @@ class BordIRLinesDataset(datasets.GeneratorBasedBuilder):
|
|
224 |
if self.llm_mode == "fewshot"
|
225 |
else llm_data.get("relevant_zeroshot", None)
|
226 |
)
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
230 |
continue
|
231 |
elif self.annotation_type == "llm" and not (relevant_llm is True):
|
232 |
continue
|
233 |
-
elif not
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
continue
|
235 |
|
|
|
236 |
|
237 |
yield (
|
238 |
counter,
|
@@ -246,11 +241,10 @@ class BordIRLinesDataset(datasets.GeneratorBasedBuilder):
|
|
246 |
"doc_id": doc_id,
|
247 |
"doc_text": docs[doc_lang][doc_id],
|
248 |
"doc_lang": doc_lang,
|
249 |
-
"relevant_human":
|
250 |
"territory_human": territory_human,
|
251 |
"relevant_llm_zeroshot": llm_data.get("relevant_zeroshot", None),
|
252 |
"relevant_llm_fewshot": llm_data.get("relevant_fewshot", None),
|
253 |
},
|
254 |
)
|
255 |
-
|
256 |
-
counter += 1
|
|
|
95 |
for lang in SUPPORTED_LANGUAGES
|
96 |
]
|
97 |
|
98 |
+
def __init__(self, *args, relevance_filter="all", annotation_type=None, llm_mode="fewshot", **kwargs):
|
99 |
super().__init__(*args, **kwargs)
|
100 |
+
self.relevance_filter = relevance_filter # "relevant", "non-relevant", or "all"
|
101 |
self.annotation_type = annotation_type
|
102 |
+
self.llm_mode = llm_mode # Default to "fewshot"
|
103 |
|
104 |
def _info(self):
|
105 |
return datasets.DatasetInfo(
|
|
|
116 |
"doc_text": datasets.Value("string"),
|
117 |
"doc_lang": datasets.Value("string"),
|
118 |
"relevant_human": datasets.Value("bool"),
|
119 |
+
"territory_human": datasets.Value("string"),
|
120 |
"relevant_llm_zeroshot": datasets.Value("bool"),
|
121 |
"relevant_llm_fewshot": datasets.Value("bool"),
|
122 |
}
|
|
|
195 |
|
196 |
# Get Human Data
|
197 |
human_data = human_map.get((query_id, doc_id), {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
+
# Directly use the new 'relevant' column (no need for tie-breaking)
|
200 |
+
relevant_human = human_data.get("relevant", False) # Default to False if missing
|
201 |
+
|
202 |
+
# Directly use the 'territory' column instead of processing 'territory_human'
|
203 |
+
territory_human = human_data.get("territory", "")
|
204 |
|
205 |
# Get LLM Data
|
206 |
llm_data = llm_map.get((query_id, doc_id), {})
|
|
|
209 |
if self.llm_mode == "fewshot"
|
210 |
else llm_data.get("relevant_zeroshot", None)
|
211 |
)
|
212 |
+
|
213 |
+
# Filtering logic based on relevance preference
|
214 |
+
if self.relevance_filter == "relevant":
|
215 |
+
if self.annotation_type == "human" and not relevant_human:
|
216 |
continue
|
217 |
elif self.annotation_type == "llm" and not (relevant_llm is True):
|
218 |
continue
|
219 |
+
elif not relevant_human and not (relevant_llm is True):
|
220 |
+
continue
|
221 |
+
|
222 |
+
elif self.relevance_filter == "non-relevant":
|
223 |
+
if self.annotation_type == "human" and relevant_human:
|
224 |
+
continue
|
225 |
+
elif self.annotation_type == "llm" and relevant_llm is True:
|
226 |
+
continue
|
227 |
+
elif relevant_human or relevant_llm is True:
|
228 |
continue
|
229 |
|
230 |
+
# If "all", do not filter anything
|
231 |
|
232 |
yield (
|
233 |
counter,
|
|
|
241 |
"doc_id": doc_id,
|
242 |
"doc_text": docs[doc_lang][doc_id],
|
243 |
"doc_lang": doc_lang,
|
244 |
+
"relevant_human": relevant_human,
|
245 |
"territory_human": territory_human,
|
246 |
"relevant_llm_zeroshot": llm_data.get("relevant_zeroshot", None),
|
247 |
"relevant_llm_fewshot": llm_data.get("relevant_fewshot", None),
|
248 |
},
|
249 |
)
|
250 |
+
counter+=1
|
|