You need to agree to share your contact information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

fineweb-2-edu-zhtw-classifier

繁體中文(台灣)網頁教育價值分類器。以 nvidia/Nemotron-3-Embed-1B-BF16 作為凍結的特徵抽取器,上層接一個輕量 ordinal 分類 head。用於從 lianghsun/fineweb-2-zhtw 篩出 lianghsun/fineweb-2-edu-zhtw

效能

在獨立測試集(39,000 筆,未參與訓練與校準):

類別 precision recall F1 support
0 低(1–2 分) 0.9833 0.9731 0.9782 35,665
1 中(3 分) 0.6275 0.7113 0.6668 2,567
2 高(4–5 分) 0.7396 0.7656 0.7524 768
macro 0.7835 0.8167 0.7991 39,000
  • test macro F1 = 0.7991(未做任何不平衡處理的線性基準線為 0.7603)
  • test accuracy = 0.9518
混淆矩陣(列=真實,行=預測)
          低      中     高
低     34707    919     39
中       573   1826    168
高        15    165    588

真實為「高」的 768 筆中,只有 15 筆(2%)被誤判為「低」——誤差幾乎都落在相鄰類別, 這是 ordinal 建模帶來的性質。

模型架構

文本 → Nemotron-3-Embed-1B-BF16(凍結,encode_document)→ 2048 維
     → Linear(2048, 512) → ReLU → Dropout(0.1) → Linear(512, 2)
     → ordinal 解碼 → logit adjustment(τ=0.25) → per-class bias → argmax

ordinal head:輸出 2 維而非 3 維,是 K−1 個累積二元分類器 (P(y > 低)P(y > 中))。教育價值本質有序,這比視為無序三類更穩健。

校準參數存於 head.ptcalibration,推論時必須套用,否則會退回未校準的 決策邊界、macro F1 明顯下降:

adj = scores - tau * log(prior) + bias
group = adj.argmax(-1)

訓練

  • 標註:Qwen3.6-27B 依五級評分標準標註 260,000 筆繁中網頁(system_prompt.txt 隨附)
    • 主標註 200,000 筆(依 Common Crawl dump 分層抽樣)
    • 高分補標 60,000 筆(教育網域+學術用語密度啟發式;標籤仍由 LLM 判定
  • 標籤映射{1,2}→低{3}→中{4,5}→高
  • 類別分佈:237,767 : 17,110 : 5,123(約 46 : 3 : 1)
  • 超參搜尋:54 組(head 架構 × 損失函數 × 取樣策略),每組再做 post-hoc 校準
    • 損失:加權 CE / Focal(γ=2) / Logit-adjusted CE
    • 取樣:自然分佈 / 類別平衡過採樣
    • 校準:logit adjustment 掃 τ + per-class bias coordinate ascent(直接最大化 val macro F1)
  • 超參與校準只依 val 選擇,回報數字一律來自獨立 test

使用方式

import numpy as np, torch, torch.nn as nn
from huggingface_hub import hf_hub_download
from sentence_transformers import SentenceTransformer

ck = torch.load(hf_hub_download("lianghsun/fineweb-2-edu-zhtw-classifier", "head.pt"),
                map_location="cuda", weights_only=False)
hp, cal = ck["args"], ck["calibration"]
prior = np.array(cal["prior"]); tau = cal["tau"]; bias = np.array(cal["bias"])

head = nn.Sequential(nn.Linear(ck["dim"], hp["hidden"]), nn.ReLU(),
                     nn.Dropout(hp["dropout"]), nn.Linear(hp["hidden"], ck["n_classes"]))
head.load_state_dict(ck["state_dict"]); head = head.cuda().eval()

enc = SentenceTransformer("nvidia/Nemotron-3-Embed-1B-BF16", device="cuda",
                          model_kwargs={"dtype": torch.bfloat16})
enc.max_seq_length = 2048

def predict(texts):
    with torch.no_grad():
        e = enc.encode_document(texts, convert_to_tensor=True, show_progress_bar=False)
        lg = head(e.float()).cpu().numpy()
    p = 1 / (1 + np.exp(-lg))                      # ordinal 解碼
    s = np.stack([np.log(1 - p[:, 0] + 1e-9),
                  np.log(p[:, 0] + 1e-9) + np.log(1 - p[:, 1] + 1e-9),
                  np.log(p[:, 0] + 1e-9) + np.log(p[:, 1] + 1e-9)], 1)
    adj = s - tau * np.log(prior + 1e-12) + bias   # 校準(必要)
    return adj.argmax(1)                            # 0=低 1=中 2=高

print(predict(["史蒂芬-波茲曼定律敘述黑體輻射與絕對溫度四次方成正比,J = εσT⁴。",
               "今天要來介紹一款個人近來愛用的指甲油,單擦拍照就非常顯色~"]))
# → [2 0]

限制

  • 訓練標籤由 Qwen3.6-27B 產生,繼承該模型對「教育價值」的判斷偏好,非人工標註。
  • 「中」類(3 分)是效能瓶頸(F1 0.6668):它夾在兩端之間、邊界模糊, 比樣本量僅其 1/3 的「高」類表現更差。要提升應優先補 3 分附近樣本並明確化邊界定義。
  • 僅在繁體中文(台灣)網頁上訓練與評估,未驗證於簡體中文、PDF、對話或程式碼。
  • 評分標準針對「中學到博士級教學環境」設計,與其他用途的教育價值定義未必一致。

檔案

檔案 說明
head.pt 分類 head 權重 + 校準參數(prior / tau / bias
system_prompt.txt 標註用的五級評分標準(含各級真實範例)
sweep_results.json 54 組超參完整結果、分類報告、混淆矩陣

Citation

@misc{fineweb2_edu_zhtw_classifier,
  title        = {fineweb-2-edu-zhtw-classifier: Educational Value Classifier for Taiwan Traditional Chinese Web Text},
  author       = {Huang, Liang Hsun},
  year         = {2026},
  howpublished = {\url{https://huggingface.co/lianghsun/fineweb-2-edu-zhtw-classifier}}
}

Author

Huang Liang Hsun

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for lianghsun/fineweb-2-edu-zhtw-classifier