BobXWu / FASTopic

A Fast, Adaptive, Stable, and Transferable Topic Model
https://pypi.org/project/fastopic/
Apache License 2.0
20 stars 2 forks source link

loss value can not decline #3

Closed xing393939 closed 1 week ago

xing393939 commented 3 weeks ago

here is my code:

# my txt are already split by blank space
preprocessing = Preprocessing(tokenizer=lambda txt: txt.split())
topic_model = FASTopic(num_topics=45, preprocessing=preprocessing, verbose=True,
                       doc_embed_model='BAAI/bge-small-zh-v1.5')
topic_model.fit_transform(docs)

here is my output:

2024-06-27 16:17:52,072 - FASTopic - use device: cpu
loading train texts: 100%|██████████| 1000/1000 [00:00<00:00, 200033.57it/s]
parsing texts: 100%|██████████| 1000/1000 [00:00<00:00, 500274.81it/s]
2024-06-27 16:17:52,095 - TopMost - Real vocab size: 1156
2024-06-27 16:17:52,096 - TopMost - Real training size: 1000     avg length: 4.925
Batches: 100%|██████████| 32/32 [00:07<00:00,  4.20it/s]
Training FASTopic:   4%|▍         | 9/200 [00:14<05:09,  1.62s/it]2024-06-27 16:18:46,098 - FASTopic - Epoch: 010 loss: 137.063
Training FASTopic:  10%|▉         | 19/200 [00:30<04:55,  1.63s/it]2024-06-27 16:19:02,858 - FASTopic - Epoch: 020 loss: 136.495
Training FASTopic:  14%|█▍        | 29/200 [00:48<04:43,  1.66s/it]2024-06-27 16:19:19,640 - FASTopic - Epoch: 030 loss: 136.246
Training FASTopic:  20%|█▉        | 39/200 [01:04<04:22,  1.63s/it]2024-06-27 16:19:36,178 - FASTopic - Epoch: 040 loss: 136.145
Training FASTopic:  24%|██▍       | 49/200 [01:20<04:03,  1.61s/it]2024-06-27 16:19:52,462 - FASTopic - Epoch: 050 loss: 136.106
Training FASTopic:  30%|██▉       | 59/200 [01:38<03:59,  1.70s/it]2024-06-27 16:20:09,813 - FASTopic - Epoch: 060 loss: 136.092
Training FASTopic:  34%|███▍      | 69/200 [01:55<03:45,  1.72s/it]2024-06-27 16:20:26,986 - FASTopic - Epoch: 070 loss: 136.086
Training FASTopic:  40%|███▉      | 79/200 [02:11<03:13,  1.60s/it]2024-06-27 16:20:42,949 - FASTopic - Epoch: 080 loss: 136.084
Training FASTopic:  44%|████▍     | 89/200 [02:28<03:17,  1.78s/it]2024-06-27 16:20:59,958 - FASTopic - Epoch: 090 loss: 136.083
Training FASTopic:  50%|████▉     | 99/200 [02:45<02:57,  1.76s/it]2024-06-27 16:21:17,387 - FASTopic - Epoch: 100 loss: 136.083
Training FASTopic:  55%|█████▍    | 109/200 [03:01<02:25,  1.60s/it]2024-06-27 16:21:33,652 - FASTopic - Epoch: 110 loss: 136.083
Training FASTopic:  60%|█████▉    | 119/200 [03:18<02:13,  1.64s/it]2024-06-27 16:21:49,979 - FASTopic - Epoch: 120 loss: 136.083
Training FASTopic:  64%|██████▍   | 129/200 [03:35<01:56,  1.64s/it]2024-06-27 16:22:06,523 - FASTopic - Epoch: 130 loss: 136.083
Training FASTopic:  70%|██████▉   | 139/200 [03:51<01:39,  1.62s/it]2024-06-27 16:22:22,760 - FASTopic - Epoch: 140 loss: 136.083
Training FASTopic:  74%|███████▍  | 149/200 [04:07<01:20,  1.57s/it]2024-06-27 16:22:38,584 - FASTopic - Epoch: 150 loss: 136.083
Training FASTopic:  80%|███████▉  | 159/200 [04:23<01:06,  1.63s/it]2024-06-27 16:22:54,644 - FASTopic - Epoch: 160 loss: 136.083
Training FASTopic:  84%|████████▍ | 169/200 [04:39<00:52,  1.69s/it]2024-06-27 16:23:11,429 - FASTopic - Epoch: 170 loss: 136.083
Training FASTopic:  90%|████████▉ | 179/200 [04:56<00:35,  1.70s/it]2024-06-27 16:23:28,525 - FASTopic - Epoch: 180 loss: 136.083
Training FASTopic:  94%|█████████▍| 189/200 [05:13<00:18,  1.68s/it]2024-06-27 16:23:45,433 - FASTopic - Epoch: 190 loss: 136.083
Training FASTopic: 100%|█████████▉| 199/200 [05:30<00:01,  1.63s/it]2024-06-27 16:24:02,273 - FASTopic - Epoch: 200 loss: 136.083
Training FASTopic: 100%|██████████| 200/200 [05:32<00:00,  1.66s/it]
Topic 0: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 1: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 2: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 3: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 4: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 5: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 6: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 7: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 8: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 9: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 10: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 11: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 12: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 13: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 14: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 15: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 16: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 17: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 18: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 19: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 20: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 21: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 22: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 23: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 24: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 25: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 26: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 27: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 28: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 29: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 30: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 31: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 32: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 33: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 34: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 35: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 36: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 37: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 38: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 39: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 40: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 41: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 42: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 43: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言
Topic 44: 游戏 中篇 世界 人才学 人物 识图法 1885 管道 利用 素质教育 美容 输入 中山市 自然 C语言

