🚀 数学快速文本分类器
这是一个用于筛选预训练数据集的文本分类器,可将文本分为数学和其他类别,在数学数据处理上表现出色且速度极快。
🚀 快速开始
本分类器是 快速文本分类器集合 的一部分,用于筛选预训练数据集。它可以将文本分为“数学”或“其他”类别。该模型在 160 万条记录上进行训练,这些记录来自网站,数学和非数学内容各占 50%,在测试集上的 F1 分数达到了 0.99(好得令人难以置信?)。这是对数学数据有意进行过采样的结果。该分类器可用于大语言模型(LLM)预训练数据的筛选,以增强模型在数学方面的能力。它速度极快 ⚡,使用 CPU 时吞吐量约为 2000 篇文档/秒。
不要低估“老派”的快速文本分类器!它实际上是一种优秀且可扩展的实践方法。例如,QWEN2.5 - MATH 就利用快速文本筛选预训练数据,尽管其分类器并未开源。
✨ 主要特性
- 高效分类:能够快速准确地将文本分为数学和其他类别。
- 数据均衡:训练数据中数学和非数学内容比例为 50:50。
- 性能优异:在测试集上 F1 分数达到 0.99。
- 速度极快:使用 CPU 时吞吐量约为 2000 篇文档/秒。
📦 安装指南
文档未提及具体安装步骤,故跳过此章节。
💻 使用示例
基础用法
from typing import List
import re
from huggingface_hub import hf_hub_download
import fasttext
model_hf = fasttext.load_model(hf_hub_download("kenhktsui/maths-fasttext-classifier", "model.bin"))
def replace_newlines(text: str) -> str:
return re.sub("\n+", " ", text)
def predict(text_list: List[str]) -> List[dict]:
text_list = [replace_newlines(text) for text in text_list]
pred = model.predict(text_list)
return [{"label": l[0].lstrip("__label__"), "score": s[0]}
for l, s in zip(*pred)]
predict([
"""This is a lightning fast model, which can classify at throughtput of 2000 doc/s with CPU""",
"""Differential geometry is a mathematical discipline that studies the geometry of smooth shapes and smooth spaces, otherwise known as smooth manifolds. It uses the techniques of single variable calculus, vector calculus, linear algebra and multilinear algebra.""",
"""Given $p$: $|4x - 3|\leqslant 1$ and $q$: $x^{2}-(2a + 1)x + a^{2}+a\leqslant 0$, find the range of values for $a$ if $p$ is a necessary but not sufficient condition for $q$."""
])
📚 详细文档
评估指标
属性 |
详情 |
模型类型 |
快速文本分类器 |
训练数据 |
来自网站的 160 万条记录,数学和非数学内容各占 50% |
评估指标 |
F1 分数 |
测试集 F1 分数 |
0.99 |
评估结果
precision recall f1-score support
Maths 0.99 0.98 0.99 200000
Others 0.98 0.99 0.99 200000
accuracy 0.99 400000
macro avg 0.99 0.99 0.99 400000
weighted avg 0.99 0.99 0.99 400000
🔧 技术细节
文档未提供具体技术实现细节,故跳过此章节。
📄 许可证
本项目采用 MIT 许可证。
⚠️ 重要提示
该分类器对短文本的处理效果不佳,这可能并不令人意外。