Edit model card

日本語医療固有表現抽出モデル

概要

ソーシャル・コンピューティング研究室さまより公開されているMedTxt-CRを用いて、alabniiさまより公開されているRoBERTaをfine-tuningした固有表現抽出モデルです。

文中のトークンに対して以下のいずれかのタグをIOB2形式で付与します (PositiveやNegativeなどの事実性が同時に付与されるタグもあります)。 詳細はこちらをご覧ください。

  • 病名/症状: d
  • 臓器/部位: a
  • 特徴/尺度: f
  • 変化: c
  • 時間表現: TIMEX3
  • 検査名: t-test
  • 検査項目: t-key
  • 検査値: t-val
  • 薬品名: m-key
  • 薬品値: m-val
  • 処置: r
  • クリニカルコンテキスト: cc
  • 保留: p
  • Outside: O

fine-tuning時のハイパーパラメータ

  • learning rate: 1e-5
  • batch size: 32
  • optimizer: AdamW
  • scheduler: linear
  • epochs: 78
  • max seq: 500

使用方法

入力は文単位で出力はIOB2系列です。

1

from transformers import BertForTokenClassification, AutoModel, AutoTokenizer
import mojimoji
import torch
text = "サンプルテキスト"
model_name = "daisaku-s/medtxt_ner_roberta"
with torch.inference_mode():
    model = BertForTokenClassification.from_pretrained(model_name).eval()
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    idx2tag = model.config.id2label
    vecs = tokenizer(mojimoji.han_to_zen(text), 
                     padding=True, 
                     truncation=True, 
                     return_tensors="pt")
    ner_logits = model(input_ids=vecs["input_ids"], 
                       attention_mask=vecs["attention_mask"])
    idx = torch.argmax(ner_logits.logits, dim=2).detach().cpu().numpy().tolist()[0]
    token = [tokenizer.convert_ids_to_tokens(v) for v in vecs["input_ids"]][0][1:-1]
    pred_tag = [idx2tag[x] for x in idx][1:-1]

2

from transformers import pipeline
text = "サンプルテキスト"
model_name = "daisaku-s/medtxt_ner_roberta"
ner = pipeline("ner", model=model_name)
results = ner(text)
print(results)

実験結果 (Micro-F1)

5分割グループ交差検証による内挿評価の結果になります。 訓練データの20%を検証データとして使用し、100エポック学習させた中で検証データにおけるMicro-F1が最も高かった時のエポック時のモデルを用いてテストデータの評価を行いました。 なお、検証データにおける最適なエポックの平均値で公開しているモデルは学習しております。

Fold RoBERTa Epoch
0 0.701 92
1 0.704 86
2 0.728 98
3 0.715 75
4 0.732 41
Avg. 0.716 78

参考文献

  • MedTxt-CR: 症例報告 (Case Reports) コーパス
  • 杉本海人, 壹岐太一, 知田悠生, 金沢輝一, 相澤彰子, JMedRoBERTa: 日本語の医学論文にもとづいた事前学習済み言語モデルの構築と評価, 言語処理学会第29回年次大会, 2023.
Downloads last month
11
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.