as it shows, loss value can not decline, and all the topics are the same, what should i do?

BobXWu commented 3 weeks ago

Hi, Can you share your dataset and complete code? So I can look into the reason.

BobXWu commented 3 weeks ago

I guess this is because the docs in your dataset are too short (avg length: 4.925), so the doc embedding model cannot produce discriminative doc embeddings. Maybe you can try to increase DT_alpha as FASTopic(DT_alpha=10.0) or FASTopic(DT_alpha=15.0).

xing393939 commented 3 weeks ago

metadata_book_cip_1k.patch

Thanks for your attention, above is my dataset, my complete code is here (with the DT_alpha is 15):

from fastopic import FASTopic
from topmost.preprocessing import Preprocessing
import pandas as pd

def fast_topic_model(docs, num_topics):
    preprocessing = Preprocessing(tokenizer=lambda txt: txt.split())
    topic_model = FASTopic(num_topics=num_topics, preprocessing=preprocessing, verbose=True,
                           doc_embed_model='BAAI/bge-small-zh-v1.5', DT_alpha=15, device='cpu')
    topics, probs = topic_model.fit_transform(docs)
    return [topics, probs, topic_model]

if __name__ == '__main__':
    name = "metadata_book_cip_1k"
    cache_file = f'./{name}.patch'
    train = pd.read_pickle(cache_file)
    t_docs = [" ".join(row) for row in train]
    fast_topic_model(t_docs, 45)

and the newest result is here:

2024-06-28 08:50:22,524 - FASTopic - use device: cpu
loading train texts: 100%|██████████| 1000/1000 [00:00<00:00, 249973.42it/s]
parsing texts: 100%|██████████| 1000/1000 [00:00<00:00, 500095.86it/s]
2024-06-28 08:50:22,548 - TopMost - Real vocab size: 1156
2024-06-28 08:50:22,550 - TopMost - Real training size: 1000     avg length: 4.925
No sentence-transformers model found with name BAAI/bge-small-zh-v1.5. Creating a new one with MEAN pooling.
Batches: 100%|██████████| 32/32 [00:04<00:00,  7.23it/s]
Training FASTopic:   4%|▍         | 9/200 [00:18<06:25,  2.02s/it]2024-06-28 08:51:17,953 - FASTopic - Epoch: 010 loss: 137.064
Training FASTopic:  10%|▉         | 19/200 [00:39<06:27,  2.14s/it]2024-06-28 08:51:38,946 - FASTopic - Epoch: 020 loss: 136.497
Training FASTopic:  14%|█▍        | 29/200 [01:00<06:01,  2.11s/it]2024-06-28 08:52:00,179 - FASTopic - Epoch: 030 loss: 136.248
Training FASTopic:  20%|█▉        | 39/200 [01:22<06:05,  2.27s/it]2024-06-28 08:52:21,943 - FASTopic - Epoch: 040 loss: 136.146
Training FASTopic:  24%|██▍       | 49/200 [01:44<05:30,  2.19s/it]2024-06-28 08:52:44,295 - FASTopic - Epoch: 050 loss: 136.107
Training FASTopic:  30%|██▉       | 59/200 [02:04<04:49,  2.06s/it]2024-06-28 08:53:04,710 - FASTopic - Epoch: 060 loss: 136.092
Training FASTopic:  34%|███▍      | 69/200 [02:25<04:27,  2.04s/it]2024-06-28 08:53:25,465 - FASTopic - Epoch: 070 loss: 136.087
Training FASTopic:  40%|███▉      | 79/200 [02:45<04:07,  2.05s/it]2024-06-28 08:53:45,585 - FASTopic - Epoch: 080 loss: 136.084
Training FASTopic:  44%|████▍     | 89/200 [03:06<03:46,  2.04s/it]2024-06-28 08:54:05,891 - FASTopic - Epoch: 090 loss: 136.083
Training FASTopic:  50%|████▉     | 99/200 [03:26<03:21,  1.99s/it]2024-06-28 08:54:26,324 - FASTopic - Epoch: 100 loss: 136.083
Training FASTopic:  55%|█████▍    | 109/200 [03:47<03:06,  2.05s/it]2024-06-28 08:54:46,967 - FASTopic - Epoch: 110 loss: 136.083
Training FASTopic:  60%|█████▉    | 119/200 [04:08<02:49,  2.09s/it]2024-06-28 08:55:07,893 - FASTopic - Epoch: 120 loss: 136.083
Training FASTopic:  64%|██████▍   | 129/200 [04:29<02:36,  2.20s/it]2024-06-28 08:55:28,890 - FASTopic - Epoch: 130 loss: 136.083
Training FASTopic:  70%|██████▉   | 139/200 [04:49<02:05,  2.05s/it]2024-06-28 08:55:49,681 - FASTopic - Epoch: 140 loss: 136.083
Training FASTopic:  74%|███████▍  | 149/200 [05:10<01:43,  2.03s/it]2024-06-28 08:56:10,413 - FASTopic - Epoch: 150 loss: 136.083
Training FASTopic:  80%|███████▉  | 159/200 [05:31<01:28,  2.16s/it]2024-06-28 08:56:31,784 - FASTopic - Epoch: 160 loss: 136.083
Training FASTopic:  84%|████████▍ | 169/200 [05:52<01:05,  2.11s/it]2024-06-28 08:56:52,682 - FASTopic - Epoch: 170 loss: 136.083
Training FASTopic:  90%|████████▉ | 179/200 [06:13<00:42,  2.00s/it]2024-06-28 08:57:13,405 - FASTopic - Epoch: 180 loss: 136.083
Training FASTopic:  94%|█████████▍| 189/200 [06:35<00:23,  2.16s/it]2024-06-28 08:57:34,952 - FASTopic - Epoch: 190 loss: 136.083
Training FASTopic: 100%|█████████▉| 199/200 [06:56<00:02,  2.11s/it]2024-06-28 08:57:56,415 - FASTopic - Epoch: 200 loss: 136.083
Training FASTopic: 100%|██████████| 200/200 [06:58<00:00,  2.09s/it]
Topic 0: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 1: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 2: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 3: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 4: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 5: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 6: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 7: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 8: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 9: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 10: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 11: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 12: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 13: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 14: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 15: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 16: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 17: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 18: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 19: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 20: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 21: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 22: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 23: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 24: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 25: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 26: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 27: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 28: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 29: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 30: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 31: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 32: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 33: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 34: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 35: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 36: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 37: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 38: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 39: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 40: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 41: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 42: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 43: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
Topic 44: 可持续 管理 电路 井冈山 Oracle 蛋白质 英文 飞机 改性沥青 计算机辅助设计 诊断学 妊娠期 推销 辅助 妇女
BobXWu commented 3 weeks ago

