Socket
Socket
Sign inDemoInstall

soykeyword

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soykeyword

Unsupervised Keyword Extracters


Maintainers
1

Python library for Keyword Extraction

ํ‚ค์›Œ๋“œ / ์—ฐ๊ด€์–ด ์ถ”์ถœ์„ ์œ„ํ•œ ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ž…๋‹ˆ๋‹ค. by Lovit (Hyunjoong) and Hunsik Shin

soykeyword ์—์„œ ์ถ”์ถœํ•˜๋Š” ํ‚ค์›Œ๋“œ์™€ ์—ฐ๊ด€์–ด๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ •์˜๋ฉ๋‹ˆ๋‹ค. ํ•œ ๋ฌธ์„œ ์ง‘ํ•ฉ์˜ ํ‚ค์›Œ๋“œ๋Š” ๋‹ค๋ฅธ ๋ฌธ์„œ ์ง‘ํ•ฉ๊ณผ ํ•ด๋‹น ๋ฌธ์„œ ์ง‘ํ•ฉ์„ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋Š” ์งˆ ์ข‹์€ ๋‹จ์–ด์ด๋ฉฐ (๊ตฌ๋ถ„๋ ฅ, discriminative power), ํ•ด๋‹น ์ง‘ํ•ฉ์„ ์ž˜ ์„ค๋ช…ํ•  ์ˆ˜ ์žˆ๋Š” (์„ค๋ช…๋ ฅ, high coverage) ๋‹จ์–ด์ž…๋‹ˆ๋‹ค. ๋นˆ๋„์ˆ˜๊ฐ€ ๋‚ฎ์€ ๋‹จ์–ด๋Š” ํ•œ ์ง‘ํ•ฉ์—์„œ๋งŒ ๋“ฑ์žฅํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌ๋ถ„๋ ฅ์€ ํฌ์ง€๋งŒ ์„ค๋ช…๋ ฅ์ด ์•ฝํ•ฉ๋‹ˆ๋‹ค. ์ œ์•ˆ๋œ ๋‘ ๊ฐ€์ง€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋†’์€ ์„ค๋ช…๋ ฅ๊ณผ ๊ตฌ๋ถ„๋ ฅ์„ ๋™์‹œ์— ์ง€๋‹ˆ๋Š” ๋‹จ์–ด๋“ค์„ ํ‚ค์›Œ๋“œ๋กœ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

์—ฐ๊ด€์–ด๋Š” ๊ธฐ์ค€ ๋‹จ์–ด๊ฐ€ ํฌํ•จ๋œ ๋ฌธ์„œ ์ง‘ํ•ฉ๊ณผ ํฌํ•จ๋˜์ง€ ์•Š์€ ๋ฌธ์„œ ์ง‘ํ•ฉ์„ ๊ตฌ๋ถ„ํ•˜๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์—ฐ๊ด€์–ด๋กœ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” co-occurrence ๊ฐ€ ๋†’์€ ๋‹จ์–ด๋ผ๋Š” ์˜๋ฏธ์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. co-occurrence ๊ฐ€ ๋†’์œผ๋ฉด์„œ๋„ ์„ค๋ช…๋ ฅ์ด ์ข‹์€ ๋‹จ์–ด๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

Setup

  • pip install soykeyword

Requires

  • Python >= 3.4 (not tested in Python 2)
  • numpy >= 1.12.1
  • scikit-learn >= 0.18
  • psutil >=5.0.1

Usage

Lasso Regerssion Keyword Extractor

ํ•™์Šต์€ sparse matrix x ๋ฅผ extractor ์— ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. index2word ๋Š” word idx ์— ๋Œ€ํ•œ ๋‹จ์–ด list ํ˜•์‹์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ train() ์— ์ž…๋ ฅํ•˜์ง€ ์•Š์œผ๋ฉด ํ‚ค์›Œ๋“œ์™€ ์—ฐ๊ด€์–ด๊ฐ€ ๋‹จ์–ด๊ฐ€ ์•„๋‹Œ word idx ๋กœ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

from soykeyword.lasso import LassoKeywordExtractor

lassobased_extractor = LassoKeywordExtractor(min_tf=20, min_df=10)
lassobased_extractor.train(x, index2word) # x: sparse matrix

ํ‚ค์›Œ๋“œ๋ฅผ ์ถ”์ถœํ•  ๋ฌธ์„œ ์ง‘ํ•ฉ documents ๋ฅผ extract_from_docs() ์— ์ž…๋ ฅํ•˜๋ฉด, ํ•ด๋‹น ๋ฌธ์„œ ์ง‘ํ•ฉ๊ณผ ๊ทธ ์™ธ์˜ ๋ฌธ์„œ ์ง‘ํ•ฉ์„ ๊ตฌ๋ถ„ํ•˜๋Š” keywords ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.

keywords = lassobased_extractor.extract_from_docs(
    documents, 
    min_num_of_keywords=30
)

