{
  "id": "huggingface/trainer-eval-dataloader-type",
  "signature": "TypeError: The `eval_dataset` must be a `Dataset` or `IterableDataset` object, but got <class 'list'>",
  "signature_zh": "类型错误：'eval_dataset' 必须是 'Dataset' 或 'IterableDataset' 对象，但得到 <class 'list'>",
  "regex": "TypeError: The `eval_dataset` must be a `Dataset` or `IterableDataset` object, but got <class 'list'>",
  "domain": "huggingface",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "The Trainer's `evaluate()` method expects a datasets.Dataset or IterableDataset object, but a plain Python list was passed, which lacks the required dataset interface.",
  "root_cause_type": "generic",
  "root_cause_zh": "Trainer 的 `evaluate()` 方法期望 datasets.Dataset 或 IterableDataset 对象，但传入了普通的 Python 列表，缺少所需的数据集接口。",
  "versions": [
    {
      "version": "transformers>=4.28.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "datasets>=2.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Pass a list of dictionaries as eval_dataset and expect Trainer to convert it automatically",
      "why_fails": "Trainer does not perform implicit conversion; it strictly checks the type and raises TypeError.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Set `eval_dataset` to `None` to skip evaluation",
      "why_fails": "This avoids the error but prevents evaluation entirely, which may hide issues in model performance.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrap the list in `torch.utils.data.TensorDataset`",
      "why_fails": "TensorDataset is not compatible with Trainer's expected interface; it lacks methods like `map()` and `select()`.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Convert the list to a Dataset object: from datasets import Dataset; eval_dataset = Dataset.from_list(your_list). Then pass it to Trainer.",
      "success_rate": 0.95,
      "how": "Convert the list to a Dataset object: from datasets import Dataset; eval_dataset = Dataset.from_list(your_list). Then pass it to Trainer.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using a list of tensors, create a Dataset from a dictionary: dataset = Dataset.from_dict({'input_ids': tensor_list, 'labels': label_list})",
      "success_rate": 0.9,
      "how": "If using a list of tensors, create a Dataset from a dictionary: dataset = Dataset.from_dict({'input_ids': tensor_list, 'labels': label_list})",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "将列表转换为 Dataset 对象：from datasets import Dataset; eval_dataset = Dataset.from_list(your_list)。然后传递给 Trainer。",
    "如果使用张量列表，从字典创建数据集：dataset = Dataset.from_dict({'input_ids': tensor_list, 'labels': label_list})"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/v4.28.0/en/main_classes/trainer#transformers.Trainer.evaluate",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.93,
  "resolvable": "true",
  "first_seen": "2024-01-18",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}