Hi, Please try to install the latest version of FASTopic: pip install --upgrade --force-reinstall fastopic. Then it works fine with your code and dataset.

xing393939 commented 3 weeks ago

no, it does not. here is the result:

2024-06-28 11:00:22,717 - FASTopic - use device: cpu
loading train texts: 100%|██████████| 1000/1000 [00:00<00:00, 249973.42it/s]
parsing texts: 100%|██████████| 1000/1000 [00:00<00:00, 500095.86it/s]
2024-06-28 11:00:22,744 - TopMost - Real vocab size: 1156
2024-06-28 11:00:22,746 - TopMost - Real training size: 1000     avg length: 4.925
No sentence-transformers model found with name BAAI/bge-small-zh-v1.5. Creating a new one with MEAN pooling.
Batches: 100%|██████████| 32/32 [00:04<00:00,  7.54it/s]
Training FASTopic:   4%|▍         | 9/200 [00:23<08:30,  2.67s/it]2024-06-28 11:01:25,160 - FASTopic - Epoch: 010 loss: 137.065
Training FASTopic:  10%|▉         | 19/200 [00:51<08:19,  2.76s/it]2024-06-28 11:01:52,660 - FASTopic - Epoch: 020 loss: 136.497
Training FASTopic:  14%|█▍        | 29/200 [01:17<07:38,  2.68s/it]2024-06-28 11:02:19,010 - FASTopic - Epoch: 030 loss: 136.248
Training FASTopic:  20%|█▉        | 39/200 [01:44<07:04,  2.64s/it]2024-06-28 11:02:45,694 - FASTopic - Epoch: 040 loss: 136.146
Training FASTopic:  24%|██▍       | 49/200 [02:10<06:28,  2.57s/it]2024-06-28 11:03:11,991 - FASTopic - Epoch: 050 loss: 136.107
Training FASTopic:  30%|██▉       | 59/200 [02:36<06:01,  2.56s/it]2024-06-28 11:03:37,697 - FASTopic - Epoch: 060 loss: 136.092
Training FASTopic:  34%|███▍      | 69/200 [03:02<05:32,  2.54s/it]2024-06-28 11:04:03,243 - FASTopic - Epoch: 070 loss: 136.086
Training FASTopic:  40%|███▉      | 79/200 [03:29<05:25,  2.69s/it]2024-06-28 11:04:30,253 - FASTopic - Epoch: 080 loss: 136.084
Training FASTopic:  44%|████▍     | 89/200 [03:58<05:38,  3.05s/it]2024-06-28 11:04:59,924 - FASTopic - Epoch: 090 loss: 136.083
Training FASTopic:  50%|████▉     | 99/200 [04:25<04:26,  2.63s/it]2024-06-28 11:05:27,107 - FASTopic - Epoch: 100 loss: 136.083
Training FASTopic:  55%|█████▍    | 109/200 [04:52<04:04,  2.68s/it]2024-06-28 11:05:53,730 - FASTopic - Epoch: 110 loss: 136.083
Training FASTopic:  60%|█████▉    | 119/200 [05:18<03:26,  2.55s/it]2024-06-28 11:06:19,429 - FASTopic - Epoch: 120 loss: 136.083
Training FASTopic:  64%|██████▍   | 129/200 [05:44<03:05,  2.61s/it]2024-06-28 11:06:45,439 - FASTopic - Epoch: 130 loss: 136.083
Training FASTopic:  70%|██████▉   | 139/200 [06:09<02:35,  2.56s/it]2024-06-28 11:07:10,889 - FASTopic - Epoch: 140 loss: 136.083
Training FASTopic:  74%|███████▍  | 149/200 [06:35<02:09,  2.53s/it]2024-06-28 11:07:36,580 - FASTopic - Epoch: 150 loss: 136.083
Training FASTopic:  80%|███████▉  | 159/200 [07:01<01:46,  2.59s/it]2024-06-28 11:08:02,173 - FASTopic - Epoch: 160 loss: 136.083
Training FASTopic:  84%|████████▍ | 169/200 [07:26<01:19,  2.58s/it]2024-06-28 11:08:27,884 - FASTopic - Epoch: 170 loss: 136.083
Training FASTopic:  90%|████████▉ | 179/200 [07:52<00:53,  2.57s/it]2024-06-28 11:08:53,607 - FASTopic - Epoch: 180 loss: 136.083
Training FASTopic:  94%|█████████▍| 189/200 [08:18<00:28,  2.56s/it]2024-06-28 11:09:20,031 - FASTopic - Epoch: 190 loss: 136.083
Training FASTopic: 100%|█████████▉| 199/200 [08:44<00:02,  2.61s/it]2024-06-28 11:09:45,592 - FASTopic - Epoch: 200 loss: 136.083
Training FASTopic: 100%|██████████| 200/200 [08:47<00:00,  2.64s/it]
Topic 0: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 1: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 2: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 3: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 4: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 5: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 6: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 7: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 8: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 9: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 10: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 11: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 12: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 13: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 14: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 15: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 16: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 17: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 18: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 19: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 20: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 21: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 22: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 23: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 24: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 25: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 26: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 27: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 28: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 29: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 30: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 31: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 32: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 33: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 34: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 35: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 36: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 37: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 38: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 39: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 40: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 41: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 42: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 43: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并
Topic 44: 预测 企业文化 经济改革 插值 管理 基本 国际贸易 物品 酿造 日本 金属 道德 处理 情报 合并

