kiwi
설치
!pip install kiwipiepy
형태소 분석
from kiwipiepy import Kiwi
kiwi = Kiwi()
text = '오늘은 자연어 처리를 배우기 좋은 날이다.'
result = kiwi.tokenize(text)
result
명사 추출
def extract_noun(text):
result = kiwi.tokenize(text)
for token in result:
if token.tag in ['NNG', 'NNP']:
yield token.form
list(extract_noun('어제는 홍차를 마시고, 오늘은 커피를 마셨다.'))
한국어 문서 단어 행렬
데이터
import pandas as pd
df = pd.read_csv('news_ai.csv')
사용자 단어
kiwi.add_user_word('인공지능', 'NNP')
문서 단어 행렬
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(
max_features=100, # 최대 단어 수(빈도 순)
tokenizer=extract_noun) # 토큰화 방법
dtm = cv.fit_transform(df['본문'])