{
  "id": "huggingface/dataset-feature-type-mismatch",
  "signature": "TypeError: Expected feature type 'Value(dtype='int32')' but got 'Value(dtype='int64')' for column 'labels'. Cast the column to the correct dtype.",
  "signature_zh": "类型错误：列 'labels' 期望特征类型 'Value(dtype='int32')'，但得到 'Value(dtype='int64')'。请将列转换为正确的数据类型。",
  "regex": "TypeError: Expected feature type 'Value\\(dtype='\\w+'\\)' but got 'Value\\(dtype='\\w+'\\)' for column '[^']+'\\. Cast the column to the correct dtype\\.",
  "domain": "huggingface",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "The dataset schema defines a specific dtype for a column (e.g., int32) but the actual data loaded has a different dtype (e.g., int64), causing a mismatch during batching or model input preparation.",
  "root_cause_type": "generic",
  "root_cause_zh": "数据集模式为某列定义了特定数据类型（如 int32），但实际加载的数据具有不同的数据类型（如 int64），导致批处理或模型输入准备时出现不匹配。",
  "versions": [
    {
      "version": "datasets>=2.16.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "transformers>=4.35.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Python>=3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Ignoring the error and using the dataset as-is may cause silent casting during training, leading to memory inefficiency or runtime errors in PyTorch.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Dropping the column with remove_columns removes the feature entirely, causing a missing column error later.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Cast the column to the expected dtype using Dataset.cast_column:\nfrom datasets import load_dataset, Features, Value\ndataset = load_dataset('org/dataset', split='train')\nexpected_features = Features({'labels': Value('int32')})\ndataset = dataset.cast(expected_features)\n# Or cast a single column:\ndataset = dataset.cast_column('labels', Value('int32'))",
      "success_rate": 0.88,
      "how": "Cast the column to the expected dtype using Dataset.cast_column:\nfrom datasets import load_dataset, Features, Value\ndataset = load_dataset('org/dataset', split='train')\nexpected_features = Features({'labels': Value('int32')})\ndataset = dataset.cast(expected_features)\n# Or cast a single column:\ndataset = dataset.cast_column('labels', Value('int32'))",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use Dataset.map to manually convert the column:\ndef convert_labels(example):\n    example['labels'] = int(example['labels'])  # Python int is flexible\n    return example\ndataset = dataset.map(convert_labels)\n# Then let the data collator handle casting automatically.",
      "success_rate": 0.82,
      "how": "Use Dataset.map to manually convert the column:\ndef convert_labels(example):\n    example['labels'] = int(example['labels'])  # Python int is flexible\n    return example\ndataset = dataset.map(convert_labels)\n# Then let the data collator handle casting automatically.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Cast the column to the expected dtype using Dataset.cast_column:\nfrom datasets import load_dataset, Features, Value\ndataset = load_dataset('org/dataset', split='train')\nexpected_features = Features({'labels': Value('int32')})\ndataset = dataset.cast(expected_features)\n# Or cast a single column:\ndataset = dataset.cast_column('labels', Value('int32'))",
    "Use Dataset.map to manually convert the column:\ndef convert_labels(example):\n    example['labels'] = int(example['labels'])  # Python int is flexible\n    return example\ndataset = dataset.map(convert_labels)\n# Then let the data collator handle casting automatically."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/datasets/en/features#features-types",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.88,
  "resolvable": "true",
  "first_seen": "2023-11-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}