pip install --upgrade --force-reinstall fastopicdoes not upgrade the version of fastopic, but the dependencies:

Successfully installed MarkupSafe-2.1.5 Pillow-10.3.0 bertopic-0.16.2 certifi-2024.6.2 charset-normalizer-3.3.2 colorama-0.4.6 cython-0.29.37 fastopic-0.0.3 filelock-3.15.4 fsspec-2024.6.1 gensim-4.3
.2 hdbscan-0.8.37 huggingface-hub-0.23.4 idna-3.7 intel-openmp-2021.4.0 jinja2-3.1.4 joblib-1.4.2 llvmlite-0.43.0 mkl-2021.4.0 mpmath-1.3.0 networkx-3.3 numba-0.60.0 numpy-1.26.4 packaging-24.1 panda
s-2.2.2 plotly-5.22.0 pynndescent-0.5.13 python-dateutil-2.9.0.post0 pytz-2024.1 pyyaml-6.0.1 regex-2024.5.15 requests-2.32.3 safetensors-0.4.3 scikit-learn-1.5.0 scipy-1.10.1 sentence-transformers-2
.7.0 six-1.16.0 smart-open-7.0.4 sympy-1.12.1 tbb-2021.13.0 tenacity-8.4.2 threadpoolctl-3.5.0 tokenizers-0.19.1 topmost-0.0.4 torch-2.3.1 torchvision-0.18.1 tqdm-4.66.4 transformers-4.42.1 typing-ex
tensions-4.12.2 tzdata-2024.1 umap-learn-0.5.6 urllib3-2.2.2 wrapt-1.16.0

I wonder the reason is that I use the windows os, I worked fine in google colab.

BobXWu commented 3 weeks ago

Yes. I tried your code on Linux. I just also ran your code on Windows, and it worked correctly. You may check if your document embedding model is properly downloaded, because your log says No sentence-transformers model found with name BAAI/bge-small-zh-v1.5. Creating a new one with MEAN pooling.

xing393939 commented 3 weeks ago

That is the point, thank you! I found than it works well when I run it with the vpn opened.

BobXWu commented 3 weeks ago

We're glad it helps. It would be wonderful if you give us a github star!

GuishePerez commented 1 week ago

Reopening this thread as I've detected another case where the training loss gets stucked.

This one is related to the SentenceTransformer model used for encoding the training docs. Particularly, if the produced embeddings are not normalized. In that case, increasing the value of DT_alpha to the suggested ones has no effect.

from fastopic import FASTopic
import topmost
from topmost.data import download_dataset

# Download data and pre-process if required
dataset_name = "NYT"
download_dataset(dataset_name, cache_path="./datasets")
dataset = topmost.data.DynamicDataset("./datasets/NYT", as_tensor=False)
docs = dataset.train_texts
preprocessing = None

# Number of topics
K = 50

# Define doc embedding model
doc_embedder = "mixedbread-ai/mxbai-embed-large-v1"

# Instantiate model's object
model = FASTopic(
    K,
    preprocessing,
    doc_embed_model=doc_embedder,
    verbose=True,
)

# Train
topic_top_words, doc_topic_dist = model.fit_transform(docs)

The output is the following one, where you can see the training loss stucked across the epochs. Consequently, the final topics are composed by a repetition of random words:

