일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 출력층
- 풀링층
- 합성곱층
- 자연어 전처리
- 카운트 벡터
- 과적합
- 텍스트 마이닝
- cnn
- NLTK
- 원-핫 인코딩
- 합성곱 신경망
- 입력층
- 클러스터링
- 시계열 분석
- 생성모델
- 이미지 분류
- 양방향 RNN
- 프로그래머스
- 순환 신경망
- 임베딩
- KONLPY
- 딥러닝
- 망각 게이트
- 완전연결층
- RNN
- COLAB
- 코딩테스트
- 성능 최적화
- 코랩
- 전이학습
Archives
- Today
- Total
Colab으로 하루에 하나씩 딥러닝
자연어 전처리_2.전처리_3) 어간 추출 / 표제어 추출 본문
728x90
어간 추출(stemming) / 표제어 추출(lemmatization)
- 단어의 원형을 찾아 주는 것
- 단어 그 자체만 고려하기 때문에 품사가 달라도 사용 가능
- 어간 추출과 표제어 추출이 공통적으로 어근 추출이 목적
- 어간 추출은 사전에 없는 단어도 추출할 수 있지만 표제어 추출은 사전에 있는 단어만 추출할 수 있음
포터 알고리즘
- 단어의 원형이 비교적 잘 보전되어 있음
### 포터 알고리즘
from nltk.stem import PorterStemmer
stemmer = PorterStemmer()
print(stemmer.stem('obsesses'), stemmer.stem('obsessed'))
print(stemmer.stem('standardizes'), stemmer.stem('standardization'))
print(stemmer.stem('national'), stemmer.stem('nation'))
print(stemmer.stem('absentness'), stemmer.stem('absently'))
print(stemmer.stem('tribalical'), stemmer.stem('tribalicalized')) # 사전에 없는 단어
랭커스터 알고리즘
- 단어 원형을 알아볼 수 없을 정도로 축소시키기 때문에 정확도가 낮음
- 일반적인 상황보다는 데이터셋을 축소시키는 상황에서나 효과적
### 랭커스터 알고리즘
from nltk.stem import LancasterStemmer
stemmer = LancasterStemmer()
print(stemmer.stem('obsesses'), stemmer.stem('obssesed'))
print(stemmer.stem('standardizes'), stemmer.stem('standardization'))
print(stemmer.stem('national'), stemmer.stem('nation'))
print(stemmer.stem('absentness'), stemmer.stem('absently'))
print(stemmer.stem('tribalical'), stemmer.stem('tribalicalized')) # 사전에 없는 단어
표제어 추출
- 일반적으로 어간 추출보다 표제어 추출의 성능이 더 좋음
- 품사와 같은 문법뿐만 아니라 문장 내에서 단어 의미도 고려하기 때문에 성능이 좋음
- 어간 추출보다 시간이 더 오래 걸림
### 표제어 추출
import nltk
nltk.download('omw-1.4')
nltk.download('wordnet')
from nltk.stem import WordNetLemmatizer # 표제어 추출 라이브러리
lemma = WordNetLemmatizer()
print(stemmer.stem('obsesses'), stemmer.stem('obssesed'))
print(lemma.lemmatize('standardizes'), lemma.lemmatize('standardization'))
print(lemma.lemmatize('national'), lemma.lemmatize('nation'))
print(lemma.lemmatize('absentness'), lemma.lemmatize('absently'))
print(lemma.lemmatize('tribalical'), lemma.lemmatize('tribalicalized')) # 사전에 없는 단어
### 품사 정보가 추가된 표제어 추출
print(lemma.lemmatize('obsesses','v'), lemma.lemmatize('obssesed','a'))
print(lemma.lemmatize('standardizes','v'), lemma.lemmatize('standardization','n'))
print(lemma.lemmatize('national','a'), lemma.lemmatize('nation','n'))
print(lemma.lemmatize('absentness','n'), lemma.lemmatize('absently','r'))
print(lemma.lemmatize('tribalical','a'), lemma.lemmatize('tribalicalized','v')) # 사전에 없는 단어
출처: 서지영, 『딥러닝 텐서플로 교과서』, 길벗(2022)
'딥러닝_개념' 카테고리의 다른 글
자연어 전처리_3.임베딩_1) 희소 표현 기반 임베딩(원-핫 인코딩) (0) | 2022.12.12 |
---|---|
자연어 전처리_2.전처리_4) 정규화 (1) | 2022.12.10 |
자연어 전처리_2.전처리_2) 불용어 제거 (0) | 2022.12.09 |
자연어 전처리_2.전처리_1) 토큰화 (2) | 2022.12.08 |
자연어 전처리_1.자연어 처리 (2) | 2022.12.07 |