{"record":{"id":"a4fe06ae1d0d691d","repo":"huggingface/transformers","slug":"training-input-text-b-is-not-a-string","errorCode":null,"errorMessage":"Training input {text_b} is not a string","messagePattern":"Training input (.+?) is not a string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/processors/xnli.py","lineNumber":51,"sourceCode":"        self.language = language\n        self.train_language = train_language\n\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]","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/processors/xnli.py#L33-L69","documentation":"Same XNLI train-example construction as the text_a check, but asserting column 1 (text_b, the premise/second sentence) is a str. A non-string value means the TSV row does not have the expected shape - typically a mis-parsed or truncated row - and the processor refuses to build an InputExample from it.","triggerScenarios":"get_train_examples(data_dir) where a row's second column is missing or the row was split incorrectly due to quoting/delimiter drift; a partially downloaded or truncated TSV.","commonSituations":"Interrupted downloads leaving truncated files; files edited with different tab/quote settings; wrong language file variant with a different column layout.","solutions":["Inspect the failing row (the traceback loop index) in the raw TSV and fix or remove it.","Re-download the XNLI-MT-1.0 data and diff file sizes against the official archive.","Validate every row has at least 3 string columns before calling the processor."],"exampleFix":"# before\nexamples = processor.get_train_examples(data_dir)\n\n# after: pre-validate rows\nimport csv\nwith open(train_tsv_path, encoding=\"utf-8\") as f:\n    rows = list(csv.reader(f, delimiter=\"\\t\", quoting=csv.QUOTE_NONE))\nbad = [i for i, r in enumerate(rows[1:], 1) if len(r) < 3 or not all(isinstance(c, str) for c in r[:3])]\nassert not bad, f\"bad rows: {bad}\"\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:]\nbad = [i for i, r in enumerate(rows) if len(r) < 3 or not all(isinstance(c, str) for c in r[:3])]\nassert not bad, f\"malformed rows: {bad[:5]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate every row has at least 3 string columns before calling the processor.","Keep the original archive checksum to detect corruption early.","Watch for truncated final rows after interrupted downloads."],"tags":["xnli","data-processing","file-format","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}