add topics
Browse files
app.py
CHANGED
@@ -63,15 +63,11 @@ stopword = stopword + context # add some frequent words in the documents
|
|
63 |
clean_text = df_clean['description'].apply(lambda x: clean_up1(x, stopword, pos))
|
64 |
docs = clean_text.apply(lambda x: " ".join(x)).tolist()
|
65 |
|
66 |
-
topic_model = BERTopic(
|
67 |
-
nr_topics=6,
|
68 |
-
top_n_words=30,
|
69 |
-
low_memory=True,
|
70 |
-
n_gram_range=(1, 2))
|
71 |
|
72 |
-
topics,
|
|
|
73 |
|
74 |
-
topic_fig = topic_model.visualize_barchart(n_words=10)
|
75 |
|
76 |
timestamps = df_clean.index
|
77 |
topics_over_time = topic_model.topics_over_time(docs, topics, timestamps,
|
@@ -86,6 +82,8 @@ topics_over_time.set_index('Timestamp', inplace=True)
|
|
86 |
topics_over_time['year'] = topics_over_time.index.year
|
87 |
topic_per_year = topics_over_time.groupby(['year'])['Words'].apply(lambda x: x.str.cat(sep=' '))
|
88 |
|
|
|
|
|
89 |
fig1, ax = plt.subplots()
|
90 |
sns.countplot(ax=ax, x='year', data=df_clean, palette='viridis');
|
91 |
|
|
|
63 |
clean_text = df_clean['description'].apply(lambda x: clean_up1(x, stopword, pos))
|
64 |
docs = clean_text.apply(lambda x: " ".join(x)).tolist()
|
65 |
|
66 |
+
topic_model = BERTopic.load("bertopic")
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
with open('topics', 'rb') as f:
|
69 |
+
topics = pickle.load(f)
|
70 |
|
|
|
71 |
|
72 |
timestamps = df_clean.index
|
73 |
topics_over_time = topic_model.topics_over_time(docs, topics, timestamps,
|
|
|
82 |
topics_over_time['year'] = topics_over_time.index.year
|
83 |
topic_per_year = topics_over_time.groupby(['year'])['Words'].apply(lambda x: x.str.cat(sep=' '))
|
84 |
|
85 |
+
topic_fig = topic_model.visualize_barchart(n_words=10)
|
86 |
+
|
87 |
fig1, ax = plt.subplots()
|
88 |
sns.countplot(ax=ax, x='year', data=df_clean, palette='viridis');
|
89 |
|
topics
ADDED
Binary file (1.17 kB). View file
|
|