stopwords for konlpy - hexists/konlpy GitHub Wiki
stopwords for konlpy
stopwords PR์ด ์์ง merge ๋์ง ์์์ต๋๋ค.
PR์ด merge ๋ ๋ค ์ด ๊ธ์ ๋ณด๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ ์ ๊ทน์ ์ธ ๊ณต์ ๋ ์ ์ ๋ฏธ๋ฃน๋๋ค.
stopwords
stopwords, ํ๊ตญ์ด๋ก ๋ถ์ฉ์ด๋ ํ
์คํธ๋ฅผ ๋ถ์ํ ๋ ์๋ฏธ๊ฐ ์์ด ์ฌ์ฉํ์ง ์๋ ๋จ์ด๋ฅผ ์๋ฏธํฉ๋๋ค.
๋ณดํต ๋ฌธ์์์ ์ผ๋ฐ์ ์ผ๋ก ๋ํ๋๋ ๋จ์ด๋ฅผ ์๋ฏธํ๋ฉฐ, ๊ด์ฌ๋ ์ ์น์ฌ ํน์ ์กฐ์ฌ ๋ฑ์ด ์์ต๋๋ค.
์๋ฅผ ๋ค์ด, ์์ด์์ 'a, the'์ ๊ฐ์ ๋จ์ด๋ ํ๊ตญ์ด์์ '์ด, ๊ฐ'์ ๊ฐ์ ๋จ์ด์
๋๋ค.
stopwords๋ฅผ ์ผ๋ง๋ ์ ๋ค๋ฃจ๋๋์ ๋ฐ๋ผ ๋ ์ ์ ํ ๋ถ์์ ํ ์ ์์ต๋๋ค. ๋จ์ด์ ๋น๋๊ฐ ๋ถ์์ ์ค์ํ ์์๋ผ๊ณ ํ ๋, ๊ณ ๋น๋์ stopwords๋ฅผ ์ ์ธํ๋ฉด ๋ ์ ์๋ฏธํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค.
๋ณดํต stopwords๋ ์ ๋ ฅ ๋ฌธ์์ ๋ฐ๋ผ ์ ์ํด์ ์ฌ์ฉํ์ง๋ง, ๋ฏธ๋ฆฌ ์ ์๋ stopwords๊ฐ ์๋ค๋ฉด ๋ถ์ ์์ ์ ์ข ๋ ์ฝ๊ฒ ํ ์ ์์ต๋๋ค.
๋ํ์ ์ธ ์์ฐ์ด์ฒ๋ฆฌ ๋๊ตฌ์ธ NLTK์์๋ 11๊ฐ ์ธ์ด๋ฅผ ๋์์ผ๋ก 2,400๊ฐ์ stopwords๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ฏธ๋ฆฌ ์ ๊ณต๋ stopwords๋ฅผ ํตํด ๋ถ์์ ํฐ ์๋ฏธ๊ฐ ์๋ ๋จ์ด๋ค์ ์ฒ๋ฆฌํฉ๋๋ค. ์์ฝ๊ฒ๋ NLTK๋ ํ๊ตญ์ด stopwords๋ฅผ ์ ๊ณตํ์ง ์์ต๋๋ค. ๊ทธ๋์, ํ๊ตญ์ด๋ฅผ ์ํ stopwords๋ฅผ ์ ๊ณตํ๋ฉด ์ข๊ฒ ๋ค๋ ์๊ฐ์ด ๋ค์์ต๋๋ค.
ํ๊ตญ์ด stopwords ๊ฐ๋ฐ
ํ๊ตญ์ด stopwords๋ ํฌ๊ฒ 3๋จ๊ณ ๊ณผ์ ์ผ๋ก ๊ฐ๋ฐํ์ต๋๋ค.
1) nltk stopwords ์ ๊ณต ๋ฐฉ๋ฒ ์กฐ์ฌ
2) ํ๊ตญ์ด stopwords ์๋ฃ ์กฐ์ฌ ๋ฐ ์์ง
3) stopwords ๊ธฐ๋ฅ ๊ฐ๋ฐ
๋จผ์ , NLTK์์ stopwords๋ฅผ ์ด๋ป๊ฒ ์ ๊ณตํ๋์ง๋ฅผ ํ์ธํด๋ดค์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ , ํ๊ตญ์ด stopwords ๊ฐ๋ฐ์ ์ํด ์๋ฃ๋ค์ ์กฐ์ฌํ๊ณ ์์งํ์ต๋๋ค. ๋ง์ง๋ง์ผ๋ก konlpy์์ stopwords๋ฅผ ์ ๊ณตํ๊ธฐ ์ํด ์ฝ๋๋ฅผ ๋ถ์ํ๊ณ ๊ฐ๋ฐํ์ต๋๋ค.
nltk stopwords ์ ๊ณต ๋ฐฉ๋ฒ ์กฐ์ฌ
NLTK๋ ์๋์ฒ๋ผ stopwords๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
>>> from nltk.corpus import stopwords
>>> stopwords.words('english')
์ด๋ ๊ฒ ํธ์ถ์ ํ๋ฉด, list ํํ๋ก stopwords๋ฅผ ๋ถ๋ฌ์ต๋๋ค. stopwords๋ ์ฌ์ฉ์๊ฐ ์ฝ๊ฐ์ ์ฝ๋๋ฅผ ๋ํด์ ํ์ํ ํํ๋ก ์ฌ์ฉํ๊ฒ ๋ฉ๋๋ค. ์ ๋ ฅ์ tokenize ๋ค์ stopwords์ ํฌํจ๋ ๊ฒฝ์ฐ๋ฅผ ์ ์ธํ๊ฑฐ๋, stopwords๊ฐ ํฌํจ๋ token์ penalty๋ฅผ ์ฃผ๋ ๋ฑ ์ฌ๋ฌ๊ฐ์ง ํํ๋ก ํ์ฉํฉ๋๋ค.
stopwords๋ nltk์ corpus class์ ์์นํฉ๋๋ค. corpus class์์ ์ฌ๋ฌ ์ข ๋ฅ์ corpus๋ฅผ ์ฌ์ฉํ ์ ์๋๋ฐ, ๊ทธ ์ค ํ๋๋ก stopwords corpus๊ฐ ์ ๊ณต๋๊ณ ์์ต๋๋ค. stopwords์ ์ถ์ฒ๋ Porter el al๋ก ๋์ค๋๋ฐ, Porter Stemmer์์ ๊ฐ์ ธ์จ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค. (์ด ๋ถ๋ถ์ ๋ํด์๋ ์ข ๋ ํ์ธ์ด ํ์ํฉ๋๋ค.)
Corpus Compiler Contents
Stopwords Corpus Porter et al 2,400 stopwords for 11 languages
ํ๊ตญ์ด stopwords ์๋ฃ ์กฐ์ฌ ๋ฐ ์์ง
ํ๊ตญ์ด stopwords๋ฅผ ์ ๊ณตํ๊ธฐ ์ํด ๊ฒ์์ ํตํด ๋ค์ํ ์๋ฃ๋ค์ ์์งํ์ต๋๋ค. ๋ํ์ ์ธ ์๋ฃ๋ค์ ์๋์ ๊ฐ์ต๋๋ค. ์ด์ธ์๋ ์ฌ๋ฌ ์๋ฃ๋ค์ด ์์์ง๋ง ์ค๋ณต๋๋ ๊ฒ๋ค์ ๋๋ค.
| source | unit | license |
|---|---|---|
| bab2min | morph | ์ ์์๊ฒ ์ฌ์ฉ ํ๋ฝ ๋ฐ์ |
| ranks.nl | word | MIT๋ก ์ถ์ |
| spikeekips gist | word | ์ ์์๊ฒ ์ฌ์ฉ ํ๋ฝ ๋ฐ์ |
| 6 github | word | apache 2.0 |
| stopwords-iso github | word | MIT |
| many-stop-words | word | MIT |
ํํ์ ๋จ์๋ก ์ ๊ณต๋๋ bab2min์ stopwords์ ๋จ์ด ๋จ์๋ก ์์ง๋ ๋ค๋ฅธ stopwords๋ค์ด ์์ต๋๋ค. ๊ฐ๊ธฐ ๋ค๋ฅธ format์ผ๋ก ์ ์ฅ๋์ด ์๊ณ , ์๋ฃ๋ค๊ฐ์ ์ค๋ณต๋ ๋ง์ ํ๋๋ก ์ฌ์ฉํ๊ธฐ ์ํด ์ ์ฒ๋ฆฌ ๊ณผ์ ์ด ํ์ํฉ๋๋ค.
-
bab2min stopwords
์ด VCP 0.018279601 ์ VA 0.011699048 ํ VV 0.009773658 ... -
ranks.nl stopwords
์ ํด ์์ด๊ตฌ ...
์ ์๋ฃ๋ค์ ์ฌ์ฉํ๊ธฐ ์ํด ๋ผ์ด์ผ์ค๋ฅผ ํ์ธ ๋๋ ์ ์์ ํ๋ฝ์ด ๊ตฌํ์ต๋๋ค. konlpy์์ ์ฌ์ฉํ ๋ ๋ฌธ์ ์์์ ํ์ธํ์ต๋๋ค. ์ด ๊ธ์ ๋น์ด ํ์พํ stopwords ์ฌ์ฉ์ ํ๋ฝํด์ฃผ์ bab2min, spikeekips๊ป ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
stopwords ๊ธฐ๋ฅ ๊ฐ๋ฐ
์ฌ์ฉ์๊ฐ ์ต์ํ๊ฒ ์ฌ์ฉํ๋ ํํ๋ก konlpy์์๋ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ nltk์์ ์ ๊ณตํ๋ ํํ๋ก ๊ฐ๋ฐํ์ต๋๋ค. ํจ์์ ํ๋กํ ํ์ ์ ์ ์ํ๊ณ ๋ช๋ช ํ์ํ ๊ธฐ๋ฅ์ ๊ฐ๋ฐํ์ต๋๋ค.
์ฌ์ฉ์ฑ ์ธก๋ฉด์์ ๋จ์ด ๋จ์์ stopwords์ ํํ์ ๋จ์์ stopwords๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์, 2๊ฐ์ง ํํ์ stopwords๋ฅผ ์ ๊ณตํ ์ ์๋๋ก ํ์ต๋๋ค. ํํ์ ๋จ์์ ๊ฒฝ์ฐ ๋ถ์๊ธฐ์ ์ข ๋ฅ์ ๋ฐ๋ผ ๋ค๋ฅธ ํ์ฌ๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์, ์ด๋ฅผ ๊ฐ๊ฐ ๋ค๋ฃฐ ์ ์๋๋ก ๋ถ์๊ธฐ์ ๋ง๋ stopwords๋ฅผ ์ค๋นํ๊ณ , analyzer๋ฅผ ์ง์ ํด์ ์ฌ์ฉํ๋๋ก ๊ฐ๋ฐํ์ต๋๋ค.
>>> from konlpy.corpus import stopwords
>>> stopwords.words()
>>> stopwords.morph(analyzer='kkma')
๋ํ, ์ฌ์ฉ์๊ฐ ํ์์ ๋ฐ๋ผ ๋ํ๊ณ ๋นผ์ ์ฌ์ฉํ ์ ์๋ ๊ธฐ๋ฅ๋ ๊ฐ๋ฐํ์ต๋๋ค.
>>> stopwords.include('word', ['ํ', '๋ค'])
>>> stopwords.exclude('word', ['์ง์ง'])
์ ๊ธฐ๋ฅ๋ค์ konlpy.corpus์ stopwords๋ผ๋ class๋ฅผ ํตํด ๊ตฌํํ์ต๋๋ค.
๋ณ๋๋ก ์์ง๋ stopwords๋ฅผ konlpy์์ ์ฌ์ฉํ ์ ์๋๋ก ํ๋์ ํ์ผ๋ก ํฉ์น๋ ์ ์ฒ๋ฆฌ ํ๋ก๊ทธ๋จ์ ๊ฐ๋ฐํ๊ณ , ํํ์ ๋จ์์ stopwords ์ ๊ณต์ ์ํด analyzer์์ ์ฌ์ฉํ๋ ํ์ฌ๋ก ๋ณํํ๋ ํ๋ก๊ทธ๋จ์ ๊ฐ๋ฐํ์ต๋๋ค. (์ด ํ๋ก๊ทธ๋จ๋ค์ konlpy์ ํฌํจํ๋ ๊ฒ์ด ์ ์ ํ์ง ํ๋จํ ์ ์์ด, ๋ค๋ฅธ repo์ ์ ์ฅํ ์ํ์ ๋๋ค. maintainer์๊ฒ ํด๋น ๋ด์ฉ์ ๋ฌธ์ํ ์ํ์ ๋๋ค.)
Usage stopwords
konlpy์์ stopwords๋ฅผ ์์ฃผ ๊ฐ๋จํ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค.
-
stopwords ๋ถ๋ฌ์ค๊ธฐ
>>> from konlpy.corpus import stopwords -
stopwords ์ฌ์ฉํ๊ธฐ(๋จ์ด ๋จ์)
>>> stopwords.words() ['!', '"', '$', ... ] -
stopwords ์ฌ์ฉํ๊ธฐ(ํํ์ ๋จ์)
>>> stopwords.morphs(analyzer='kkma') ['๊ฐ/VV', '๊ฐ์ง/VV', '๊ฐ/VA', ... ] -
stopwords ์ถ๊ฐํ๊ธฐ
>>> stopwords.include('word', ['ํ', '๋ค']) -
stopwords ์ ์ธํ๊ธฐ
>>> stopwords.exclude('word', ['์ง์ง'])
Futher Works
- stopwords๋ฅผ ํ์ฉํ๋ example ์์ฑํฉ๋๋ค. ์ด๋ป๊ฒ ์ฐ๋์ง ์ด๋ค ์ ์ด ์ข์์ง ์ค๋ช ํ๋ ๊ธ์ ํตํด ํ์ฉ๋๋ฅผ ๋์ด๊ณ ์ถ์ต๋๋ค.
- ๋ค์ํ ๋ฌธ์์์ stopwords ์์งํ์ฌ, stopwords๋ฅผ ๋ณด๊ฐํ๊ณ ์ถ์ต๋๋ค.