Delete 模型上传指南.md
Browse files
模型上传指南.md
DELETED
|
@@ -1,232 +0,0 @@
|
|
| 1 |
-
# Detection模型上传到Hugging Face指南
|
| 2 |
-
|
| 3 |
-
**模型信息**:
|
| 4 |
-
- 文件: `best_model.pt` (1.17GB)
|
| 5 |
-
- 基础模型: bert-base-chinese
|
| 6 |
-
- 任务: 情感检测(6类)
|
| 7 |
-
- 准确率: 91.47%
|
| 8 |
-
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
## 🚀 快速上传(3步完成)
|
| 12 |
-
|
| 13 |
-
### 方法1: 使用上传脚本(推荐)
|
| 14 |
-
|
| 15 |
-
#### 步骤1: 安装依赖
|
| 16 |
-
```bash
|
| 17 |
-
pip install huggingface_hub
|
| 18 |
-
```
|
| 19 |
-
|
| 20 |
-
#### 步骤2: 登录Hugging Face
|
| 21 |
-
```bash
|
| 22 |
-
huggingface-cli login
|
| 23 |
-
```
|
| 24 |
-
然后输入你的Token(从 https://huggingface.co/settings/tokens 获取)
|
| 25 |
-
|
| 26 |
-
#### 步骤3: 修改并运行上传脚本
|
| 27 |
-
```bash
|
| 28 |
-
# 1. 编辑 upload_to_huggingface.py
|
| 29 |
-
# 2. 将 REPO_NAME 改为 "你的用户名/longemotion-detection"
|
| 30 |
-
# 3. 运行
|
| 31 |
-
cd Detection
|
| 32 |
-
python upload_to_huggingface.py
|
| 33 |
-
```
|
| 34 |
-
|
| 35 |
-
---
|
| 36 |
-
|
| 37 |
-
### 方法2: 使用命令行(更简单)
|
| 38 |
-
|
| 39 |
-
#### 步骤1: 安装和登录
|
| 40 |
-
```bash
|
| 41 |
-
pip install huggingface_hub
|
| 42 |
-
huggingface-cli login
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
#### 步骤2: 直接上传
|
| 46 |
-
```bash
|
| 47 |
-
cd Detection
|
| 48 |
-
|
| 49 |
-
# 上传模型文件
|
| 50 |
-
huggingface-cli upload your-username/longemotion-detection model/best_model.pt best_model.pt
|
| 51 |
-
|
| 52 |
-
# 上传README
|
| 53 |
-
huggingface-cli upload your-username/longemotion-detection README.md README.md
|
| 54 |
-
|
| 55 |
-
# 上传脚本
|
| 56 |
-
huggingface-cli upload your-username/longemotion-detection scripts/inference_longemotion.py inference_longemotion.py
|
| 57 |
-
```
|
| 58 |
-
|
| 59 |
-
**注意**: 将 `your-username` 替换为你的Hugging Face用户名
|
| 60 |
-
|
| 61 |
-
---
|
| 62 |
-
|
| 63 |
-
### 方法3: 使用Web界面
|
| 64 |
-
|
| 65 |
-
#### 步骤1: 创建仓库
|
| 66 |
-
1. 访问 https://huggingface.co/new
|
| 67 |
-
2. 创建新模型仓库,命名如 `longemotion-detection`
|
| 68 |
-
|
| 69 |
-
#### 步骤2: 上传文件
|
| 70 |
-
1. 进入仓库页面
|
| 71 |
-
2. 点击 "Files and versions"
|
| 72 |
-
3. 点击 "Add file" -> "Upload files"
|
| 73 |
-
4. 上传 `model/best_model.pt`
|
| 74 |
-
5. 上传其他文件(README等)
|
| 75 |
-
|
| 76 |
-
---
|
| 77 |
-
|
| 78 |
-
## 📝 创建模型卡片(README.md)
|
| 79 |
-
|
| 80 |
-
在Hugging Face仓库中创建一个好的README非常重要。以下是模板:
|
| 81 |
-
|
| 82 |
-
```markdown
|
| 83 |
-
---
|
| 84 |
-
language: zh
|
| 85 |
-
license: apache-2.0
|
| 86 |
-
tags:
|
| 87 |
-
- emotion-detection
|
| 88 |
-
- sentiment-analysis
|
| 89 |
-
- chinese
|
| 90 |
-
- bert
|
| 91 |
-
datasets:
|
| 92 |
-
- dair-ai/emotion
|
| 93 |
-
metrics:
|
| 94 |
-
- accuracy
|
| 95 |
-
model-index:
|
| 96 |
-
- name: LongEmotion-Detection
|
| 97 |
-
results:
|
| 98 |
-
- task:
|
| 99 |
-
type: text-classification
|
| 100 |
-
name: Emotion Detection
|
| 101 |
-
metrics:
|
| 102 |
-
- type: accuracy
|
| 103 |
-
value: 0.9147
|
| 104 |
-
name: Validation Accuracy
|
| 105 |
-
---
|
| 106 |
-
|
| 107 |
-
# LongEmotion Detection Model
|
| 108 |
-
|
| 109 |
-
## 模型描述
|
| 110 |
-
|
| 111 |
-
这是一个基于BERT的中文情感检测模型,用于LongEmotion比赛的Detection任务。
|
| 112 |
-
|
| 113 |
-
**任务**: 在长文本的多个段落中,找出表达独特情感的段落。
|
| 114 |
-
|
| 115 |
-
## 模型性能
|
| 116 |
-
|
| 117 |
-
- **验证准确率**: 91.47%
|
| 118 |
-
- **平均置信度**: 89.27%
|
| 119 |
-
- **基础模型**: bert-base-chinese
|
| 120 |
-
- **情感类别**: 6类 (sadness, joy, love, anger, fear, surprise)
|
| 121 |
-
|
| 122 |
-
## 使用方法
|
| 123 |
-
|
| 124 |
-
\`\`\`python
|
| 125 |
-
import torch
|
| 126 |
-
from transformers import BertTokenizer
|
| 127 |
-
|
| 128 |
-
# 加载模型
|
| 129 |
-
model = torch.load("best_model.pt")
|
| 130 |
-
tokenizer = BertTokenizer.from_pretrained("bert-base-chinese")
|
| 131 |
-
|
| 132 |
-
# 推理示例
|
| 133 |
-
text = "你的文本"
|
| 134 |
-
encoding = tokenizer(text, return_tensors='pt', max_length=512, truncation=True)
|
| 135 |
-
with torch.no_grad():
|
| 136 |
-
outputs = model(**encoding)
|
| 137 |
-
predicted_class = torch.argmax(outputs, dim=-1)
|
| 138 |
-
\`\`\`
|
| 139 |
-
|
| 140 |
-
## 训练数据
|
| 141 |
-
|
| 142 |
-
- **数据集**: dair-ai/emotion (中文部分)
|
| 143 |
-
- **训练样本**: 12,800条
|
| 144 |
-
- **验证样本**: 3,200条
|
| 145 |
-
|
| 146 |
-
## 限制和偏见
|
| 147 |
-
|
| 148 |
-
- 模型主要针对短文本情感分类训练
|
| 149 |
-
- 在非常长的文本上可能需要分段处理
|
| 150 |
-
|
| 151 |
-
## 引用
|
| 152 |
-
|
| 153 |
-
如果使用此模型,请引用:
|
| 154 |
-
\`\`\`
|
| 155 |
-
@misc{longemotion-detection,
|
| 156 |
-
author = {Your Name},
|
| 157 |
-
title = {LongEmotion Detection Model},
|
| 158 |
-
year = {2025},
|
| 159 |
-
publisher = {Hugging Face},
|
| 160 |
-
howpublished = {\url{https://huggingface.co/your-username/longemotion-detection}}
|
| 161 |
-
}
|
| 162 |
-
\`\`\`
|
| 163 |
-
```
|
| 164 |
-
|
| 165 |
-
---
|
| 166 |
-
|
| 167 |
-
## ⚠️ 注意事项
|
| 168 |
-
|
| 169 |
-
### 文件大小
|
| 170 |
-
- `best_model.pt`: 1.17GB
|
| 171 |
-
- 上传时间取决于网络速度(可能需要10-30分钟)
|
| 172 |
-
|
| 173 |
-
### 仓库命名建议
|
| 174 |
-
- `longemotion-detection`
|
| 175 |
-
- `emotion-detection-chinese`
|
| 176 |
-
- `bert-chinese-emotion`
|
| 177 |
-
|
| 178 |
-
### 私有 vs 公开
|
| 179 |
-
- 公开仓库:任何人都可以下载使用
|
| 180 |
-
- 私有仓库:只有你能访问(需要Pro账号)
|
| 181 |
-
|
| 182 |
-
---
|
| 183 |
-
|
| 184 |
-
## 🔍 验证上传
|
| 185 |
-
|
| 186 |
-
上传后,访问:
|
| 187 |
-
```
|
| 188 |
-
https://huggingface.co/your-username/longemotion-detection
|
| 189 |
-
```
|
| 190 |
-
|
| 191 |
-
检查:
|
| 192 |
-
- ✅ 模型文件已上传
|
| 193 |
-
- ✅ README显示正确
|
| 194 |
-
- ✅ 可以下载模型
|
| 195 |
-
|
| 196 |
-
---
|
| 197 |
-
|
| 198 |
-
## 📥 下载使用
|
| 199 |
-
|
| 200 |
-
其他人可以这样使用你的模型:
|
| 201 |
-
|
| 202 |
-
```python
|
| 203 |
-
from huggingface_hub import hf_hub_download
|
| 204 |
-
|
| 205 |
-
# 下载模型
|
| 206 |
-
model_path = hf_hub_download(
|
| 207 |
-
repo_id="your-username/longemotion-detection",
|
| 208 |
-
filename="best_model.pt"
|
| 209 |
-
)
|
| 210 |
-
|
| 211 |
-
# 加载模型
|
| 212 |
-
import torch
|
| 213 |
-
model = torch.load(model_path)
|
| 214 |
-
```
|
| 215 |
-
|
| 216 |
-
---
|
| 217 |
-
|
| 218 |
-
## 🆘 常见问题
|
| 219 |
-
|
| 220 |
-
**Q: Token在哪里获取?**
|
| 221 |
-
A: https://huggingface.co/settings/tokens -> Create new token
|
| 222 |
-
|
| 223 |
-
**Q: 上传很慢怎么办?**
|
| 224 |
-
A: 可以使用Git LFS方式上传大文件
|
| 225 |
-
|
| 226 |
-
**Q: 如何更新模型?**
|
| 227 |
-
A: 重新运行上传脚本即可覆盖旧文件
|
| 228 |
-
|
| 229 |
-
---
|
| 230 |
-
|
| 231 |
-
**准备好了吗?开始上传吧!** 🚀
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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