{
  "id": "huggingface/tokenizer-typeerror-nonstring",
  "signature": "TypeError: Text input must be of type `str` (single example), `List[str]` (batch) or `List[List[str]]` (batch of sequences). Received type: <class 'int'>",
  "signature_zh": "TypeError：文本输入必须是 `str`（单个示例）、`List[str]`（批次）或 `List[List[str]]`（序列批次）类型。收到类型：<class 'int'>",
  "regex": "Text input must be of type `str` \\(single example\\), `List\\[str\\]` \\(batch\\) or `List\\[List\\[str\\]\\]`",
  "domain": "huggingface",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "The tokenizer received a non-text input type (e.g., integer, float) instead of expected string types.",
  "root_cause_type": "generic",
  "root_cause_zh": "分词器接收到了非文本输入类型（例如整数、浮点数），而不是预期的字符串类型。",
  "versions": [
    {
      "version": "transformers>=4.20.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "While `str(123)` works for a single int, if the input is a list of ints like `[1, 2, 3]`, `str([1,2,3])` produces a single string '[1, 2, 3]' which the tokenizer will tokenize incorrectly as a single sequence of characters, not as three separate tokens.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "`tokenizer.encode` also performs type checking and will raise the same error for non-string inputs. It is not a bypass.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Convert integer inputs to strings before tokenization: `tokenizer(str(123))` for single ints, or `tokenizer([str(x) for x in [1, 2, 3]])` for lists of ints.",
      "success_rate": 0.9,
      "how": "Convert integer inputs to strings before tokenization: `tokenizer(str(123))` for single ints, or `tokenizer([str(x) for x in [1, 2, 3]])` for lists of ints.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure your data pipeline outputs string types. If using a dataset, map with `dataset = dataset.map(lambda x: {'text': str(x['label'])})` to convert columns.",
      "success_rate": 0.85,
      "how": "Ensure your data pipeline outputs string types. If using a dataset, map with `dataset = dataset.map(lambda x: {'text': str(x['label'])})` to convert columns.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在分词前将整数输入转换为字符串：对于单个整数使用 `tokenizer(str(123))`，对于整数列表使用 `tokenizer([str(x) for x in [1, 2, 3]])`。",
    "确保数据管道输出字符串类型。如果使用数据集，通过 `dataset = dataset.map(lambda x: {'text': str(x['label'])})` 进行映射转换列。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/v4.35.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizer.__call__",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.92,
  "resolvable": "true",
  "first_seen": "2023-04-08",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}