Downloading https://raw.githubusercontent.com/BobXWu/TopMost/master/data/NYT.zip to ./datasets/NYT.zip
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 15070620/15070620 [00:00<00:00, 365760685.97it/s]
all train size:  8254
all test size:  918
all vocab size:  10000
average length: 175.429
num of each time slice:  11 [ 194  265  431  554  744  837  802  884 1283 1400  860]
2024-07-09 15:43:05,399 - FASTopic - use device: cuda
Training model from scratch
loading train texts: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 8254/8254 [00:02<00:00, 3898.37it/s]
parsing texts: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 8254/8254 [00:01<00:00, 4323.96it/s]
2024-07-09 15:43:11,618 - TopMost - Real vocab size: 10000
2024-07-09 15:43:11,656 - TopMost - Real training size: 8254     avg length: 175.429
Batches: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 258/258 [01:05<00:00,  3.93it/s]
Training FASTopic:   4%|████▋                                                                                                    | 9/200 [00:16<05:46,  1.82s/it]2024-07-09 15:44:38,850 - FASTopic - Epoch: 010 loss: 4848.005
Training FASTopic:  10%|█████████▉                                                                                              | 19/200 [00:34<05:30,  1.82s/it]2024-07-09 15:44:57,203 - FASTopic - Epoch: 020 loss: 4847.487
Training FASTopic:  14%|███████████████                                                                                         | 29/200 [00:53<05:14,  1.84s/it]2024-07-09 15:45:15,645 - FASTopic - Epoch: 030 loss: 4847.342
Training FASTopic:  20%|████████████████████▎                                                                                   | 39/200 [01:11<04:51,  1.81s/it]2024-07-09 15:45:33,762 - FASTopic - Epoch: 040 loss: 4847.304
Training FASTopic:  24%|█████████████████████████▍                                                                              | 49/200 [01:29<04:33,  1.81s/it]2024-07-09 15:45:51,771 - FASTopic - Epoch: 050 loss: 4847.293
Training FASTopic:  30%|██████████████████████████████▋                                                                         | 59/200 [01:47<04:25,  1.88s/it]2024-07-09 15:46:10,331 - FASTopic - Epoch: 060 loss: 4847.289
Training FASTopic:  34%|███████████████████████████████████▉                                                                    | 69/200 [02:06<03:59,  1.83s/it]2024-07-09 15:46:28,773 - FASTopic - Epoch: 070 loss: 4847.287
Training FASTopic:  40%|█████████████████████████████████████████                                                               | 79/200 [02:24<03:39,  1.81s/it]2024-07-09 15:46:46,718 - FASTopic - Epoch: 080 loss: 4847.286
Training FASTopic:  44%|██████████████████████████████████████████████▎                                                         | 89/200 [02:42<03:16,  1.77s/it]2024-07-09 15:47:04,580 - FASTopic - Epoch: 090 loss: 4847.286
Training FASTopic:  50%|███████████████████████████████████████████████████▍                                                    | 99/200 [02:59<02:57,  1.76s/it]2024-07-09 15:47:22,391 - FASTopic - Epoch: 100 loss: 4847.286
Training FASTopic:  55%|████████████████████████████████████████████████████████▏                                              | 109/200 [03:17<02:40,  1.77s/it]2024-07-09 15:47:40,110 - FASTopic - Epoch: 110 loss: 4847.286
Training FASTopic:  60%|█████████████████████████████████████████████████████████████▎                                         | 119/200 [03:35<02:24,  1.79s/it]2024-07-09 15:47:58,044 - FASTopic - Epoch: 120 loss: 4847.286
Training FASTopic:  64%|██████████████████████████████████████████████████████████████████▍                                    | 129/200 [03:53<02:06,  1.79s/it]2024-07-09 15:48:15,917 - FASTopic - Epoch: 130 loss: 4847.286
Training FASTopic:  70%|███████████████████████████████████████████████████████████████████████▌                               | 139/200 [04:11<01:48,  1.78s/it]2024-07-09 15:48:33,720 - FASTopic - Epoch: 140 loss: 4847.286
Training FASTopic:  74%|████████████████████████████████████████████████████████████████████████████▋                          | 149/200 [04:29<01:32,  1.82s/it]2024-07-09 15:48:51,803 - FASTopic - Epoch: 150 loss: 4847.286
Training FASTopic:  80%|█████████████████████████████████████████████████████████████████████████████████▉                     | 159/200 [04:47<01:14,  1.81s/it]2024-07-09 15:49:10,036 - FASTopic - Epoch: 160 loss: 4847.286
Training FASTopic:  84%|███████████████████████████████████████████████████████████████████████████████████████                | 169/200 [05:05<00:55,  1.80s/it]2024-07-09 15:49:27,985 - FASTopic - Epoch: 170 loss: 4847.286
Training FASTopic:  90%|████████████████████████████████████████████████████████████████████████████████████████████▏          | 179/200 [05:23<00:37,  1.80s/it]2024-07-09 15:49:46,100 - FASTopic - Epoch: 180 loss: 4847.286
Training FASTopic:  94%|█████████████████████████████████████████████████████████████████████████████████████████████████▎     | 189/200 [05:41<00:20,  1.83s/it]2024-07-09 15:50:04,234 - FASTopic - Epoch: 190 loss: 4847.286
Training FASTopic: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████▍| 199/200 [06:00<00:01,  1.84s/it]2024-07-09 15:50:22,437 - FASTopic - Epoch: 200 loss: 4847.286
Training FASTopic: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [06:01<00:00,  1.81s/it]
Topic 0: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 1: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 2: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 3: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 4: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 5: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 6: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 7: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 8: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 9: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 10: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 11: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 12: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 13: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 14: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 15: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 16: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 17: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 18: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 19: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 20: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 21: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 22: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 23: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 24: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 25: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 26: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 27: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 28: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 29: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 30: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 31: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 32: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 33: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 34: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 35: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 36: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 37: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 38: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 39: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 40: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 41: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 42: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 43: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 44: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 45: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 46: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 47: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 48: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired
Topic 49: safeguard consequence generational ambition brilliant military rebel circle outlining reached effectiveness looking trips wheeler aired

