data: 2024-05-23
aliases:
- “huggingface_hub.utils.validators.HFValidationError: Repo id must use alphanumeric chars or ‘-’, '', ‘.’, ‘–’ and ‘…’ are forbidden, ‘-’ and ‘.’ cannot start or end the name, max length is 96: ‘D:\10770\HIT\Project\HIT-KRAR-2024\ltp_small’.”
tags:
- error
问题描述
Python载入本地下载的 ltp_small 模型报错:
Huggingface_hub. Utils.validators. HFValidationError: Repo id must use alphanumeric chars or ‘-’, '', ‘.’, ‘–’ and ‘…’ are forbidden, ‘-’ and ‘.’ cannot start or end the name, max length is 96: ‘D:\10770\HIT\Project\HIT-KRAR-2024\ltp_small’.
问题分析
代码中直接使用的相对路径来载入模型:
ltp = LTP(pretrained_model_name_or_path='./ltp_small') #加载模型
检查报错内容,发现获取的路径与预期不符:
文件结构:
D:.
├─. Idea
│ ├─codeStyles
│ └─inspectionProfiles
├─lab 1
├─lab 2
└─lab 3
│ ├─duie_data
│ ├─ltp_small
│ └─__pycache__
实际模型保存在为当前 VS Code 工作目录的子文件夹 lab3
下。
问题解决
将代码修改为:
ltp = LTP(pretrained_model_name_or_path='./lab3/ltp_small') #加载模型
错误解决,运行成功。