🚀 數學快速文本分類器
這是一個用於篩選預訓練數據集的文本分類器,可將文本分為數學和其他類別,在數學數據處理上表現出色且速度極快。
🚀 快速開始
本分類器是 快速文本分類器集合 的一部分,用於篩選預訓練數據集。它可以將文本分為“數學”或“其他”類別。該模型在 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 許可證。
⚠️ 重要提示
該分類器對短文本的處理效果不佳,這可能並不令人意外。