Sean MacAvaney commited on
Commit
e631ffe
1 Parent(s): 813c876

commit files to HF hub

Browse files
Files changed (2) hide show
  1. README.md +42 -0
  2. cranfield.py +43 -0
README.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: '`cranfield`'
3
+ viewer: false
4
+ source_datasets: []
5
+ task_categories:
6
+ - text-retrieval
7
+ ---
8
+
9
+ # Dataset Card for `cranfield`
10
+
11
+ The `cranfield` dataset, provided by the [ir-datasets](https://ir-datasets.com/) package.
12
+ For more information about the dataset, see the [documentation](https://ir-datasets.com/cranfield#cranfield).
13
+
14
+ # Data
15
+
16
+ This dataset provides:
17
+ - `docs` (documents, i.e., the corpus); count=1,400
18
+ - `queries` (i.e., topics); count=225
19
+ - `qrels`: (relevance assessments); count=1,837
20
+
21
+
22
+ ## Usage
23
+
24
+ ```python
25
+ from datasets import load_dataset
26
+
27
+ docs = load_dataset('irds/cranfield', 'docs')
28
+ for record in docs:
29
+ record # {'doc_id': ..., 'title': ..., 'text': ..., 'author': ..., 'bib': ...}
30
+
31
+ queries = load_dataset('irds/cranfield', 'queries')
32
+ for record in queries:
33
+ record # {'query_id': ..., 'text': ...}
34
+
35
+ qrels = load_dataset('irds/cranfield', 'qrels')
36
+ for record in qrels:
37
+ record # {'query_id': ..., 'doc_id': ..., 'relevance': ..., 'iteration': ...}
38
+
39
+ ```
40
+
41
+ Note that calling `load_dataset` will download the dataset (or provide access instructions when it's not public) and make a copy of the
42
+ data in 🤗 Dataset format.
cranfield.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """
3
+ """ # TODO
4
+ try:
5
+ import ir_datasets
6
+ except ImportError as e:
7
+ raise ImportError('ir-datasets package missing; `pip install ir-datasets`')
8
+ import datasets
9
+
10
+ IRDS_ID = 'cranfield'
11
+ IRDS_ENTITY_TYPES = {'docs': {'doc_id': 'string', 'title': 'string', 'text': 'string', 'author': 'string', 'bib': 'string'}, 'queries': {'query_id': 'string', 'text': 'string'}, 'qrels': {'query_id': 'string', 'doc_id': 'string', 'relevance': 'int64', 'iteration': 'string'}}
12
+
13
+ _CITATION = ''
14
+
15
+ _DESCRIPTION = "" # TODO
16
+
17
+ class cranfield(datasets.GeneratorBasedBuilder):
18
+ BUILDER_CONFIGS = [datasets.BuilderConfig(name=e) for e in IRDS_ENTITY_TYPES]
19
+
20
+ def _info(self):
21
+ return datasets.DatasetInfo(
22
+ description=_DESCRIPTION,
23
+ features=datasets.Features({k: datasets.Value(v) for k, v in IRDS_ENTITY_TYPES[self.config.name].items()}),
24
+ homepage=f"https://ir-datasets.com/cranfield#cranfield",
25
+ citation=_CITATION,
26
+ )
27
+
28
+ def _split_generators(self, dl_manager):
29
+ return [datasets.SplitGenerator(name=self.config.name)]
30
+
31
+ def _generate_examples(self):
32
+ dataset = ir_datasets.load(IRDS_ID)
33
+ for i, item in enumerate(getattr(dataset, self.config.name)):
34
+ key = i
35
+ if self.config.name == 'docs':
36
+ key = item.doc_id
37
+ elif self.config.name == 'queries':
38
+ key = item.query_id
39
+ yield key, item._asdict()
40
+
41
+ def as_dataset(self, split=None, *args, **kwargs):
42
+ split = self.config.name # always return split corresponding with this config to avid returning a redundant DatasetDict layer
43
+ return super().as_dataset(split, *args, **kwargs)