In order to create a substring graph, you must enter the minimum frequency of substring and the max length of substring.
from krwordrank . word import KRWordRank
min_count = 5 # 단어의 최소 출현 빈도수 (그래프 생성 시)
max_length = 10 # 단어의 최대 길이
wordrank_extractor = KRWordRank ( min_count = min_count , max_length = max_length )KR-Wordrank extracts words using a graph Ranking algorithm similar to Pagerank (Hits Algorithm). The parameters of the Graph Ranking algorithm must be entered to calculate the Node (Substrig) ranking in the substring graph.
beta = 0.85 # PageRank의 decaying factor beta
max_iter = 10
texts = [ '예시 문장 입니다' , '여러 문장의 list of str 입니다' , ... ]
keywords , rank , graph = wordrank_extractor . extract ( texts , beta , max_iter )Graph Ranking Nodes (Substrings) are output as words through post -processing. As a result of extracting keywords from the movie 'La La Land' in the movie 'La Land', Tutorials is an example.
for word , r in sorted ( keywords . items (), key = lambda x : x [ 1 ], reverse = True )[: 30 ]:
print ( '%8s: t %.4f' % ( word , r )) 영화: 229.7889
관람객: 112.3404
너무: 78.4055
음악: 37.6247
정말: 37.2504
....
Python's WordCloud Package allows you to draw the word Cloud Figure on keywords.
Remove the common words (Stopwords) that will not be shown in the Figure to create passwords. It must be {word: score} in Dict format.
stopwords = { '영화' , '관람객' , '너무' , '정말' , '보고' }
passwords = { word : score for word , score in sorted (
keywords . items (), key = lambda x : - x [ 1 ])[: 300 ] if not ( word in stopwords )}Or you can simply proceed to the above process with a Summarize_with_Keywords function.
from krwordrank . word import summarize_with_keywords
keywords = summarize_with_keywords ( texts , min_count = 5 , max_length = 10 ,
beta = 0.85 , max_iter = 10 , stopwords = stopwords , verbose = True )
keywords = summarize_with_keywords ( texts ) # with default argumentsInstallation of WordCloud can be installed with the following command.
pip install wordcloud
WordCloud's default fonts are not supported by Korean. Find your font that supports Hangul and prepare font_path. After specifying the size of the picture (width, height) and background (background_color), etc.
from wordcloud import WordCloud
# Set your font path
font_path = 'YOUR_FONT_DIR/truetype/nanum/NanumBarunGothic.ttf'
krwordrank_cloud = WordCloud (
font_path = font_path ,
width = 800 ,
height = 800 ,
background_color = "white"
)
krwordrank_cloud = krwordrank_cloud . generate_from_frequencies ( passwords )When drawing in Jupyter Notebook, you must enter %matplotlib inline as shown below. If you make a .py file, you do not enter it.
% matplotlib inline
import matplotlib . pyplot as plt
fig = plt . figure ( figsize = ( 10 , 10 ))
plt . imshow ( krwordrank_cloud , interpolation = "bilinear" )
plt . show ()You can save the drawn picture.
fig . savefig ( './lalaland_wordcloud.png' )The stored picture is as follows.

