• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

固有表現抽出

date: 2022-02-27 excerpt: 固有表現抽出について

tag: statistics機械学習bertner固有表現抽出python


固有表現抽出について

概要

  • 固有表現抽出はNERと呼ばれることもある
  • エンティティを抽出するアルゴリズムの1つ
    • エンティティは以下のようなもの
      • 任意の人
      • 場所
      • 物の名前
  • Google NLP APIでも同様の機能がある

transformer(hugging face)による例

from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import pipeline

tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
model = AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER")

NER = pipeline("ner", model=model, tokenizer=tokenizer)
example = "My name is Kobayashi and I live in Japan. I bought a Chocoball chocolate in Russia."

results = NER(example)
print(results)

出力

[{'entity': 'B-PER', 'score': 0.9991658, 'index': 4, 'word': 'Ko', 'start': 11, 'end': 13}, 
{'entity': 'I-PER', 'score': 0.62678564, 'index': 5, 'word': '##bayashi', 'start': 13, 'end': 20}, 
{'entity': 'B-LOC', 'score': 0.9998134, 'index': 10, 'word': 'Japan', 'start': 35, 'end': 40}, 
{'entity': 'B-MISC', 'score': 0.7207684, 'index': 15, 'word': 'Cho', 'start': 53, 'end': 56}, 
{'entity': 'I-MISC', 'score': 0.42669713, 'index': 17, 'word': '##ball', 'start': 58, 'end': 62}, 
{'entity': 'B-LOC', 'score': 0.9997788, 'index': 20, 'word': 'Russia', 'start': 76, 'end': 82}]

entityの凡例

  • 物の名前などの固有名詞
    • B-MISC
    • I-MISC
  • 場所や地名などの固有名詞
    • B-LOC
    • I-LOC
  • 人名などの固有名詞
    • B-PER
    • I-PER


statistics機械学習bertner固有表現抽出python Share Tweet