| import json | |
| import datasets | |
| class MNLP_M2_rag_documents(datasets.GeneratorBasedBuilder): | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| features=datasets.Features({ | |
| "title": datasets.Value("string"), | |
| "text": datasets.Value("string"), | |
| "source": datasets.Value("string"), | |
| }), | |
| description="RAG documents for MNLP", | |
| ) | |
| def _split_generators(self, dl_manager): | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={"filepath": "wiki_rag.jsonl"}, | |
| ) | |
| ] | |
| def _generate_examples(self, filepath): | |
| with open(filepath, encoding="utf-8") as f: | |
| for i, line in enumerate(f): | |
| data = json.loads(line) | |
| yield i, { | |
| "title": data.get("title", ""), | |
| "text": data.get("text", ""), | |
| "source": data.get("source", "wikipedia"), | |
| } | |