crystina-z commited on
Commit
bf3af95
·
1 Parent(s): 8d0a106

random 10 + skip unfound

Browse files
Files changed (1) hide show
  1. mmarco-train.py +19 -1
mmarco-train.py CHANGED
@@ -20,6 +20,7 @@ from collections import defaultdict
20
  from gc import collect
21
  import datasets
22
  from tqdm import tqdm
 
23
 
24
 
25
  _CITATION = """
@@ -181,6 +182,9 @@ class MMarco(datasets.GeneratorBasedBuilder):
181
 
182
  # it would generate language by language so that it would be easier to constrain that each batch only contain one language;
183
  for lang in tqdm(languages, desc=f"Preparing training example for {len(languages)} languages."):
 
 
 
184
  collection_path, queries_path = args["collection"][lang], args["queries"][lang]
185
 
186
  collection = {}
@@ -194,7 +198,20 @@ class MMarco(datasets.GeneratorBasedBuilder):
194
 
195
  assert len(runs) == self.size_per_lang[lang]
196
  for query_id, (pos_ids, neg_ids) in runs.items():
 
 
 
 
197
  pos_ids, neg_ids = list(pos_ids), list(neg_ids)
 
 
 
 
 
 
 
 
 
198
  features = {
199
  "query_id": query_id,
200
  "query": queries[query_id],
@@ -207,4 +224,5 @@ class MMarco(datasets.GeneratorBasedBuilder):
207
  "text": collection[neg_id],
208
  } for neg_id in neg_ids],
209
  }
210
- yield f"{lang}-{query_id}-{idx}", features
 
 
20
  from gc import collect
21
  import datasets
22
  from tqdm import tqdm
23
+ import random
24
 
25
 
26
  _CITATION = """
 
182
 
183
  # it would generate language by language so that it would be easier to constrain that each batch only contain one language;
184
  for lang in tqdm(languages, desc=f"Preparing training example for {len(languages)} languages."):
185
+ n_missed_q = 0
186
+ n_missed_d = 0
187
+
188
  collection_path, queries_path = args["collection"][lang], args["queries"][lang]
189
 
190
  collection = {}
 
198
 
199
  assert len(runs) == self.size_per_lang[lang]
200
  for query_id, (pos_ids, neg_ids) in runs.items():
201
+ if query_id not in queries:
202
+ n_missed_q += 1
203
+ continue
204
+
205
  pos_ids, neg_ids = list(pos_ids), list(neg_ids)
206
+ pos_ids = [d for d in pos_ids if d in collection]
207
+ neg_ids = [d for d in neg_ids if d in collection]
208
+ if len(neg_ids) == 0 or len(pos_ids) == 0:
209
+ n_missed_d += 1
210
+ continue
211
+
212
+ NNEG = min(10, len(neg_ids))
213
+ neg_ids = random.choices(neg_ids, k=NNEG)
214
+
215
  features = {
216
  "query_id": query_id,
217
  "query": queries[query_id],
 
224
  "text": collection[neg_id],
225
  } for neg_id in neg_ids],
226
  }
227
+ yield f"{lang}-{query_id}-{idx}", features
228
+ print(f'Number of missed Q: {n_missed_q}. Number of missed D: {n_missed_d}')