{"record":{"id":"d37f649e36d018bd","repo":"huggingface/transformers","slug":"squadprocessor-should-be-instantiated-via-squadv1p","errorCode":null,"errorMessage":"SquadProcessor should be instantiated via SquadV1Processor or SquadV2Processor","messagePattern":"SquadProcessor should be instantiated via SquadV1Processor or SquadV2Processor","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/processors/squad.py","lineNumber":513,"sourceCode":"            examples.append(self._get_example_from_tensor_dict(tensor_dict, evaluate=evaluate))\n\n        return examples\n\n    def get_train_examples(self, data_dir, filename=None):\n        \"\"\"\n        Returns the training examples from the data directory.\n\n        Args:\n            data_dir: Directory containing the data files used for training and evaluating.\n            filename: None by default, specify this if the training file has a different name than the original one\n                which is `train-v1.1.json` and `train-v2.0.json` for squad versions 1.1 and 2.0 respectively.\n\n        \"\"\"\n        if data_dir is None:\n            data_dir = \"\"\n\n        if self.train_file is None:\n            raise ValueError(\"SquadProcessor should be instantiated via SquadV1Processor or SquadV2Processor\")\n\n        with open(\n            os.path.join(data_dir, self.train_file if filename is None else filename), \"r\", encoding=\"utf-8\"\n        ) as reader:\n            input_data = json.load(reader)[\"data\"]\n        return self._create_examples(input_data, \"train\")\n\n    def get_dev_examples(self, data_dir, filename=None):\n        \"\"\"\n        Returns the evaluation example from the data directory.\n\n        Args:\n            data_dir: Directory containing the data files used for training and evaluating.\n            filename: None by default, specify this if the evaluation file has a different name than the original one\n                which is `dev-v1.1.json` and `dev-v2.0.json` for squad versions 1.1 and 2.0 respectively.\n        \"\"\"\n        if data_dir is None:\n            data_dir = \"\"","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/processors/squad.py#L495-L531","documentation":"Raised by SquadProcessor.get_train_examples when the instance's train_file attribute is None. SquadProcessor is an abstract base: only SquadV1Processor (train-v1.1.json) and SquadV2Processor (train-v2.0.json) set train_file, so instantiating the base class directly and asking for training data is a misuse the class detects explicitly.","triggerScenarios":"processor = SquadProcessor(); processor.get_train_examples('data/squad'). Also reachable by subclassing SquadProcessor without assigning train_file/dev_file.","commonSituations":"Generic processor-selection code that instantiates the base class as a default; custom SQuAD-format processors that forget to set train_file; refactors that changed which class gets constructed.","solutions":["Instantiate a concrete subclass: SquadV1Processor() or SquadV2Processor() depending on your data version.","In custom subclasses, set self.train_file and self.dev_file in __init__ before calling get_train_examples.","If the file has a nonstandard name, you can also pass filename=... to get_train_examples on a concrete subclass."],"exampleFix":"# before\nprocessor = SquadProcessor()\nexamples = processor.get_train_examples('squad_data/')  # raises\n\n# after\nprocessor = SquadV2Processor()\nexamples = processor.get_train_examples('squad_data/')","handlingStrategy":"type-guard","validationCode":"from transformers.data.processors.squad import SquadV1Processor, SquadV2Processor\n\nprocessor = SquadV2Processor() if args.version_2_with_negative else SquadV1Processor()\nassert processor.train_file is not None  # concrete subclasses always set it","typeGuard":"from transformers.data.processors.squad import SquadProcessor\n\ndef is_concrete_squad_processor(p: SquadProcessor) -> bool:\n    return getattr(p, 'train_file', None) is not None","tryCatchPattern":null,"preventionTips":["Never instantiate SquadProcessor directly; select SquadV1Processor or SquadV2Processor.","In custom subclasses, always set train_file and dev_file in __init__.","Centralize processor selection in one factory function keyed on version_2_with_negative."],"tags":["squad","processor","subclassing","question-answering","configuration"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}