File size: 5,789 Bytes
d795fd7
 
7a8298c
 
 
 
d795fd7
 
446ae99
7a8298c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446ae99
7a8298c
2ef291b
6788187
 
 
8ec7874
6788187
 
 
 
 
 
 
 
 
78c3513
2ef291b
9304305
2ef291b
7a8298c
 
 
 
 
 
446ae99
7a8298c
59c0418
7a8298c
 
 
 
 
 
 
 
 
84dfcf6
7a8298c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d0404b
f96a30d
1d0404b
bb3d378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d0404b
 
6f3595f
 
 
 
 
 
 
 
 
a31fb98
 
 
 
 
 
6f3595f
 
30fd0dc
6f3595f
30fd0dc
 
 
 
 
 
 
 
 
 
 
 
6f3595f
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
141
142
143
144
145
146
147
148
149
150
151
---
library_name: transformers
tags:
  - japanese
  - ner
  - medical
---

# Model Card for `sociocom/MedTXTNER`

**本モデルは、日本語医療テキストの NER(固有表現抽出)タスク向けに `cl-tohoku/bert-base-japanese-v3` をファインチューニングしたモデルです。**

## モデル詳細

### 説明
- ベースに `cl-tohoku/bert-base-japanese-v3`を使用  
- 奈良先端大で作成された日本語医療テキストのアノテーション付きデータ(症例報告、読影レポート、看護記録)でファインチューニングを実施

| 項目                    | 詳細                                   |
|-------------------------|----------------------------------------|
| **Developed by**        | NAIST ソーシャルコンピューティング研究室       |
| **Model type**          | Token classification                  |
| **Language(s)**         | Japanese                               |
| **Finetuned from**      | cl-tohoku/bert-base-japanese-v3        |

### モデルソース
- **Hub リポジトリ**: https://huggingface.co/sociocom/MedTXTNER

## タグおよび属性一覧
| タグ名   | 説明                                      | 属性一覧                                        |
|----------|-------------------------------------------|-------------------------------------------------|
| a        | 臓器・部位(Anatomical parts)            | なし                                            |
| c        | 変化(Change)            | なし                                            |
| cc       | クリニカルコンテクスト(Clinical Context)| executed, negated, other, scheduled             |
| d        | 病変・症状(Diseases and symptoms)       | general, negative, positive, suspicious         |
| f        | 特徴・尺度(Features and measurements)   | なし                                            |
| m-key    | 薬品名(Medicine name)                   | executed, negated, other, scheduled             |
| m-val    | 薬品値(Medicine value)                  | executed, negated, other, scheduled             |
| r        | 治療(Remedy)                            | executed, negated, other, scheduled             |
| t-key    | 検査項目(Test item)                     | executed, negated, other, scheduled             |
| t-test   | 検査名(Test name)                       | executed, negated, other, scheduled             |
| t-val    | 検査値(Test value)                      | なし                                            |
| timex3   | 時間表現(Time expressions)              | age, date, duration, med, misc, set, time   |

各タグ・属性の詳細は[Real-MedNLP アノテーションガイドライン](https://sociocom.naist.jp/real-mednlp/wp-content/uploads/sites/3/2021/12/Real-MedNLP_Annotation_Guidelines.pdf)をご参照ください。

## 利用方法

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

model_dir = "sociocom/MedTXTNER"
model     = AutoModelForTokenClassification.from_pretrained(model_dir)
tokenizer = AutoTokenizer.from_pretrained(model_dir, use_fast=True)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()

def predict_text(text: str):
    enc = tokenizer(
        text,
        return_tensors="pt",
        truncation=True,
        padding="longest",
        is_split_into_words=False
    ).to(device)

    with torch.no_grad():
        outputs = model(**enc)
        logits  = outputs.logits

    pred_ids = torch.argmax(logits, dim=-1)[0].cpu().tolist()
    tokens = tokenizer.convert_ids_to_tokens(enc["input_ids"][0])
    id2label = model.config.id2label

    result = []
    for tok, pid in zip(tokens, pred_ids):
        if tok in tokenizer.all_special_tokens:
            continue
        result.append((tok, id2label[pid]))
    return result

sample = "症例】53歳女性。発熱と嘔気を認め、プレドニゾロンを中断しました。"
for tok, lab in predict_text(sample):
    print(f"{tok}\t{lab}")
```

## 出力例
```
症例    O
】      O
53      B-timex3_age
歳      I-timex3_age
女性    O
。      O
発熱    B-d_positive
と      I-d_positive
嘔      I-d_positive
##気    I-d_positive
を      O
認め    O
、      O
プレ    B-m-key_negated
##ド    I-m-key_negated
##ニ    I-m-key_negated
##ゾ    I-m-key_negated
##ロン  I-m-key_negated
を      O
中断    O
し      O
まし    O
た      O
。      O
```

## Evaluation

属性なし(エンティティタイプのみ評価)
| Dataset        | Micro‑F1 | Macro‑F1 | Weighted‑F1 |
| -------------- | --------:| --------:| -----------:|
| **Overall**    |     0.699 |     0.673 |       0.700 |
| **MedTxt‑CR**  |     0.608 |     0.575 |       0.612 |
| **MedTxt‑RR**  |     0.903 |     0.930 |       0.903 |
| **MedTxt‑NR**  |     0.800 |     0.788 |       0.800 |

属性あり(エンティティタイプ+属性を区別して評価)
| Dataset        | Micro‑F1 | Macro‑F1 | Weighted‑F1 |
| -------------- | --------:| --------:| -----------:|
| **Overall**    |     0.638 |     0.480 |       0.641 |
| **MedTxt‑CR**  |     0.551 |     0.396 |       0.559 |
| **MedTxt‑RR**  |     0.887 |     0.708 |       0.888 |
| **MedTxt‑NR**  |     0.730 |     0.552 |       0.731 |


## Publication

This model can be cites as:

```
@misc{social_computing_lab_2025,
	author       = { Social Computing Lab },
	title        = { MedTXTNER (Revision 6788187) },
	year         = 2025,
	url          = { https://huggingface.co/sociocom/MedTXTNER },
	doi          = { 10.57967/hf/5732 },
	publisher    = { Hugging Face }
}
```