Views
No views yet
sbintuitions/modernbert-ja-130m. The model uses ModernBERT hidden states at special line-token positions and applies a binary classifier to each line.1import torch
2from transformers import AutoModel, AutoTokenizer
3
4
5LINE_TOKEN = "<line>"
6THRESHOLD = 0.6
7TEXT = """富士山は日本で最も高い山で、標高は3,776メートルである。
8山頂付近は夏でも気温が低く、天候が急に変化することがある。
9外部リンク: https://example.com/fuji
10この記事は検証可能な参考文献が不足しています。
11登山道は複数あり、利用者は体力や経験に応じて経路を選ぶ。
12カテゴリ: 日本の山 | 火山 | 世界遺産"""
13
14
15def main() -> None:
16 # ---------------------------------------------------------
17 # Load tokenizer and AutoModel-compatible line classifier.
18 # ---------------------------------------------------------
19 tokenizer = AutoTokenizer.from_pretrained("MK0727/corpus-refiner-jp")
20 model = AutoModel.from_pretrained("MK0727/corpus-refiner-jp", trust_remote_code=True)
21 model.eval()
22
23 # ---------------------------------------------------------
24 # Add the line marker before each input line.
25 # ---------------------------------------------------------
26 lines = TEXT.split("\n")
27 text = "".join(f"{LINE_TOKEN}{line}" for line in lines)
28 inputs = tokenizer(text, return_tensors="pt")
29
30 # ---------------------------------------------------------
31 # Predict the keep probability for each line marker.
32 # ---------------------------------------------------------
33 with torch.no_grad():
34 logits = model(**inputs).logits
35 probabilities = torch.softmax(logits, dim=-1)[:, 1].detach().cpu().tolist()
36
37 # ---------------------------------------------------------
38 # Print each line with its predicted label and probability.
39 # ---------------------------------------------------------
40 for line_number, (line, probability) in enumerate(zip(lines, probabilities, strict=True), start=1):
41 label = "KEEP" if probability >= THRESHOLD else "DELETE"
42 print(f"{line_number:02d} [{label:<6}] {probability:.4f} {line}")
43
44
45if __name__ == "__main__":
46 main()01 [KEEP ] 0.9673 富士山は日本で最も高い山で、標高は3,776メートルである。
02 [KEEP ] 0.9888 山頂付近は夏でも気温が低く、天候が急に変化することがある。
03 [DELETE] 0.0240 外部リンク: https://example.com/fuji
04 [DELETE] 0.0817 この記事は検証可能な参考文献が不足しています。
05 [KEEP ] 0.8815 登山道は複数あり、利用者は体力や経験に応じて経路を選ぶ。
06 [DELETE] 0.0447 カテゴリ: 日本の山 | 火山 | 世界遺産sbintuitions/modernbert-ja-130m<line>. The model classifies the hidden state corresponding to each line token, so one forward pass can produce predictions for multiple lines.MK0727/noise-line-label-jp, a Japanese line-level dataset with lines_to_keep annotations.MK0727/noise-line-label-jp.F1 keep, because the model is intended to preserve useful corpus lines while removing noisy ones.| Metric | Score (higher is better, max 1.0) | Meaning |
|---|---|---|
| F1 keep | 0.927 | Balance between keeping useful lines and avoiding noisy lines |
| Precision keep | 0.946 | How often kept lines are actually useful |
| Recall keep | 0.908 | How many useful lines the model keeps |