I've updated both fastopic and topmost libraries in order to get as input the argument normalize_embeddings which is the one used by sentence-transformers library, the one used in the class DocEmbedModel of topmost library.

Now if we repeat the experiment passing normalize_embeddings=True:

from fastopic import FASTopic
import topmost
from topmost.data import download_dataset

# Download data and pre-process if required
dataset_name = "NYT"
download_dataset(dataset_name, cache_path="./datasets")
dataset = topmost.data.DynamicDataset("./datasets/NYT", as_tensor=False)
docs = dataset.train_texts
preprocessing = None

# Number of topics
K = 50

# Define doc embedding model
doc_embedder = "mixedbread-ai/mxbai-embed-large-v1"

# Instantiate model's object
model = FASTopic(
    K,
    preprocessing,
    doc_embed_model=doc_embedder,
    normalize_embeddings=True,
    verbose=True,
)

# Train
topic_top_words, doc_topic_dist = model.fit_transform(docs)

The output now looks much better:

Downloading https://raw.githubusercontent.com/BobXWu/TopMost/master/data/NYT.zip to ./datasets/NYT.zip
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 15070620/15070620 [00:00<00:00, 479778077.79it/s]
all train size:  8254
all test size:  918
all vocab size:  10000
average length: 175.429
num of each time slice:  11 [ 194  265  431  554  744  837  802  884 1283 1400  860]
2024-07-09 15:55:32,861 - FASTopic - use device: cuda
Training model from scratch
loading train texts: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 8254/8254 [00:02<00:00, 3898.86it/s]
parsing texts: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 8254/8254 [00:01<00:00, 4312.00it/s]
2024-07-09 15:55:39,075 - TopMost - Real vocab size: 10000
2024-07-09 15:55:39,113 - TopMost - Real training size: 8254     avg length: 175.429
Batches: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 258/258 [01:05<00:00,  3.94it/s]
Training FASTopic:   4%|███▋                                                                                                     | 7/200 [00:00<00:09, 19.90it/s]2024-07-09 15:56:48,275 - FASTopic - Epoch: 010 loss: 1609.717
Training FASTopic:   9%|█████████▎                                                                                              | 18/200 [00:00<00:09, 18.27it/s]2024-07-09 15:56:48,854 - FASTopic - Epoch: 020 loss: 1573.869
Training FASTopic:  14%|██████████████▌                                                                                         | 28/200 [00:01<00:10, 16.34it/s]2024-07-09 15:56:49,483 - FASTopic - Epoch: 030 loss: 1539.161
Training FASTopic:  19%|███████████████████▊                                                                                    | 38/200 [00:02<00:11, 13.87it/s]2024-07-09 15:56:50,244 - FASTopic - Epoch: 040 loss: 1516.833
Training FASTopic:  24%|████████████████████████▉                                                                               | 48/200 [00:02<00:09, 15.70it/s]2024-07-09 15:56:50,864 - FASTopic - Epoch: 050 loss: 1500.015
Training FASTopic:  29%|██████████████████████████████▏                                                                         | 58/200 [00:03<00:09, 15.62it/s]2024-07-09 15:56:51,505 - FASTopic - Epoch: 060 loss: 1486.479
Training FASTopic:  34%|███████████████████████████████████▎                                                                    | 68/200 [00:04<00:11, 11.94it/s]2024-07-09 15:56:52,265 - FASTopic - Epoch: 070 loss: 1475.485
Training FASTopic:  39%|████████████████████████████████████████▌                                                               | 78/200 [00:05<00:08, 15.16it/s]2024-07-09 15:56:52,892 - FASTopic - Epoch: 080 loss: 1466.522
Training FASTopic:  44%|█████████████████████████████████████████████▊                                                          | 88/200 [00:05<00:06, 16.00it/s]2024-07-09 15:56:53,511 - FASTopic - Epoch: 090 loss: 1458.777
Training FASTopic:  49%|██████████████████████████████████████████████████▉                                                     | 98/200 [00:06<00:08, 12.05it/s]2024-07-09 15:56:54,269 - FASTopic - Epoch: 100 loss: 1451.944
Training FASTopic:  54%|███████████████████████████████████████████████████████▌                                               | 108/200 [00:07<00:05, 15.35it/s]2024-07-09 15:56:54,884 - FASTopic - Epoch: 110 loss: 1445.733
Training FASTopic:  59%|████████████████████████████████████████████████████████████▊                                          | 118/200 [00:07<00:05, 16.05it/s]2024-07-09 15:56:55,502 - FASTopic - Epoch: 120 loss: 1440.017
Training FASTopic:  64%|█████████████████████████████████████████████████████████████████▉                                     | 128/200 [00:08<00:04, 16.19it/s]2024-07-09 15:56:56,261 - FASTopic - Epoch: 130 loss: 1434.754
Training FASTopic:  69%|███████████████████████████████████████████████████████████████████████                                | 138/200 [00:09<00:04, 15.01it/s]2024-07-09 15:56:56,880 - FASTopic - Epoch: 140 loss: 1429.868
Training FASTopic:  74%|████████████████████████████████████████████████████████████████████████████▏                          | 148/200 [00:09<00:03, 16.10it/s]2024-07-09 15:56:57,497 - FASTopic - Epoch: 150 loss: 1425.339
Training FASTopic:  79%|█████████████████████████████████████████████████████████████████████████████████▎                     | 158/200 [00:10<00:02, 16.10it/s]2024-07-09 15:56:58,119 - FASTopic - Epoch: 160 loss: 1421.107
Training FASTopic:  84%|██████████████████████████████████████████████████████████████████████████████████████▌                | 168/200 [00:11<00:02, 13.91it/s]2024-07-09 15:56:58,874 - FASTopic - Epoch: 170 loss: 1417.096
Training FASTopic:  89%|███████████████████████████████████████████████████████████████████████████████████████████▋           | 178/200 [00:11<00:01, 15.89it/s]2024-07-09 15:56:59,485 - FASTopic - Epoch: 180 loss: 1413.368
Training FASTopic:  94%|████████████████████████████████████████████████████████████████████████████████████████████████▊      | 188/200 [00:12<00:00, 16.16it/s]2024-07-09 15:57:00,101 - FASTopic - Epoch: 190 loss: 1409.853
Training FASTopic:  99%|█████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 198/200 [00:12<00:00, 11.93it/s]2024-07-09 15:57:00,867 - FASTopic - Epoch: 200 loss: 1406.540
Training FASTopic: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [00:13<00:00, 15.24it/s]
Topic 0: investigation charges lawyer prosecutors fbi lawyers documents mueller inquiry investigators guilty investigations counsel attorney prosecutor
Topic 1: cup olympics olympic gold parade space jumps medal toe plaza halfway notre skating cathedral bird
Topic 2: euros airline euro output currencies boeing reserves austerity reliance pork aluminum layoffs petroleum hospitality commodity
Topic 3: obama secretary trump aides washington house administration impeachment president white advisers adviser vice ambassador congress
Topic 4: bannon burisma rudy testifying qanon watergate rod daniels remark melania contradicted supremacists clintons fixer stormy
Topic 5: students education schools communities school college chicago university immigrants teachers survey families rural population shift
Topic 6: inflation fed prices markets growth economy bond recession price reserve bank stock economic unemployment market
Topic 7: hong kong protesters protest communist jinping beijing protests unrest crackdown demonstrations activists mainland demonstrators chinese
Topic 8: mayor brooklyn emanuel staten lynch ferguson superintendent northam rev assemblyman mansion lightfoot comptroller assaulting priests
Topic 9: rubble buried surfside horror bedroom remembered rodriguez sleeping aunt laundry bones condo champlain species stranger
Topic 10: kim korean jong abdullah seoul provincial nigeria fighter ballistic ghani moon col kandahar battlefield nigerian
Topic 11: sexual woman wife sex father mother weinstein women daughter husband abuse convicted brother friend son
Topic 12: talks negotiations withdrew inspectors negotiators pact enrichment tillerson blinken negotiation democracies retaliate capability annex annexation
Topic 13: delivery jersey transportation rail yorkers homeless transit warehouse hochul manhattan bike gavin evictions amtrak hudson
Topic 14: injured suspect rifle firearms sergeant rifles fatally gregory gunfire hostages gunmen unarmed blake rampage bystander
Topic 15: estate donations donated plaintiffs proposition nail raiser upheld ethical legalization beleaguered infusion signatures sum legalize
Topic 16: centrist socialist rajoy leftist thatcher govern opposes socialists formation majorities revolt boycott deadlock commons amendments
Topic 17: michael barbaro recording archived think know going really right just want kind get like see
Topic 18: storm hurricane puerto rescue rico collapse water river ice flooding rain disasters southwest flooded winds
Topic 19: travelers quarantine travel respiratory ventilators transmissible outdoors indoors pneumonia easter quarantined epidemiologists infect cough transmitted
Topic 20: drug drugs fda medicine trials treatment doctors patients blood cancer immune opioid researchers treatments fentanyl
Topic 21: supreme cuomo ruling abortion laws ban court gov courts governor rights judge amendment texas ruled
Topic 22: regulations restricting rulings prohibit obligations broadband adopting directive mechanism applies lobbied exemptions multinational blueprint align
Topic 23: corruption sentenced arrest navalny hacking arrested sentence nsa surveillance bribes silva spying graft dilma bribery
Topic 24: cory beto unfavorable takeaways undecided endorsements pundits characteristic libertarian comfortably nonwhite victor bend trailing campaigning
Topic 25: confirmation nominated collins scalise christie meadows insurrection gillibrand brady kemp murkowski pac nominate vacancies lindsey
Topic 26: spain indian india asia greece delhi madrid migrant asylum catalan philippines catalonia visa narendra myanmar
Topic 27: francis confronts dmitri hastily burnish entrenched cancels backfire grinding bureaucracy invade hinted cnbc reset pledging
Topic 28: student campus employer applicants academic yale educators universities pew gig graduates campuses nyu exam cornell
Topic 29: home whole good seems work little open lost old live long best something else look
Topic 30: lord possibilities treats influences philosophy humor authentic poker savage planting prefers charming genius tones labels
Topic 31: coronavirus vaccine virus covid vaccinated vaccines doses vaccination variant outbreak hospitals masks tested cdc infections
Topic 32: inconsistent alarms administering undergo jen inspection warranted directs directives adequate warp rollout certificates batch recommends
Topic 33: prime british minister parliament london brexit britain netanyahu france european boris royal ireland meghan independence
Topic 34: players league teams sports fans game player games baseball soccer athletes nfl ball season coach
Topic 35: voters candidates senator republican candidate democratic sanders voting votes vote election polls senate republicans clinton
Topic 36: film movie writer netflix movies documentary hbo films literature comedy memoir creative fiction writers biography
Topic 37: company companies executives uber industry amazon investment sales business musk billion buy corporate firm customers
Topic 38: art opera harry museum queen dance theater musical broadway artist performances singing songs ballet orchestra
Topic 39: flag muslim rally religious confederate muslims religion nazi charlottesville hindu flags nationalists extremism condemn semitic
Topic 40: saudi islamic afghanistan taliban syria iraq afghan isis iranian arabia iraqi syrian terrorist iran forces
Topic 41: captivity cries forthcoming rehabilitation psychologist executions tortured litany ordeal lethal injected disappearance wrenching forensic contends
Topic 42: tax budget insurance taxes proposal blasio plan bill funding proposed legislation package infrastructure spending benefits
Topic 43: china russian nuclear putin korea sanctions ukrainian moscow ukraine russia japan fuel sea canada countries
Topic 44: brazil rousseff club rio manchester petrobras carlos brazilian janeiro latin swiss banker cave fifa argentina
Topic 45: cars emissions environmental electric climate tesla vehicles plants pollution carbon coal plant trucks driving warming
Topic 46: twitter media harassment fox accusations facebook editor news resigned network email messages posted comments online
Topic 47: culture era words true dream love ideas book elites idea built writes grace phrase applause
Topic 48: police officers gun shooting officer violence floyd crowd station crime minutes brooks fire guns capitol
Topic 49: apple app google users apps software tech digital mobile privacy internet streaming silicon devices microsoft

