leonardo-avila commited on
Commit
4d4b98e
1 Parent(s): f9200b2

Update fiqa_pt.py

Browse files
Files changed (1) hide show
  1. fiqa_pt.py +34 -14
fiqa_pt.py CHANGED
@@ -6,10 +6,11 @@ import datasets
6
  logger = datasets.logging.get_logger(__name__)
7
 
8
  _DESCRIPTION = "FIQA Dataset"
9
- _SPLITS = ["corpus", "topics"]
10
 
11
  URL = ""
12
- _URLs = {subset: URL + f"{subset}_pt.tsv" for subset in _SPLITS}
 
13
 
14
  class BEIR(datasets.GeneratorBasedBuilder):
15
  """BEIR BenchmarkDataset."""
@@ -18,17 +19,26 @@ class BEIR(datasets.GeneratorBasedBuilder):
18
  datasets.BuilderConfig(
19
  name=name,
20
  description=f"This is the {name} in the FiQA dataset.",
21
- ) for name in _SPLITS
22
  ]
23
 
24
  def _info(self):
25
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  return datasets.DatasetInfo(
27
  description=_DESCRIPTION,
28
- features=datasets.Features({
29
- #"id": datasets.Value("string"),
30
- "text": datasets.Value("string"),
31
- }),
32
  supervised_keys=None,
33
  )
34
 
@@ -48,10 +58,20 @@ class BEIR(datasets.GeneratorBasedBuilder):
48
 
49
  def _generate_examples(self, filepath):
50
  """Yields examples."""
51
- with open(filepath, encoding="utf-8") as f:
52
- for line in f:
53
- yield line
54
- #fields = line.strip().split("\t")
55
- #idx = fields[0]
56
- #text = fields[1]
57
- #yield idx, text
 
 
 
 
 
 
 
 
 
 
 
6
  logger = datasets.logging.get_logger(__name__)
7
 
8
  _DESCRIPTION = "FIQA Dataset"
9
+ _SPLITS = ["corpus", "queries"]
10
 
11
  URL = ""
12
+ _URLs = {subset: URL + f"{subset}.jsonl.gz" for subset in _SPLITS}
13
+ _URLs.update({"qrel": URL + "qrels.tsv"})
14
 
15
  class BEIR(datasets.GeneratorBasedBuilder):
16
  """BEIR BenchmarkDataset."""
 
19
  datasets.BuilderConfig(
20
  name=name,
21
  description=f"This is the {name} in the FiQA dataset.",
22
+ ) for name in _SPLITS + ["qrel"]
23
  ]
24
 
25
  def _info(self):
26
 
27
+ if self.config.name in ["corpus", "topics"]:
28
+ features=datasets.Features({
29
+ "_id": datasets.Value("string"),
30
+ "title": datasets.Value("string"),
31
+ })
32
+
33
+ else:
34
+ features = datasets.Features({
35
+ "query_id": datasets.Value("string"),
36
+ "doc_id": datasets.Value("string"),
37
+ "rel": datasets.Value("string")
38
+ })
39
  return datasets.DatasetInfo(
40
  description=_DESCRIPTION,
41
+ features=features,
 
 
 
42
  supervised_keys=None,
43
  )
44
 
 
58
 
59
  def _generate_examples(self, filepath):
60
  """Yields examples."""
61
+ if self.config.name in ["corpus", "topics"]:
62
+ with open(filepath, encoding="utf-8") as f:
63
+ texts = f.readlines()
64
+ for i, text in enumerate(texts):
65
+ text = json.loads(text)
66
+ if 'metadata' in text: del text['metadata']
67
+ if "title" not in text: text["title"] = ""
68
+ yield i, text
69
+ else:
70
+ with open(filepath, encoding="utf-8") as f:
71
+ for line in f:
72
+ if "query-id" not in line:
73
+ fields = line.strip().split("\t")
74
+ query_id = fields[0]
75
+ doc_id = fields[1]
76
+ rel = int(fields[2])
77
+ yield query_id, doc_id, rel