{"record":{"id":"c13335ea01f6fe86","repo":"huggingface/transformers","slug":"training-input-text-a-is-not-a-string","errorCode":null,"errorMessage":"Training input {text_a} 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":49,"sourceCode":"\n    def __init__(self, language, train_language=None):\n        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}\"","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/processors/xnli.py#L31-L67","documentation":"While building XNLI training examples from the multilingual TSV, the processor asserts that column 0 of each row (text_a) is a str. The CSV reader normally yields strings, so this TypeError signals a malformed row: wrong delimiter, a file without a header as expected, QUOTE_NONE artifacts, or a row whose columns are not plain text. The check exists to fail loudly on corrupt data instead of producing broken InputExamples.","triggerScenarios":"get_train_examples(data_dir) on a multinli.train.{lg}.tsv that is corrupted, uses a different delimiter/quoting, or where line[0] is empty/None-like; pointing data_dir at the wrong directory so a different file layout is read.","commonSituations":"Downloading XNLI-MT-1.0 manually and getting HTML or partial content; locale/encoding issues producing bytes; editing the TSV in a spreadsheet that changed quoting.","solutions":["Re-download the XNLI-MT-1.0 archive and verify multinli.train.{language}.tsv opens as tab-separated text with a header row.","Sanity-parse the file yourself with csv.reader(f, delimiter='\\t', quoting=csv.QUOTE_NONE) and inspect the offending row index.","Confirm data_dir contains XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv exactly as the processor expects."],"exampleFix":"# before\nexamples = processor.get_train_examples(data_dir)  # corrupt TSV\n\n# after: validate the file first\nimport csv\nwith open(f\"{data_dir}/XNLI-MT-1.0/multinli/multinli.train.en.tsv\", encoding=\"utf-8\") as f:\n    rows = list(csv.reader(f, delimiter=\"\\t\", quoting=csv.QUOTE_NONE))\nassert all(isinstance(r[0], str) for r in rows[1:])\nexamples = processor.get_train_examples(data_dir)","handlingStrategy":"validation","validationCode":"import csv\npath = f\"{data_dir}/XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv\"\nwith open(path, encoding=\"utf-8\") as f:\n    rows = list(csv.reader(f, delimiter=\"\\t\", quoting=csv.QUOTE_NONE))[1:]\nassert rows and all(isinstance(r[0], str) and r[0] for r in rows), \"malformed text_a column\"","typeGuard":null,"tryCatchPattern":"try:\n    examples = processor.get_train_examples(data_dir)\nexcept TypeError as e:\n    if \"not a string\" in str(e):\n        raise ValueError(f\"Corrupt XNLI train TSV under {data_dir}; re-download XNLI-MT-1.0\") from e\n    raise","preventionTips":["Download XNLI archives from official sources and verify file sizes.","Pre-parse the TSV with the same csv settings the processor uses before running.","Never hand-edit the raw TSVs; generate a cleaned copy instead."],"tags":["xnli","data-processing","file-format","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}