| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| """SQUAD: The Stanford Question Answering Dataset.""" |
|
|
|
|
| import json |
|
|
| import datasets |
|
|
|
|
| logger = datasets.logging.get_logger(__name__) |
|
|
|
|
| |
| _URLS = { |
| "train": "train.json", |
| "dev": "dev_incomplete.json", |
| "test": "openbook_beam_5.json" |
| } |
|
|
|
|
| class SquadConfig(datasets.BuilderConfig): |
| """BuilderConfig for SQUAD.""" |
|
|
| def __init__(self, **kwargs): |
| """BuilderConfig for SQUAD. |
| |
| Args: |
| **kwargs: keyword arguments forwarded to super. |
| """ |
| super(SquadConfig, self).__init__(**kwargs) |
|
|
|
|
| class Squad(datasets.GeneratorBasedBuilder): |
| """SQUAD: The Stanford Question Answering Dataset. Version 1.1.""" |
|
|
| BUILDER_CONFIGS = [ |
| SquadConfig( |
| name="plain_text", |
| version=datasets.Version("1.0.0", ""), |
| description="Plain text", |
| ), |
| ] |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| |
| features=datasets.Features( |
| { |
| "id": datasets.Value("int32"), |
| "context": datasets.Value("string"), |
| "question": datasets.Value("string"), |
| "answers": datasets.features.Sequence( |
| { |
| "text": datasets.Value("string"), |
| "answer_start": datasets.Value("int32"), |
| } |
| ), |
| } |
| ), |
| |
| |
| supervised_keys=None, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
| return [ |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
| datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), |
| datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}), |
| ] |
|
|
| def _generate_examples(self, filepath): |
| """This function returns the examples in the raw (text) form.""" |
| logger.info("generating examples from = %s", filepath) |
| key = 0 |
| print(filepath) |
| with open(filepath, 'rb') as f: |
| data = json.load(f) |
| print("example data: ", data[0]) |
| print("number of data: ", len(data)) |
| print("data keys: ", data[0].keys()) |
| for line in data: |
| yield key, { |
| "context": line['context'], |
| "question": line["question"], |
| "id": line["id"], |
| "answers": line['answers'] |
| } |
| key += 1 |
|
|