🚀 精細網絡教育FastText分類器
本項目是一個基於FastText的分類器,用於判斷網頁的教育價值。它藉助訓練數據 fineweb-edu-llama3-annotations 進行訓練,具備兩大核心目標:一是實現高吞吐量優化,在CPU上每秒可分類超2000個示例,適用於預訓練階段即時處理海量數據;二是對比FastText輕量級模型與基於Transformer的原模型 HuggingFaceFW/fineweb-edu-classifier 的性能差異。
模型信息
🚀 快速開始
本模型是一個基於FastText的分類器,用於根據訓練數據 fineweb-edu-llama3-annotations 判斷網頁的教育價值。它有兩個目標:
FastText方法的靈感來自於我基於不同的教育價值定義獨立開發的教育分類器,可在 kenhktsui/llm-data-textbook-quality-fasttext-classifier-v2 找到。
💻 使用示例
基礎用法
from typing import List
import re
from huggingface_hub import hf_hub_download
import fasttext
model_hf = fasttext.load_model(hf_hub_download("kenhktsui/fineweb-edu-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_hf.predict(text_list)
return [{"label": int(l[0].lstrip("__label__")), "score": s[0]}
for l, s in zip(*pred)]
predict(["Hi"])
📊 評估
使用最後46867個樣本作為測試數據,但這與 HuggingFaceFW/fineweb-edu-classifier 中的測試數據並不完全相同。
分類報告
精確率 召回率 f1分數 樣本數
0 0.72 0.44 0.55 5704
1 0.73 0.87 0.80 26595
2 0.52 0.49 0.50 10350
3 0.48 0.33 0.39 3397
4 0.69 0.03 0.06 819
5 0.00 0.00 0.00 2
準確率 0.68 46867
宏平均 0.52 0.36 0.38 46867
加權平均 0.67 0.68 0.66 46867
下面的表格比較了FastText模型和基於Transformer的模型。
標籤0、1、2與原始模型相當。從標籤3開始,性能下降開始明顯,到標籤4時差距進一步擴大,這是由於FastText模型的容量有限。因此,該分類器在標籤0、1、2上表現良好,在標籤3上也有一定表現,但性能有所下降。
混淆矩陣
[ 2537 3098 65 4 0 0]
[ 944 23037 2491 123 0 0]
真實標籤 [ 26 4742 5048 533 1 0]
[ 4 434 1846 1105 8 0]
[ 0 38 213 544 24 0]
[ 0 0 0 0 2 0]
預測標籤
該模型的準確率為68%,並且它更傾向於低估教育價值而不是高估。這種保守性對於過濾大量數據很有好處。
預測 - 實際評級 |
頻率 |
百分比 |
0 |
31751 |
67.7% |
-1 |
8078 |
17.2% |
+1 |
6130 |
13.1% |
-2 |
673 |
1.4% |
+2 |
189 |
0.4% |
-3 |
42 |
0.1% |
+3 |
4 |
0.0% |
在MiniPile訓練集和測試集中,Spearman等級相關係數分別為0.5881和0.5832,這表明在超過100萬個具有代表性的網頁數據文檔中存在中等強度的單調關係。
📄 許可證
本項目採用ODC-BY許可證。