{"record":{"id":"f45ef67045f19368","repo":"d2l-ai/d2l-zh","slug":"f-name-data-hub-f45ef6","errorCode":null,"errorMessage":"f\"{name} 不存在于 {DATA_HUB}\"","messagePattern":"f\"(.+?) 不存在于 (.+?)\"","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"d2l/paddle.py","lineNumber":385,"sourceCode":"    \"\"\"评估给定数据集上模型的损失。\n\n    Defined in :numref:`sec_model_selection`\"\"\"\n    metric = d2l.Accumulator(2)  # 损失的总和, 样本数量\n    for X, y in data_iter:\n        out = net(X)\n        y = y.reshape(out.shape)\n        l = loss(out, y)\n        metric.add(l.sum(), l.numel())\n    return metric[0] / metric[1]\n\nDATA_HUB = dict()\nDATA_URL = 'http://d2l-data.s3-accelerate.amazonaws.com/'\n\ndef download(name, cache_dir=os.path.join('..', 'data')):\n    \"\"\"下载一个DATA_HUB中的文件，返回本地文件名\n\n    Defined in :numref:`sec_kaggle_house`\"\"\"\n    assert name in DATA_HUB, f\"{name} 不存在于 {DATA_HUB}\"\n    url, sha1_hash = DATA_HUB[name]\n    os.makedirs(cache_dir, exist_ok=True)\n    fname = os.path.join(cache_dir, url.split('/')[-1])\n    if os.path.exists(fname):\n        sha1 = hashlib.sha1()\n        with open(fname, 'rb') as f:\n            while True:\n                data = f.read(1048576)\n                if not data:\n                    break\n                sha1.update(data)\n        if sha1.hexdigest() == sha1_hash:\n            return fname  # 命中缓存\n    print(f'正在从{url}下载{fname}...')\n    r = requests.get(url, stream=True, verify=True)\n    with open(fname, 'wb') as f:\n        f.write(r.content)\n    return fname","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/d2l-ai/d2l-zh/blob/e6b18ccea71451a55fcd861d7b96fddf2587b09a/d2l/paddle.py#L367-L403","documentation":"An AssertionError in d2l.paddle.download: the requested dataset name is not a key in DATA_HUB. DATA_HUB is a module-level dict of name -> (url, sha1) registrations at the bottom of the module; download() requires the entry for both the URL and the integrity check. The Chinese message means '{name} does not exist in {DATA_HUB}'.","triggerScenarios":"Calling d2l.download / download_extract / download_all with an unregistered or misspelled name; importing the module in a way that skips the module-level DATA_HUB[...] assignment statements; expecting arbitrary Kaggle datasets to be downloadable.","commonSituations":"Users assuming d2l mirrors all book datasets under any name — only entries explicitly registered (kaggle_house_train, kaggle_house_test, etc.) work; typos like 'kaggle-house-train' or wrong case; partial copy-paste of the download section into notebooks without the registrations.","solutions":["Use a registered name, e.g. d2l.download('kaggle_house_train') or 'kaggle_house_test'.","Register your own entry first: d2l.DATA_HUB['mydata'] = (d2l.DATA_URL + 'mydata.csv', '<sha1_hex>') then d2l.download('mydata').","For live Kaggle competitions, download via the Kaggle website/CLI into ../data instead — the mirror only hosts the book's static files.","Print list(d2l.DATA_HUB.keys()) to see exactly which names are available."],"exampleFix":"# before\nd2l.download('kaggle_house')  # AssertionError\n# after\nprint(list(d2l.DATA_HUB.keys()))  # pick an exact name\nd2l.download('kaggle_house_train')","handlingStrategy":"validation","validationCode":"def safe_download(name):\n    if name not in d2l.DATA_HUB:\n        raise KeyError(f'{name!r} not in DATA_HUB; available: {sorted(d2l.DATA_HUB)}')\n    return d2l.download(name)","typeGuard":"def is_registered(name: str) -> bool:\n    return isinstance(name, str) and name in d2l.DATA_HUB","tryCatchPattern":"try:\n    d2l.download(name)\nexcept AssertionError:\n    raise KeyError(f'{name!r} not registered; pick from {sorted(d2l.DATA_HUB)}')","preventionTips":["Check sorted(d2l.DATA_HUB) before downloading unfamiliar names.","Register custom datasets with DATA_HUB[name] = (url, sha1) first.","Use the Kaggle CLI for competition data; d2l mirrors only static book files."],"tags":["d2l","paddle","download","data-hub","kaggle","assertion"],"backgroundTag":null,"analyzedSha":"e6b18ccea71451a55fcd861d7b96fddf2587b09a","analyzedAt":"2026-08-14T20:05:26.414Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}