6️⃣Topic Modeling: BERTopic

Topic Modeling: BERTopic

토픽 모델링은 텍스트 내에서 추상적인 토픽을 발견하는 데 초점을 맞춘 NLP의 하위 분야입니다. 주요 목표는 대규모 텍스트 코퍼스에서 숨겨진 주제 구조를 발견하여 비정형 텍스트의 대규모 데이터 세트를 더 쉽게 이해하고 정리하는 것입니다.

  • 문서에 존재하는 토픽을 식별함으로써 토픽 모델링을 사용해 유사한 문서를 분류하거나 클러스터링할 수 있습니다.

  • 검색 엔진은 토픽 분포를 기반으로 문서를 색인화하여 이를 활용할 수 있습니다.

  • 또한 토픽을 기반으로 유사한 기사나 논문을 추천하는 데 사용할 수 있습니다.

BERTopic

BERTopic은 BERT 임베딩과 클래스 기반 TF-IDF를 활용하여 밀도가 높은 클러스터를 생성하는 토픽 모델링 기법으로, 토픽 설명에서 중요한 단어를 유지하면서 쉽게 해석할 수 있는 토픽을 생성할 수 있습니다.

최첨단 언어 모델과 새로운 알고리즘 접근 방식을 사용함으로써 기존의 토픽 모델링 접근 방식과 차별화됩니다.

%pip install bertopic

Dataset

!mkdir dataset
!wget https://github.com/sharmaroshan/Twitter-Sentiment-Analysis/raw/master/train_tweet.csv -O ./dataset/tokyo_2020_tweets.csv
--2024-05-19 08:57:58--  https://github.com/sharmaroshan/Twitter-Sentiment-Analysis/raw/master/train_tweet.csv
Resolving github.com (github.com)... 20.200.245.247
Connecting to github.com (github.com)|20.200.245.247|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/sharmaroshan/Twitter-Sentiment-Analysis/master/train_tweet.csv [following]
--2024-05-19 08:57:59--  https://raw.githubusercontent.com/sharmaroshan/Twitter-Sentiment-Analysis/master/train_tweet.csv
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3103165 (3.0M) [text/plain]
Saving to: ‘./dataset/tokyo_2020_tweets.csv’

./dataset/tokyo_202 100%[===================>]   2.96M  --.-KB/s    in 0.03s   

2024-05-19 08:58:00 (103 MB/s) - ‘./dataset/tokyo_2020_tweets.csv’ saved [3103165/3103165]
id
label
tweet

0

1

0

@user when a father is dysfunctional and is s...

1

2

0

@user @user thanks for #lyft credit i can't us...

2

3

0

bihday your majesty

3

4

0

#model i love u take with u all the time in ...

4

5

0

factsguide: society now #motivation

Return Result

Topic
Count

1

-1

4119

27

0

346

9

1

303

10

2

198

11

3

166

14

4

155

29

5

144

35

6

142

2

7

131

13

8

125

Visualization

Topic Frequnt Count

Topic
Count

0

0

5517

1

-1

4226

2

1

206

4

2

28

3

3

23

Model Save & Load

Using Huggingface

Topic
Count
Name
CustomName
Representation
Representative_Docs

0

10

408

10_communism_capitalism_marx_economic

10_communism_capitalism_marx_economic

[communism, capitalism, marx, economic, econom...

NaN

Last updated