# ValueError: 数据集的特征与预期的模式不匹配。缺少列: ['text', 'label']。多余列: ['input', 'target']

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

## 根因

从 Hugging Face Datasets 加载的数据集具有与训练脚本或分词器预期不同的列名。

## 版本兼容性

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

## 解决方案

1. ```
   Align columns using Dataset.rename_columns() and Dataset.remove_columns(): `dataset = dataset.rename_columns({'input': 'text', 'target': 'label'}).remove_columns(['unused_col'])`
   ```
2. ```
   Use datasets.Dataset.map() with a function that selects only the required columns: `dataset = dataset.map(lambda x: {'text': x['input'], 'label': x['target']}, remove_columns=dataset.column_names)`
   ```
3. ```
   Load the dataset with expected column names by specifying the 'columns' argument in load_dataset() if the dataset supports it, or create a new dataset with the correct schema.
   ```

## 无效尝试

- **** — If there are more mismatches (e.g., 'target' vs 'label'), the error persists. Also, renaming may break other downstream code that expects 'input'. (40% 失败率)
- **** — Trainer does not have ignore_columns; dropping columns with dataset.remove_columns() is correct but users often drop the wrong ones or forget to add missing columns. (50% 失败率)
- **** — Model config does not control dataset schema; this is a data preprocessing issue, not a model architecture issue. (70% 失败率)
