BERT Chinese SMS Name Classifier

模型描述

這是一個基於 ckiplab/bert-base-chinese 微調的中文 BERT 模型,專門用於識別 SMS 簡訊中是否包含人名的二元分類任務。

模型用途

  • 任務: 文本分類 (Text Classification)
  • 語言: 中文 (Chinese)
  • 領域: SMS 簡訊、姓名識別
  • 分類: 二元分類 (包含姓名 vs 不包含姓名)

性能表現

指標 數值
驗證準確率 0.9965
最佳準確率 0.9965

訓練資料

  • 訓練集大小: 6888 筆
  • 驗證集大小: 861 筆
  • 測試集大小: 862 筆

使用方法

from transformers import BertTokenizer, BertForSequenceClassification
import torch

# 載入模型和分詞器
model_name = "renhehuang/bert-chinese-sms-name-classifierv2"
tokenizer = BertTokenizer.from_pretrained(model_name)
model = BertForSequenceClassification.from_pretrained(model_name)

# 預測函數
def predict_name_in_sms(text, max_length=256):
    model.eval()
    encoding = tokenizer.encode_plus(
        text,
        add_special_tokens=True,
        max_length=max_length,
        return_token_type_ids=False,
        padding='max_length',
        truncation=True,
        return_attention_mask=True,
        return_tensors='pt'
    )

    with torch.no_grad():
        outputs = model(
            input_ids=encoding['input_ids'],
            attention_mask=encoding['attention_mask']
        )

        logits = outputs.logits
        probabilities = torch.softmax(logits, dim=-1)

        predicted_class = torch.argmax(logits, dim=-1).item()
        confidence = probabilities[0][predicted_class].item()

    return predicted_class, confidence

# 使用範例
text = "王先生您好,您的訂單已確認"
predicted_class, confidence = predict_name_in_sms(text)
print(f"預測類別: {predicted_class} (信心度: {confidence:.4f})")

訓練配置

  • 基礎模型: ckiplab/bert-base-chinese
  • 訓練週期: 5 epochs
  • 批次大小: 8
  • 學習率: 3e-05
  • 最大序列長度: 256
  • 訓練設備: mps
  • 早停機制: 啟用

特殊優化

Apple Silicon 優化: 此模型針對 Apple Silicon (M1/M2/M3) 晶片進行了特別優化,包括 MPS GPU 加速和記憶體優化。

標籤說明

  • 0: 不包含姓名
  • 1: 包含姓名

使用場景

  1. 客服系統: 自動識別客戶訊息中是否提及具體人名
  2. 內容審核: 檢測訊息中的個人資訊
  3. 資料分析: 統計包含個人姓名的簡訊比例
  4. 隱私保護: 識別需要匿名化處理的內容

限制和注意事項

  1. 此模型專門針對中文 SMS 簡訊文本進行訓練
  2. 最佳性能表現在長度不超過 256 個 token 的文本上
  3. 主要適用於繁體中文內容,在簡體中文上可能有細微差異
  4. 專注於識別常見的中文姓氏和稱謂

引用

如果您使用了此模型,請引用:

@misc{bert-chinese-sms-name-classifier,
  title={BERT Chinese SMS Name Classifier},
  author={renhehuang},
  year={2025},
  publisher={Hugging Face},
  journal={Hugging Face Model Hub},
}

聯絡資訊

如有問題或建議,請通過 Hugging Face 或 GitHub 聯絡作者。

Downloads last month
5
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Evaluation results