库名称: transformers
数据集:
- WebOrganizer/TopicAnnotations-Llama-3.1-8B
- WebOrganizer/TopicAnnotations-Llama-3.1-405B-FP8
基础模型:
- Alibaba-NLP/gte-base-en-v1.5
WebOrganizer/TopicClassifier
[论文] [官网] [GitHub]
TopicClassifier模型能根据网页URL和文本内容,将网络内容归类至17个类别中。
该模型基于gte-base-en-v1.5(1.4亿参数)微调而成,训练数据包括:
- WebOrganizer/TopicAnnotations-Llama-3.1-8B:由Llama-3.1-8B标注的100万文档(第一阶段训练)
- WebOrganizer/TopicAnnotations-Llama-3.1-405B-FP8:由Llama-3.1-405B-FP8标注的10万文档(第二阶段训练)
全领域分类器
使用方法
输入格式要求:
{URL}
{文本内容}
示例:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("WebOrganizer/TopicClassifier")
model = AutoModelForSequenceClassification.from_pretrained(
"WebOrganizer/TopicClassifier",
trust_remote_code=True,
use_memory_efficient_attention=False)
web_page = """http://www.example.com
如何从零开始组装电脑?以下是所需组件..."""
inputs = tokenizer([web_page], return_tensors="pt")
outputs = model(**inputs)
probs = outputs.logits.softmax(dim=-1)
print(probs.argmax(dim=-1))
通过softmax转换模型的logits
输出,可获得以下24个类别的概率分布(标签顺序参见模型配置中的id2label
和label2id
):
- 成人内容
- 艺术与设计
- 软件开发
- 犯罪与法律
- 教育与就业
- 硬件
- 娱乐
- 社交生活
- 时尚与美容
- 金融与商业
- 餐饮美食
- 游戏
- 健康
- 历史
- 家居与爱好
- 工业
- 文学
- 政治
- 宗教
- 科学与技术
- 软件
- 运动健身
- 交通运输
- 旅行
完整类别定义参见分类体系配置。
高效推理
推荐启用解填充和内存高效注意力机制(需安装xformers
,详见说明):
AutoModelForSequenceClassification.from_pretrained(
"WebOrganizer/TopicClassifier",
trust_remote_code=True,
unpad_inputs=True,
use_memory_efficient_attention=True,
torch_dtype=torch.bfloat16
)
引用
@article{wettig2025organize,
title={Organize the Web: Constructing Domains Enhances Pre-Training Data Curation},
author={Alexander Wettig and Kyle Lo and Sewon Min and Hannaneh Hajishirzi and Danqi Chen and Luca Soldaini},
journal={arXiv preprint arXiv:2502.10341},
year={2025}
}