0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

spaCy GiNZAに含まれる全てのentity(固有表現)を表示する方法

Posted at

特定の文章のentityを表示する方法は以下のとおりです。

import spacy
                #またはja_ginza_electra, ja_ginza
nlp = spacy.load("ja_ginza_bert_large")
sample_text =  "イタリアでは犬も歩けば猫に出会う。"
doc = nlp(sample_text)

for ent in doc.ents:
    print(ent.text, ent.label_)

displacyを用いれば視覚的に分かりやすく表示することも可能です。(displayではないのでタイプミスに注意)

from spacy import displacy

displacy.render(doc, style="ent", jupyter=True)

もっとも、文章を指定せずに、そのモデルで抽出できる全てのentityをprintしたい時は以下のように記載すれば良い。

all_entity = nlp.get_pipe("ner").labels
print(all_entity)

"ner"によってNamed Entity Recognitionを指定しています。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?