์—ฐ๊ด€์–ด๋Š” extract_from_word ์— ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

lassobased_extractor.extract_from_word(
    '์•„์ด์˜ค์•„์ด',
    min_num_of_keywords=30
)

ํ•˜๋ฃจ ๋‰ด์Šค๋ฅผ ๊ธฐ์ค€์œผ๋กœ '์•„์ด์˜ค์•„์ด'์˜ ์—ฐ๊ด€์–ด๋ฅผ ์ถ”์ถœํ•œ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.

[KeywordScore(word='์•„์ด์˜ค์•„์ด', frequency=270, coefficient=17.850189941320671),
 KeywordScore(word='์— ์นด์šดํŠธ๋‹ค์šด', frequency=221, coefficient=1.200759338786378),
 KeywordScore(word='๋ฎค์ง', frequency=195, coefficient=1.081777863860977),
 KeywordScore(word='์ผ์‚ฐ๋™๊ตฌ', frequency=36, coefficient=0.98636875892070186),
 KeywordScore(word='ํ‚ค๋ฏธ', frequency=297, coefficient=0.70877507721215616),
 KeywordScore(word='์ฑ”ํ”ผ์–ธ', frequency=105, coefficient=0.51940928356916138),
 KeywordScore(word='๊ฐ•๋ ฌ', frequency=352, coefficient=0.36972563098092176),
 KeywordScore(word='์ปด๋ฐฑ', frequency=536, coefficient=0.30677481146665397),
 KeywordScore(word='ํ™”๋ ค', frequency=518, coefficient=0.26764304959838653),
 KeywordScore(word='์ˆ˜์ถœ', frequency=735, coefficient=0.23882691530127598),
 KeywordScore(word='๊ฑธ๊ทธ๋ฃน', frequency=1060, coefficient=0.20972098801573957),
 KeywordScore(word='๋ฐฉ์˜', frequency=208, coefficient=0.19694219657704334),
 KeywordScore(word='ํ”„๋กœ๋“€์Šค101', frequency=96, coefficient=0.17074232136595247),
 ...

์ž์„ธํ•œ ํŠœํ† ๋ฆฌ์–ผ์€ ๋งํฌ์— ์žˆ์Šต๋‹ˆ๋‹ค.

Proportion based Keyword Extractor

Proportion based ํ‚ค์›Œ๋“œ / ์—ฐ๊ด€์–ด ์ถ”์ถœ์€ ๋‘ ์ง‘ํ•ฉ์˜ ๋‹จ์–ด ์ถœ์—ฐ ํ™•๋ฅ ์˜ ๋น„์œจ์„ ๋ฐ”ํƒ•์œผ๋กœ ํ‚ค์›Œ๋“œ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค. P(w|pos) ๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์ถ”์ถœํ•  ๋ฌธ์„œ ์ง‘ํ•ฉ์—์„œ์˜ ๋‹จ์–ด w ์˜ ์ถœ์—ฐ ๋น„์œจ์ด๋ฉฐ, P(w|neg)๋Š” ๊ทธ ์™ธ์˜ ๋ฌธ์„œ ์ง‘ํ•ฉ์—์„œ์˜ ๋‹จ์–ด w์˜ ์ถœ์—ฐ ๋น„์œจ ์ž…๋‹ˆ๋‹ค.

score(w) = P(w|pos) / { P(w|pos) + P(w|neg) }

ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ ํ˜•ํƒœ๋Š” (sparse matrix, index2word) ํ˜น์€ ํ…์ŠคํŠธ ๋ฐ์ดํ„ฐ, ๋‘ ์ข…๋ฅ˜๋ฅผ ๋ชจ๋‘ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

ํ…์ŠคํŠธ ๋ฐ์ดํ„ฐ ํ˜•์‹์œผ๋กœ ํ•™์Šต์„ ํ•  ๊ฒฝ์šฐ์—๋Š” min_tf, min_df, tokenize ๋ฅผ ์„ค์ •ํ•ด์ค๋‹ˆ๋‹ค. ๋‹ค์Œ์˜ ์˜ˆ์‹œ๋Š” default value ์ž…๋‹ˆ๋‹ค.

from soykeyword.proportion import CorpusbasedKeywordExtractor
corpusbased_extractor = CorpusbasedKeywordExtractor(
    min_tf=20,
    min_df=2,
    tokenize=lambda x:x.strip().split(),
    verbose=True
)

# docs: list of str like
corpusbased_extractor.train(docs)

ํ‚ค์›Œ๋“œ๋ฅผ ์ถ”์ถœํ•  ๋ฌธ์„œ ์ง‘ํ•ฉ documents ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

keywords = corpusbased_extractor.extract_from_docs(
    documents,
    min_score=0.8,
    min_frequency=100
)

์—ฐ๊ด€์–ด๋ฅผ ์ถ”์ถœํ•  ๋‹จ์–ด word ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

keywords = corpusbased_extractor.extract_from_word(
    '์•„์ด์˜ค์•„์ด',
    min_score=0.8,
    min_frequency=100
)

ํ•˜๋ฃจ์˜ ๋‰ด์Šค๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ถ”์ถœํ•œ ์•„์ด์˜ค์•„์ด์˜ ์—ฐ๊ด€์–ด ์ž…๋‹ˆ๋‹ค.

keywords[:10]

[KeywordScore(word='์•„์ด์˜ค์•„์ด', frequency=270, score=1.0),
 KeywordScore(word='์— ์นด์šดํŠธ๋‹ค์šด', frequency=221, score=0.997897148491129),
 KeywordScore(word='ํŽœํƒ€๊ณค', frequency=104, score=0.9936420169665052),
 KeywordScore(word='์ž ๊น', frequency=162, score=0.9931809154109712),
 KeywordScore(word='์— ๋„ท', frequency=125, score=0.9910325251765126),
 KeywordScore(word='๊ฑธํฌ๋Ÿฌ์‰ฌ', frequency=111, score=0.9904705029926091),
 KeywordScore(word='ํƒ€์ดํ‹€๊ณก', frequency=311, score=0.987384461584851),
 KeywordScore(word='์ฝ”๋“œ', frequency=105, score=0.9871835929954923),
 KeywordScore(word='๋ณธ๋ช…', frequency=105, score=0.9863934667369743),
 KeywordScore(word='์—‘์Šค', frequency=101, score=0.9852544036088814)]

ํ•™์Šต๋ฐ์ดํ„ฐ์˜ ํ˜•ํƒœ๊ฐ€ (sparse matrix, index2word) ๋ผ๋ฉด MatrixbasedKeywordExtractor ๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

from soykeyword.proportion import MatrixbasedKeywordExtractor

matrixbased_extractor = MatrixbasedKeywordExtractor(
    min_tf=20,
    min_df=2,
    verbose=True
)

matrixbased_extractor.train(x, index2word)

์ž์„ธํ•œ ํŠœํ† ๋ฆฌ์–ผ์€ ๋งํฌ์— ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•จ๊ป˜ ์ด์šฉํ•˜๋ฉด ์ข‹์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค

soynlp

ํ•œ๊ตญ์–ด ์ž์—ฐ์–ด์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ๋ฏธ๋“ฑ๋ก๋‹จ์–ด ๋ฌธ์ œ ํ•ด๊ฒฐ์„ ์œ„ํ•œ ๋‹จ์–ด ์ถ”์ถœ / ๋‹จ์–ด ์ถ”์ถœ๊ธฐ์˜ ํ•™์Šต ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•˜๋Š” ํ† ํฌ๋‚˜์ด์ € / ํ’ˆ์‚ฌ ํŒ๋ณ„ / ์ •๊ทœํ™” ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

KoNLPy

KoNLPy ๋Š” ํ•œ๊ตญ์–ด ์ •๋ณด์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ ํŒจํ‚ค์ง€์ž…๋‹ˆ๋‹ค. ํ•œ๋‚˜๋ˆ”, ๊ผฌ๊ผฌ๋งˆ, ์ฝ”๋ชจ๋ž€, MeCab-ko, ํŠธ์œ„ํ„ฐ ํ•œ๊ตญ์–ด ๋ถ„์„๊ธฐ๋ฅผ ํŒŒ์ด์ฌ ํ™˜๊ฒฝ์—์„œ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • http://konlpy.org
  • KoNLPy ๋Š” Java๋ฅผ ์ด์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— Java ์™€ JPype ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ํ™ˆํŽ˜์ด์ง€์˜ ์„ค์น˜๋ฒ•์„ ๋ฐ˜๋“œ์‹œ ๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

customized KoNLPy

KoNLPy ์— ๋“ฑ๋ก๋˜์ง€ ์•Š์€ ๋‹จ์–ด๋ฅผ ์†์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ํ…œํ”Œ๋ฆฟ๊ณผ ์‚ฌ์ „ ๊ธฐ๋ฐ˜ string match ๋ฅผ KoNLPy ์™€ ํ•จ๊ป˜ ์ด์šฉํ•˜๋Š” wrapping ํŒŒ์ด์ฌ ํŒจํ‚ค์ง€์ž…๋‹ˆ๋‹ค.

soyspacing

๋„์–ด์“ฐ๊ธฐ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ์ด๋ฅผ ์ œ๊ฑฐํ•˜๋ฉด ํ…์ŠคํŠธ ๋ถ„์„์ด ์‰ฌ์›Œ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ถ„์„ํ•˜๋ ค๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋„์–ด์“ฐ๊ธฐ ์—”์ง„์„ ํ•™์Šตํ•˜๊ณ , ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ๋„์–ด์“ฐ๊ธฐ ์˜ค๋ฅ˜๋ฅผ ๊ต์ •ํ•ฉ๋‹ˆ๋‹ค.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc