Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 표집분포
- unstack
- ndarray
- dtype
- Python
- seaborn
- Numpy
- groupby
- type hints
- boolean & fancy index
- python 문법
- namedtuple
- 가능도
- 정규분포 MLE
- linalg
- pivot table
- Array operations
- scatter
- Python 유래
- 부스트캠프 AI테크
- 카테고리분포 MLE
- subplot
- 딥러닝
- VSCode
- 최대가능도 추정법
- Numpy data I/O
- Python 특징
- Operation function
- Comparisons
- BOXPLOT
Archives
- Today
- Total
또르르's 개발 Story
[16-3] Spacy를 이용한 영어 전처리 본문
1️⃣ 설정
spacy 모듈에서 'en'을 load 하면 tokenization를 쉽게 사용할 수 있습니다.
import spacy
spacy_en = spacy.load('en')
nlp = spacy.load('en_core_web_sm') # english의 tokenization이 가능
2️⃣ Tokenezation
위에서 선언한 nlp를 사용하면 쉽게 token을 분리할 수 있습니다.
doc = nlp('This assignment is about Natural Language Processing.' 'In this assignment, we will do preprocessing')
>>> print ([token.text for token in doc])
['This', 'assignment', 'is', 'about', 'Natural', 'Language', 'Processing', '.', 'In', 'this', 'assignment', ',', 'we', 'will', 'do', 'preprocessing']
3️⃣ 불용어 (Stopword)
불용어(Stopword)는 자주 등장하지만 분석에 있어 큰 도움이 되지 않는 단어 (I, my, me, over, 조사, 접미사 같은 단어)를 뜻합니다.
spacy_stopwords = spacy.lang.en.stop_words.STOP_WORDS
for stop_word in list(spacy_stopwords)[:30]:
print(stop_word)
everything
after
nobody
always
becomes
nothing
eleven
under
‘ll
hers
anything
would
herself
until
meanwhile
his
six
how
therefore
upon
wherein
such
everyone
she
too
well
'll
forty
beside
four
4️⃣ Lemmatization
표제어(Lemma)는 한글로는 '표제어' 또는 '기본 사전형 단어' 정도의 의미를 갖습니다. 표제어 추출은 단어들로부터 표제어를 찾아가는 과정입니다. 표제어 추출은 단어들이 다른 형태를 가지더라도, 그 뿌리 단어를 찾아가서 단어의 개수를 줄일 수 있는지 판단합니다.
예를 들어서 am, are, is는 서로 다른 스펠링이지만 그 뿌리 단어는 be라고 볼 수 있습니다. 이때, 이 단어들의 표제어는 be라고 합니다.
(출처:https://wikidocs.net/21707)
for token in text[:]:
print (token, "-", token.lemma_)
development - development
began - begin
Iron - Iron
Man - Man
in - in
May - May
5️⃣ 그외 token class의 attributes
print("token \t is_punct \t is_space \t shape_ \t is_stop")
print("="*70)
for token in text[21:31]:
print(token,"\t", token.is_punct, "\t\t",token.is_space,"\t\t", token.shape_, "\t\t",token.is_stop)
token is_punct is_space shape_ is_stop
======================================================================
of False False xx True
the False False xxx True
film False False xxxx False
Iron False False Xxxx False
Man False False Xxx False
in False False xx True
May False False Xxx True
2008 False False dddd False
, True False , False
Marvel False False Xxxxx False
'부스트캠프 AI 테크 U stage > 실습' 카테고리의 다른 글
[17-2] 번역 모델 전처리 using PyTorch (0) | 2021.02.17 |
---|---|
[17-1] LSTM / GRU with PyTorch (0) | 2021.02.16 |
[16-2] Word2Vec Using Konlpy (0) | 2021.02.16 |
[16-1] NaiveBayes Classifier Using Konlpy (0) | 2021.02.16 |
[14-3] Scaled Dot-Product Attention (SDPA) using PyTorch (0) | 2021.02.04 |