# ValueError：数据集的特征与预期模式不匹配。缺失列：['text', 'label']。多余列：['id', 'metadata']

- **ID:** `huggingface/dataset-features-mismatch`
- **领域:** huggingface
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

从 Hugging Face Datasets 加载的数据集具有与模型或训练脚本所需的预期模式不匹配的列。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| datasets>=2.10.0 | active | — | — |
| transformers>=4.30.0 | active | — | — |
| python>=3.8 | active | — | — |

## 解决方案

1. ```
   使用 dataset.select_columns(['text', 'label']) 仅保留所需列，然后添加缺失列并赋予默认值：dataset = dataset.add_column('label', [0]*len(dataset))。
   ```
2. ```
   将多余列映射到所需列：dataset = dataset.map(lambda x: {'text': x['metadata'], 'label': 0})。
   ```

## 无效尝试

- **** — Missing columns still need to be added or mapped from existing columns. (50% 失败率)
- **** — If the column name is misspelled, the error persists. (60% 失败率)
