{"record":{"id":"f997c3c5cbbefb05","repo":"huggingface/transformers","slug":"training-label-label-is-not-a-string","errorCode":null,"errorMessage":"Training label {label} is not a string","messagePattern":"Training label (.+?) is not a string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/processors/xnli.py","lineNumber":53,"sourceCode":"\n    def get_train_examples(self, data_dir):\n        \"\"\"See base class.\"\"\"\n        lg = self.language if self.train_language is None else self.train_language\n        lines = self._read_tsv(os.path.join(data_dir, f\"XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv\"))\n        examples = []\n        for i, line in enumerate(lines):\n            if i == 0:\n                continue\n            guid = f\"train-{i}\"\n            text_a = line[0]\n            text_b = line[1]\n            label = \"contradiction\" if line[2] == \"contradictory\" else line[2]\n            if not isinstance(text_a, str):\n                raise TypeError(f\"Training input {text_a} is not a string\")\n            if not isinstance(text_b, str):\n                raise TypeError(f\"Training input {text_b} is not a string\")\n            if not isinstance(label, str):\n                raise TypeError(f\"Training label {label} is not a string\")\n            examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))\n        return examples\n\n    def get_test_examples(self, data_dir):\n        \"\"\"See base class.\"\"\"\n        lines = self._read_tsv(os.path.join(data_dir, \"XNLI-1.0/xnli.test.tsv\"))\n        examples = []\n        for i, line in enumerate(lines):\n            if i == 0:\n                continue\n            language = line[0]\n            if language != self.language:\n                continue\n            guid = f\"test-{i}\"\n            text_a = line[6]\n            text_b = line[7]\n            label = line[1]\n            if not isinstance(text_a, str):","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/processors/xnli.py#L35-L71","documentation":"The third XNLI train-row check: the label (column 2, with 'contradictory' mapped to 'contradiction') must be a str. Because the mapping expression 'contradiction' if line[2] == 'contradictory' else line[2] passes through whatever is in the column, a non-string there propagates and this TypeError fires, indicating a malformed label column rather than an invalid label value.","triggerScenarios":"get_train_examples(data_dir) on a TSV whose label column is empty or non-text for some row; files where column order differs from the expected (text, text, label) layout.","commonSituations":"Header/row column drift after manual editing; using a different NLI TSV that happens to have 3+ columns but a different order; truncated rows from a bad download.","solutions":["Check the label column of the failing row and the file's column layout against the official XNLI-MT format.","Re-download the dataset if any corruption is suspected.","Pre-validate that line[2] is a non-empty string for every data row before calling get_train_examples."],"exampleFix":"# before\nexamples = processor.get_train_examples(data_dir)\n\n# after: confirm labels parse cleanly first\nimport csv\nwith open(train_tsv_path, encoding=\"utf-8\") as f:\n    rows = list(csv.reader(f, delimiter=\"\\t\", quoting=csv.QUOTE_NONE))\nlabels = {r[2] for r in rows[1:]}\nassert labels <= {\"contradictory\", \"contradiction\", \"entailment\", \"neutral\"}, labels\nexamples = processor.get_train_examples(data_dir)","handlingStrategy":"validation","validationCode":"with open(train_tsv_path, encoding=\"utf-8\") as f:\n    rows = list(csv.reader(f, delimiter=\"\\t\", quoting=csv.QUOTE_NONE))[1:]\nlabels = {r[2] for r in rows if len(r) > 2}\nassert labels <= {\"contradictory\", \"contradiction\", \"entailment\", \"neutral\"}, f\"bad labels: {labels}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the label column vocabulary before processing.","Confirm the column order matches the official XNLI-MT layout.","Reject empty label cells during preprocessing."],"tags":["xnli","data-processing","labels","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}