Download cqadupstack-programmers-pl.py from clarin-knext/cqadupstack-programmers-pl: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/datasets/clarin-knext/cqadupstack-programmers-pl/resolve/main/cqadupstack-programmers-pl.py
- Command line
-
hf download hf://datasets/clarin-knext/cqadupstack-programmers-pl/cqadupstack-programmers-pl.py
-
curl -L -o cqadupstack-programmers-pl.py https://huggingface.co/datasets/clarin-knext/cqadupstack-programmers-pl/resolve/main/cqadupstack-programmers-pl.py
1.65 kB
| import json | |
| import csv | |
| import os | |
| import datasets | |
| logger = datasets.logging.get_logger(__name__) | |
| _DESCRIPTION = "cqadupstack programmers Dataset" | |
| _SPLITS = ["corpus", "queries"] | |
| URL = "" | |
| _URLs = {subset: URL + f"{subset}.jsonl.gz" for subset in _SPLITS} | |
| class Programmers(datasets.GeneratorBasedBuilder): | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig( | |
| name=name, | |
| description=f"This is the {name} in the BEIR-PL dataset.", | |
| ) for name in _SPLITS | |
| ] | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=datasets.Features({ | |
| "_id": datasets.Value("string"), | |
| "title": datasets.Value("string"), | |
| "text": datasets.Value("string"), | |
| }), | |
| supervised_keys=None, | |
| ) | |
| def _split_generators(self, dl_manager): | |
| """Returns SplitGenerators.""" | |
| my_urls = _URLs[self.config.name] | |
| data_dir = dl_manager.download_and_extract(my_urls) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=self.config.name, | |
| # These kwargs will be passed to _generate_examples | |
| gen_kwargs={"filepath": data_dir}, | |
| ), | |
| ] | |
| def _generate_examples(self, filepath): | |
| """Yields examples.""" | |
| with open(filepath, encoding="utf-8") as f: | |
| texts = f.readlines() | |
| for i, text in enumerate(texts): | |
| text = json.loads(text) | |
| if 'metadata' in text: del text['metadata'] | |
| if "title" not in text: text["title"] = "" | |
| yield i, text |