Downloads · 30 days
10
13% of all-time downloads
robertlyon/Qwen3-32B-reuters21578
Qwen3-32B-reuters21578 is a text classification model from robertlyon. Use it when you need a label for a piece of text. The card lists the license as gpl-3.0.
这是一个基于 Qwen3-32B 模型,在经典的 Reuters-21578 (ModApte split) 数据集上通过 LoRA 方法进行微调的多标签文本分类模型。
Downloads · 30 days
10
13% of all-time downloads
All-time downloads
79
Public
Parameters
33.7B
19.2 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors19.2 GB · 100%
How the weights are stored.
U832.2B · 95%
From the Hugging Face model README
这是一个基于 Qwen3-32B 模型,在经典的 Reuters-21578 (ModApte split) 数据集上通过 LoRA 方法进行微调的多标签文本分类模型。
模型被训练来理解一篇新闻文章,并以逗号分隔的格式生成一个或多个相关的主题标签。
该模型将多标签分类任务转化为一个条件文本生成任务。它接收特定格式的提示(包含新闻文章),然后生成对应的标签字符串。
您可以使用 transformers 库轻松加载和使用该模型。请确保您的输入遵循上述提示格式。
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# 加载模型和分词器
model_name = "your_huggingface_username/qwen3-32b-reuters21578-multilabel" # ⬅️ 请替换为您的模型路径
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name,
device_map="auto",
torch_dtype=torch.bfloat16)
def predict_topics(article: str, max_new_tokens: int = 32):
"""
使用微调后的模型预测文章的主题标签。
"""
prompt = f"### 文章\n{article.strip()}\n\n### 标签\n"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
# 使用 generate 方法生成 token
gen_ids = model.generate(**inputs,
max_new_tokens=max_new_tokens,
temperature=0.1,
eos_token_id=tokenizer.eos_token_id)
# 解码并提取标签部分
full_output = tokenizer.decode(gen_ids[0], skip_special_tokens=True)
tag_part = full_output.split("### 标签")[-1]
# 解析标签
return [t.strip() for t in tag_part.split(",") if t.strip()]
# --- 示例 ---
demo_text = """
The U.S. Agriculture Department said it approved a consignment of 15,000 tonnes of U.S. Number 2 hard red winter wheat for shipment to the Soviet Union.
The wheat is for March 1-15 shipment and was sold by a U.S. exporter under the long-term grain supply agreement between the two countries, it said.
"""
predicted_labels = predict_topics(demo_text)
print(f"文章: {demo_text[:100]}...")
print(f"预测标签: {predicted_labels}")
# 预测标签: ['wheat', 'grain']
模型使用了路透社 Reuters-21578 数据集的 ModApte 子集进行训练。数据集通过 load_dataset 加载,并划分为 90% 的训练集和 10% 的验证集。
在预处理阶段,所有样本被格式化为 ### 文章\n{文章}\n\n### 标签\n{标签1}, {标签2}...<eos> 的形式。没有标签的样本被丢弃。
bitsandbytes 进行了 4-bit NF4 量化,以降低显存占用。r: 16lora_alpha: 32lora_dropout: 0.1target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]transformers 的 Seq2SeqTrainer 进行训练,因为它支持 predict_with_generate。| 超参数 | 值 |
|---|---|
learning_rate | 2e-4 |
num_train_epochs | 4 |
per_device_train_batch_size | 1 |
gradient_accumulation_steps | 8 |
| (有效批处理大小) | (8) |
fp16 | True |
max_length | 512 |
根据对 Qwen3 系列模型(7B, 14B, 32B)进行的横向评测,此 32B 模型在所有关键指标上均表现最佳。
| 指标 | 分数 |
|---|---|
| 子集准确率 (Subset Accuracy) | 0.391 |
| 加权 F1 分数 (Weighted F1) | 0.636 |
| 微观 F1 分数 (Micro F1) | 0.454 |
| 宏观 F1 分数 (Macro F1) | 0.290 |
| 汉明损失 (Hamming Loss) | 0.020 |
评估是在生成任务的框架下进行的,模型生成标签字符串,然后解析并与真实标签计算 F1 分数。
Reuters-21578 数据集中出现过的标签。earn, acq)上的表现要优于罕见类别。如果您在您的研究中使用了这个模型,请考虑引用:
@misc{your_name_2025_qwen3_reuters,
author = {Your Name},
title = {Qwen3-32B Fine-tuned for Reuters-21578 Multi-Label Classification},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face Hub},
howpublished = {\url{https://huggingface.co/your_username/qwen3-32b-reuters21578-multilabel}}
}
@inproceedings{lewis1997reuters,
title={Reuters-21578 text categorization test collection},
author={Lewis, David D.},
year={1997},
organization={AT\&T Labs}
}
@misc{qwen_team2024qwen2,
title={Qwen2: The New Generation of Qwen Large Language Models},
author={Qwen Team},
year={2024},
howpublished = {\url{https://qwen.ai/blog/qwen2/}}
}