File size: 3,564 Bytes
6ad3241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
language:
- ja
license: apache-2.0
base_model: sbintuitions/modernbert-ja-310m
tags:
- text-classification
- multi-label-classification
- japanese
- location-detection
- emergency-call
datasets: []
metrics:
- f1
- precision
- recall
pipeline_tag: text-classification
---

# ModernBERT 日本語場所タイプ分類モデル (改善版)

このモデルは、日本語の緊急通報テキストから場所タイプを多ラベル分類するために、`sbintuitions/modernbert-ja-310m`をファインチューニングしたものです。

## モデル概要

- **ベースモデル**: sbintuitions/modernbert-ja-310m
- **タスク**: 多ラベルテキスト分類(場所タイプ検出)
- **言語**: 日本語
- **ラベル**: apartment, outdoor, highway, station, commercial_facility

## 学習設定

### 改善内容
1. **クラス重み付け損失関数**の導入(少数クラスを重視)
2. **エポック数**: 20
3. **バッチサイズ**: 8
4. **学習率**: 2e-5
5. **Warmup ratio**: 0.15

### クラス重み
```python
CLASS_WEIGHTS = [
    1.0,   # apartment (236件)
    1.72,  # outdoor (137件)
    18.15, # highway (13件)
    9.08,  # station (26件)
    2.03,  # commercial_facility (116件)
]
```

## 性能

テストデータでの評価結果:

| クラス | 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 |

**総合スコア**:
- Micro Avg: Precision 0.86, Recall 0.84, F1 0.85
- Macro Avg: Precision 0.85, Recall 0.85, F1 0.84

## 使い方

### インストール

```bash
pip install transformers torch
```

### 基本的な使用例

```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# モデルとトークナイザーのロード
model_name = "ttt421/modernbert-ja-location-classifier"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# 推論
text = "マンションの3階から火が出ています"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024)

with torch.no_grad():
    outputs = model(**inputs)
    probs = torch.sigmoid(outputs.logits)[0]

# 結果の表示
labels = ["apartment", "outdoor", "highway", "station", "commercial_facility"]
threshold = 0.5

print("検出された場所タイプ:")
for label, prob in zip(labels, probs):
    if prob > threshold:
        print(f"  {label}: {prob:.3f}")
```

### バッチ処理

```python
texts = [
    "高速道路で事故が発生しました",
    "駅のホームで人が倒れています",
    "ショッピングモールで迷子になりました"
]

inputs = tokenizer(texts, return_tensors="pt", truncation=True, max_length=1024, padding=True)

with torch.no_grad():
    outputs = model(**inputs)
    probs = torch.sigmoid(outputs.logits)

for i, text in enumerate(texts):
    print(f"
テキスト: {text}")
    print("場所タイプ:")
    for label, prob in zip(labels, probs[i]):
        if prob > threshold:
            print(f"  {label}: {prob:.3f}")
```

## 制限事項

- `highway`はテストサンプルが4件と少ないため、精度が不安定
- `commercial_facility`のRecallが0.71と改善の余地あり

## ライセンス

Apache 2.0

## 引用

ベースモデル: [sbintuitions/modernbert-ja-310m](https://huggingface.co/sbintuitions/modernbert-ja-310m)