Views
No views yet
sbintuitions/modernbert-ja-310mをファインチューニングしたものです。1CLASS_WEIGHTS = [
2 1.0, # apartment (236件)
3 1.72, # outdoor (137件)
4 18.15, # highway (13件)
5 9.08, # station (26件)
6 2.03, # commercial_facility (116件)
7]| クラス | Precision | Recall | F1-Score |
|---|---|---|---|
| apartment | 0.88 | 0.95 | 0.91 |
| outdoor | 0.88 | 0.83 | 0.86 |
| highway | 0.67 | 1.00 | 0.80 |
| station | 1.00 | 0.75 | 0.86 |
| commercial_facility | 0.83 | 0.71 | 0.76 |
pip install transformers torch1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# モデルとトークナイザーのロード
5model_name = "ttt421/modernbert-ja-location-classifier"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# 推論
10text = "マンションの3階から火が出ています"
11inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024)
12
13with torch.no_grad():
14 outputs = model(**inputs)
15 probs = torch.sigmoid(outputs.logits)[0]
16
17# 結果の表示
18labels = ["apartment", "outdoor", "highway", "station", "commercial_facility"]
19threshold = 0.5
20
21print("検出された場所タイプ:")
22for label, prob in zip(labels, probs):
23 if prob > threshold:
24 print(f" {label}: {prob:.3f}")1texts = [
2 "高速道路で事故が発生しました",
3 "駅のホームで人が倒れています",
4 "ショッピングモールで迷子になりました"
5]
6
7inputs = tokenizer(texts, return_tensors="pt", truncation=True, max_length=1024, padding=True)
8
9with torch.no_grad():
10 outputs = model(**inputs)
11 probs = torch.sigmoid(outputs.logits)
12
13for i, text in enumerate(texts):
14 print(f"
15テキスト: {text}")
16 print("場所タイプ:")
17 for label, prob in zip(labels, probs[i]):
18 if prob > threshold:
19 print(f" {label}: {prob:.3f}")highwayはテストサンプルが4件と少ないため、精度が不安定commercial_facilityのRecallが0.71と改善の余地あり