> ## Content Index
> Fetch the complete content index at: https://bongholee.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# [Python] Top2Vec WordCloud 한글 깨짐 해결하기(임시방편)
- URL: https://bongholee.com/python-top2vec-wordcloud-hangeul-ggaejim-haegyeolhagi-imsibangpyeon/
- Published: 2022-04-22T14:40:55.000Z
- Updated: 2022-04-22T14:40:55.000Z
- Author: Bongho Lee
- Tags: Data, #Import 2026-11-22 06:32

Top2Vec 내재 Function 중 하나인 generate\_topic\_wordcloud를 실행했는데 한글이 모두 깨져나온다.

출력물의 형태를 보니, 대략 Wordcloud 패키지를 쓰지 않았을까 생각되어 [Top2Vec](https://github.com/ddangelov/Top2Vec/blob/master/top2vec/Top2Vec.py?ref=bongholee.com)의 github를 보니 Wordcloud Package를 쓰고 있길래 별도 Function으로 분리시켜스 "font\_path"부분에 Font를 넣어주고, Top2Vec Class에서 별도로 분리가 되었기 때문에 self를 모두 제거하고 model을 넘겨주는 식으로 우선은 급하게 해결해서 사용하였다.

```
from wordcloud import WordCloud
from scipy.special import softmax

def generate_topic_wordcloud(model,topic_num, background_color="black"):
        word_score_dict = dict(zip(model.topic_words[topic_num], softmax(model.topic_word_scores[topic_num])))
        plt.figure(figsize=(16, 4),dpi=200)
        plt.axis("off")
        plt.imshow(
            WordCloud(font_path='NanumGothicCoding', width=1600,
                      height=400,
                      background_color=background_color).generate_from_frequencies(word_score_dict))
        plt.title("Topic " + str(topic_num), loc='left', fontsize=25, pad=20)
```

실행해보니 다음과 같이 한글이 잘 나온다.

![](https://bongholee.com/content/images/size/w2400/2022/04/image.png)

Image by author

해당코드가 임시방편인 이유는 두 가지 기능을 미구현했기 때문이다. 첫번째는 1) "reduction" Parameter에 대한 대응 부분과 2)토픽 갯수 Validation 부분이다. 코드로 보면 다음 부분이다.

```
 if reduced:
            self._validate_hierarchical_reduction()
            self._validate_topic_num(topic_num, reduced)
            word_score_dict = dict(zip(self.topic_words_reduced[topic_num],
                                       softmax(self.topic_word_scores_reduced[topic_num])))
        else:
            self._validate_topic_num(topic_num, reduced)
            word_score_dict = dict(zip(self.topic_words[topic_num],
                                       softmax(self.topic_word_scores[topic_num])))
```