본문 바로가기
데이터분석/Python

머신러닝 Example by Python - 고유명사 태깅 시스템 만들기 (문서 분류)

by 버섯도리 2022. 1. 14.
# 스탠포드 고유명사 태깅 프로그램(zip) 다운로드 경로 : https://nlp.stanford.edu/software/CRF-NER.shtml#Download

# import nltk
# nltk.download('punkt')


## 1. 고유명사 태깅하기

from nltk.tag import StanfordNERTagger
from nltk.tokenize import word_tokenize

STANFORD_NER_CLASSIFIER_PATH = 'F:/1_Study/1_BigData/7_FirstML/stanford-ner-2020-11-17/classifiers/english.muc.7class.distsim.crf.ser.gz'
STANFORD_NER_JAR_PATH = 'F:/1_Study/1_BigData/7_FirstML/stanford-ner-2020-11-17/stanford-ner-4.2.0.jar'

ner_tagger = StanfordNERTagger(STANFORD_NER_CLASSIFIER_PATH, STANFORD_NER_JAR_PATH)

text = 'One day in November 2016, the two authors of this book, Seungyeon and Youngjoo, had a coffer at Red Back cafe, which is very popular place in Mountain View.'

tokens = word_tokenize(text)
print(ner_tagger.tag(tokens))

# 장소 정보만 추출
all_locations = []
for token in ner_tagger.tag(tokens):
    if token[1] == 'LOCATION':
        all_locations.append(token[0])
print(', '.join(all_locations))
 
 
 
 
 
 
출처 : 처음 배우는 머신러닝 : 기초부터 모델링, 실전 예제, 문제 해결까지