KEY SENTENCE EXTRACTION will start from KR-Wordrank> = 1.0.0 . Since KR-Wordrank has a Korean torque-age function, it is difficult to use the TextRank method using the similarity between sentences that are torque. Instead, KR-Wordrank selects a sentence that includes a lot of keywords as a key sentence. The principle of extracting the sentence is to create a keyword vector using the rank value of the extracted keyword, and then select a sentence similar to the keyword vector input from the cos -signed similarity basis.
If you enter texts in Summarize_With_sentences function, you can learn KR-Wordrank to select keywords and key sentences using them.
from krwordrank . sentence import summarize_with_sentences
texts = [] # 라라랜드 영화평
keywords , sents = summarize_with_sentences ( texts , num_keywords = 100 , num_keysents = 10 ) Keywords is stored in Dict {Str: Float} format with keywords of num_keywords learned from KR-Wordrank.
{'영화': 201.02402099523516,
'너무': 81.53699026386887,
'정말': 40.53709233921311,
'음악': 40.43446188536923,
'마지막': 38.598509495213484,
'뮤지컬': 23.198810378709844,
'최고': 21.810147306627464,
'사랑': 20.638511587426862,
'꿈을': 20.43744237599688,
'아름': 20.324710458174806,
'영상': 20.283994278960186,
'여운이': 19.471356929084546,
'진짜': 19.06433920013137,
'노래': 18.732801785265316,
...
}
SENTS includes num_sents core sentences in List of Stro.
['여운이 크게남는영화 엠마스톤 너무 사랑스럽고 라이언고슬링 남자가봐도 정말 매력적인 배우인듯 영상미 음악 연기 구성 전부 좋았고 마지막 엔딩까지 신선하면서 애틋하구요 30중반에 감정이 많이 메말라있었는데 오랜만에 가슴이 촉촉해지네요',
'영상미도 너무 아름답고 신나는 음악도 좋았다 마지막 세바스찬과 미아의 눈빛교환은 정말 마음 아팠음 영화관에 고딩들이 엄청 많던데 고딩들은 영화 내용 이해를 못하더라ㅡㅡ사랑을 깊게 해본 사람이라면 누구나 느껴볼수있는 먹먹함이 있다',
'정말 영상미랑 음악은 최고였다 그리고 신선했다 음악이 너무 멋있어서 연기를 봐야 할지 노래를 들어야 할지 모를 정도로 그리고 보고 나서 생각 좀 많아진 영화 정말 이 연말에 보기 좋은 영화 인 것 같다',
'무언의 마지막 피아노연주 완전 슬픔ㅠ보는이들에게 꿈을 상기시켜줄듯 또 보고 싶은 내생에 최고의 뮤지컬영화였음 단순할수 있는 내용에 뮤지컬을 가미시켜째즈음악과 춤으로 지루할틈없이 빠져서봄 ost너무좋았음',
'처음엔 초딩들 보는 그냥 그런영화인줄 알았는데 정말로 눈과 귀가 즐거운 영화였습니다 어찌보면 뻔한 스토리일지 몰라도 그냥 보고 듣는게 즐거운 그러다가 정말 마지막엔 너무 아름답고 슬픈 음악이 되어버린',
'정말 멋진 노래와 음악과 영상미까지 정말 너무 멋있는 영화 눈물을 흘리면서 봤습니다 영화가 끝난 순간 감탄과 동시에 여운이 길게 남아 또 눈물을 흘렸던내 인생 최고의 뮤지컬 영화',
'평소 뮤지컬 영화 좋아하는 편인데도 평점에 비해 너무나 별로였던 영화 재즈음악이나 영상미 같은 건 좋았지만 줄거리도 글쎄 결말은 정말 별로 6 7점 정도 주는게 맞다고 생각하지만 개인적으로 후반부가 너무 별로여서',
'오랜만에 좋은 영화봤다는 생각들었구요 음악도 영상도 스토리도 너무나좋았고 무엇보다 진한 여운이 남는 영화는 정말 오랜만이었어요 연인끼리 가서 보기 정말 좋은영화 너뮤너뮤너뮤 재밌게 잘 봤습니다',
'음악 미술 연기 등 모든 것이 좋았지만 마지막 결말이 너무 현실에 뒤떨어진 꿈만 같다 꿈을 이야기하는 영화지만 과정과 결과에 있어 예술가들의 현실을 너무 반영하지 못한 것이 아닌가하는 생각이든다 그래서 보고 난 뒤 나는 꿈을 꿔야하는데 허탈했다',
'마지막 회상씬의 감동이 잊혀지질않는다마지막 십분만으로 티켓값이 아깝지않은 영화 음악들도 너무 아름다웠다옛날 뮤지컬 같은 빈티지영상미도 최고']
You can add some parameters. Define the PenALTY function to remove too long or short sentences. Below means that you prefer sentences with 25 letters to 80 letters. Stopwords are removed from the keyword. These are not used to create a keyword vector. In addition, if you choose a sentence similar to the keyword vector, you may choose the sentences that are previously selected as the previously selected sentences. This can be adjusted using diversity . diversity is the minimum distance between core sentences based on coconus similarity. The larger this value, the more various sentences are selected.
penalty = lambda x : 0 if ( 25 <= len ( x ) <= 80 ) else 1
stopwords = { '영화' , '관람객' , '너무' , '정말' , '진짜' }
keywords , sents = summarize_with_sentences (
texts ,
penalty = penalty ,
stopwords = stopwords ,
diversity = 0.5 ,
num_keywords = 100 ,
num_keysents = 10 ,
verbose = False
) The extracted keywords were removed from 영화 , 관람객 , and 너무 much STOPWORDS.
{'음악': 40.43446188536923,
'마지막': 38.598509495213484,
'뮤지컬': 23.198810378709844,
'최고': 21.810147306627464,
'사랑': 20.638511587426862,
'꿈을': 20.43744237599688,
'아름': 20.324710458174806,
'영상': 20.283994278960186,
'여운이': 19.471356929084546,
'노래': 18.732801785265316,
...
}
Core sentences also prefer sentences with 25 to 80 letters.
['최고라는 말밖엔 음악 연출 영상 스토리 모두완벽 마지막 10분잊을수없다 한편의 뮤지컬을본듯한 느낌인생영화',
'기대했었는데 저한텐 스토리도 음악도 평범했어요 영화보는내내 지루하다는 느낌을 많이 받았는데 신기하게도 마지막 씬을 보고나니 여운이 남네요',
'슬펐지만 아름다웠던 두사람의 사랑과 갈등 그리고 음악 마지막 오버랩은 그냥 할말을 잃었습니다 여운이 남는 영화',
'마지막 회상신에서 눈물이 왈칵 쏟아질뻔했다 올해중 최고의 영화를 본거 같다음악이며 배우들이며 영상이며 다시 또 보고싶은 그런 영화이다',
'예쁜 영상과 아름다운 음악 꿈을 쫒는 두사람의 선택이 달랐다면 어땠을까 상상하는 장면이 인상깊었다 쓸쓸하지만 현실적인 사랑이랄까',
'음악도 좋고 미아와 세바스티안의 아름다운 사랑과 예술에 대한 열정이 감동적이었습니다 재즈음악을 사랑하고 뮤지컬을 좋아하는 사람들에게 강추합니다',
'생각보다 굉장히 재미있는 뻔한 결말도 아니고 아름다운 음악과 현실적인 스토리구성 모두에게 와닿을법한 울림들이 차 좋았어요 추천',
'최고입니다 마지막 장면을 위해 음악과 함께 달려왔고현실적이지만 모두의 가슴을 뭉클하게 만드는 멋진 결말입니다 노래가 머리속에서 떠나질않네요',
'먼저 음악이 너무 좋고아름다운 영상미만으로도 최고네요 아름답지만 짠내도 나구요 별 생각없이 봤는데 강추입니다 영화보고 계속 음악이 귀에 맴돌아요',
'초반에 좀 지루하나 음악도 좋고 영상도 좋아서 보는 맛이 있어요 마지막이 좋았어요']
If you want to remove the sentence with the word 마지막 , you can change penalty function as shown below.
penalty = lambda x : 0 if ( 25 <= len ( x ) <= 80 and not '마지막' in x ) else 1 ,
keywords , sents = summarize_with_sentences (
texts ,
penalty = penalty ,
stopwords = stopwords ,
diversity = 0.5 ,
num_keywords = 100 ,
num_keysents = 10 ,
verbose = False
)
print ( sents ) ['예쁜 영상과 아름다운 음악 꿈을 쫒는 두사람의 선택이 달랐다면 어땠을까 상상하는 장면이 인상깊었다 쓸쓸하지만 현실적인 사랑이랄까',
'음악도 좋고 미아와 세바스티안의 아름다운 사랑과 예술에 대한 열정이 감동적이었습니다 재즈음악을 사랑하고 뮤지컬을 좋아하는 사람들에게 강추합니다',
'생각보다 굉장히 재미있는 뻔한 결말도 아니고 아름다운 음악과 현실적인 스토리구성 모두에게 와닿을법한 울림들이 차 좋았어요 추천',
'먼저 음악이 너무 좋고아름다운 영상미만으로도 최고네요 아름답지만 짠내도 나구요 별 생각없이 봤는데 강추입니다 영화보고 계속 음악이 귀에 맴돌아요',
'사랑 꿈 현실 모든걸 다시한번 생각하게 하는 영화였어요 영상미도 너무 예쁘고 주인공도 예쁘고 내용도 아름답네요ㅠㅠ 인생 영화',
'너무 좋은 영화 스토리는 비숫한것같아요 그래도 음악 영상 이루어지지않는 사랑을 더 매력적으로 전달한영화인것같아요 보고나서도 여운이 남는',
'노래도 좋고 영상미도 좋고 그리고 배우들 연기까지 정말 좋았어요 개인적으로 뮤지컬 형식 영화를 안좋아하는 편인데 재밌게 봤습니다',
'16년 최고의영화 인생영화입니다 영상미 색감 음악 감정선 다좋았는데 엔딩이 참현실적이네요 ㅎㅎ 참 공감되고 감동받았습니다 씁쓸하니 정말잘봤어요',
'사실 두번째 보는 영화입니다 영상 편집과 음악이 너무 좋아요 어떻게 보면 너무나 현실적일 수 있는 결말이 슬프기하지만 아름답습니다',
'영화사에 남을 최고의 뮤지컬영화입니다 음악과 영상이 너무 아름답고 두 주연배우의 연기는 매우 감동적입니다 무조건 보세요 최고']
For more details, please refer to the KRWORDRANK_KEYSENCE.IPYNB file in the Tutorials folder for more details Extraction Tutorials.
pip install krwordrank
Tested in