Skip to content

spaCy

설치

!pip install spacy

영어 모델 설치

!python -m spacy download en_core_web_sm

한국어 모델 설치

!python -m spacy download ko_core_news_sm

품사 태깅

import spacy

nlp = spacy.load("en_core_web_sm")

text = "All work and no play makes Jack a dull boy."
doc = nlp(text)

for token in doc:
    print(token.text,
          token.lemma_,  # 표제어
          token.pos_,    # 단어의 품사
          token.tag_,    # 자세한 품사
          token.is_stop) # 불용어 여부

용어 설명

spacy.explain('PROPN')

문장 구조

from IPython.display import SVG
SVG(spacy.displacy.render(doc))
for token in doc:
    print(token.text,
          token.dep_,   # 의존 관계
          token.head)   # 지배소