# 类型错误：'eval_dataset' 必须是 'Dataset' 或 'IterableDataset' 对象，但得到 <class 'list'>

- **ID:** `huggingface/trainer-eval-dataloader-type`
- **领域:** huggingface
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

Trainer 的 `evaluate()` 方法期望 datasets.Dataset 或 IterableDataset 对象，但传入了普通的 Python 列表，缺少所需的数据集接口。

## 版本兼容性

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

## 解决方案

1. ```
   将列表转换为 Dataset 对象：from datasets import Dataset; eval_dataset = Dataset.from_list(your_list)。然后传递给 Trainer。
   ```
2. ```
   如果使用张量列表，从字典创建数据集：dataset = Dataset.from_dict({'input_ids': tensor_list, 'labels': label_list})
   ```

## 无效尝试

- **Pass a list of dictionaries as eval_dataset and expect Trainer to convert it automatically** — Trainer does not perform implicit conversion; it strictly checks the type and raises TypeError. (100% 失败率)
- **Set `eval_dataset` to `None` to skip evaluation** — This avoids the error but prevents evaluation entirely, which may hide issues in model performance. (90% 失败率)
- **Wrap the list in `torch.utils.data.TensorDataset`** — TensorDataset is not compatible with Trainer's expected interface; it lacks methods like `map()` and `select()`. (80% 失败率)