As in the training process we're computing the pairwise euclidean distance between doc-topic and topic-word embeddings matrices, if the magnitude of some of those vectors is much higher than others, that influence can prevail and make all topics point in the same direction.

Not totally sure about this claim, but for me makes sense. Maybe @BobXWu can shed a bit of light here.

Guille

BobXWu commented 1 week ago

Hi Guille, You may try to set DT_alpha as the below. This can make the loss decline.

# Instantiate model's object
model = FASTopic(
    K,
    preprocessing,
    DT_alpha=10.0,
    doc_embed_model=doc_embedder,
    verbose=True,
)

I believe normalizing doc embeddings is also a good way to solve this problem. I guess this is because generated doc embeddings may be too widely distributed in the latent space, making topic embeddings difficult to build meaningful relations to them. Normalization can exactly mitigate this issue.

Thank you for this great finding!

BobXWu commented 1 week ago

Close this issue since the new version (v0.0.5) supports this feature: FASTopic(50, normalize_embeddings=True).

GuishePerez commented 1 week ago

Hi!

Yes, I tried several values, the same you suggested in the README: [5.0, 10.0, 15.0] but have no effect and the training loss didn't decrease.

I've just done an experiment. I see here in the sinkhorn's algorithm, DT_alpha is scaling the cost matrix (here named M). Then, if the embeddings are unnormalized, the distances will be large. If we further scale that by factors > 1 and then take the exp(-M * DT_alpha) that will be 0 right in the first iteration, and that's why it doesn't converge to anything. What I did is actually scale the cost matrix by DT_alpha < 1 (I tried 0.05), and in that case we start seeing the training loss decrease and producing meaningful topics eventually. Even with the unnormalized version of the embeddings.

I've seen in your paper, in the Appendix C (Algorithm 1), that M = exp(-C / eps), does it mean that in the code it should be K = torch.exp(-M / self.sinkhorn_alpha) instead of K = torch.exp(-M * self.sinkhorn_alpha)? In that case, yes, increasing DT_alpha will help the convergence.

Guille

BobXWu commented 1 week ago

Hi Guille,

eps in the paper and sinkhorn_alpha in the code are just different notations, where eps = 1/ sinkhorn_alpha.

I believe you're right. Small DT_alpha (large eps) can mitigate the issue caused by unnormalized embeddings. Small DT_alpha leads to less sparse transport plans between doc and topic embeddings; thus topic embeddings can move more freely in the space. Otherwise, large DT_alpha leads to sparse transport plans, limiting the movements of topic embeddings. See also the figure 2. mixedbread-ai/mxbai-embed-large-v1 may produce widely distributed embeddings, so either normalization or small DT_alpha can solve this issue.