일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- UDF
- youtube data
- top_k
- airflow subdag
- chatGPT
- BigQuery
- requests
- tensorflow text
- TensorFlow
- GCP
- login crawling
- spark udf
- gather_nd
- flask
- XAI
- subdag
- 상관관계
- session 유지
- integrated gradient
- grad-cam
- hadoop
- correlation
- 유튜브 API
- API Gateway
- Retry
- Airflow
- GenericGBQException
- Counterfactual Explanations
- 공분산
- API
- Today
- Total
데이터과학 삼학년
KoNLPy 한국어 분류기 소개 본문
한국어 관련 대표적인 형태소 분류기는 konlpy에서 볼 수 있다.
kkma, komoran, mecab, twitter(현 okt) 등이 있다.
이것들을 활용하면 문장을 토큰나이저할 뿐만 아니라 품사까지 알 수 있어 분석에 맞게 쓸 수 있다.
mecab이 형태소 분류에 빠른 처리 속도를 보여 큰 용량의 데이터를 분석할때 적합해 보인다.
konlpy를 이용하여 간단히 문장을 토큰하여 count를 세어 word cloud로 표현한 코드는 아래와 같다.
!pip install konlpy
!pip install wordcloud
from konlpy.tag import Okt, Kkma,Komoran #형태소 분석기
from collections import Counter #빈도수 세기
from wordcloud import WordCloud #wordcloud
from PIL import Image
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from nltk.corpus import stopwords
def _word_count(df,kon,stopwords=stopwords):
konp = kon
result = []
for i in df.values :
for s in konp.nouns(str(i)):
if s not in stopwords:
result.append(s)
# result += konp.nouns(str(i))
res_count = Counter(result)
return res_count
def wordcloud(df,kon,n,stopwords=[]):
okt_count = _word_count(df,kon,stopwords=stopwords)
word_data = okt_count.most_common(n) ###
wc = WordCloud(font_path='/content/HANDotum.ttf',background_color='white',width=800,height=600) #mask=bus_mask)
cloud = wc.generate_from_frequencies(dict(word_data))
plt.figure(figsize=(10,8))
plt.imshow(cloud) #,interpolation="bilinear")
plt.axis('off')
plt.show()
return word_data
##------- 원하는 형태소 분석기 선택----------
ok = Okt()
km = Kkma()
kom = Komoran()
stopwords =['어쩌고','저쩌고']
status = wordcloud(data,kon=ok,n=70,stopwords=stopwords)
print(status)
자연어처리에서 아주 간단한 word count를 세어서 그림으로 표현해보는 것을 알아보았다.
count를 세는 것은 나중에 word를 vectorizer 할때 쓰을 수 있다. count_vectorize, tf-idf vectorize 등...
기초니 잘 알아두면 좋다.
사실 count만 잘 세어도 사람들의 선호도를 대략적으로 볼 수 있어 의미있는 데이터다.
(물론 표본수도 많고 표본 데이터가 충분히 대표성을 가질 만큼 좋아야 겠지만...)
https://konlpy-ko.readthedocs.io/ko/v0.4.3/morph/#comparison-between-pos-tagging-classes
형태소 분석 및 품사 태깅 — KoNLPy 0.4.3 documentation
형태소 분석 및 품사 태깅 형태소 분석 이란 형태소를 비롯하여, 어근, 접두사/접미사, 품사(POS, part-of-speech) 등 다양한 언어적 속성의 구조를 파악하는 것입니다. 품사 태깅 은 형태소의 뜻과 문맥을 고려하여 그것에 마크업을 하는 일입니다. 예를 들어: 가방에 들어가신다 -> 가방/NNG + 에/JKM + 들어가/VV + 시/EPH + ㄴ다/EFN KoNLPy로 품사 태깅하기 KoNLPy에는 품사 태깅을 하기 위한 옵션이 여럿 있는데,
konlpy-ko.readthedocs.io
'Natural Language Processing' 카테고리의 다른 글
[Text preprocessing] 텍스트 데이터의 encoding 형식을 알아내기 (0) | 2020.05.28 |
---|---|
[Text preprocessing] 한국어 문장 splitter (0) | 2020.05.27 |
[Text preprocessing] Lemmatization and Stemming (0) | 2020.03.24 |
[Text preprocessing] Cleaning and Normalization, Stopwords (0) | 2020.03.24 |
[Text preprocessing] Tokenization (0) | 2020.03.19 |