From dc41ddfca3142e4d0b69eb5b35161eb5d49ae1ff Mon Sep 17 00:00:00 2001
From: PrimozGodec
Date: Fri, 3 Nov 2023 13:21:35 +0100
Subject: [PATCH] Topic modelling - Reorder methods by relevance
---
orangecontrib/text/widgets/owtopicmodeling.py | 2 ++
.../text/widgets/tests/test_owtopicmodeling.py | 14 ++++++--------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/orangecontrib/text/widgets/owtopicmodeling.py b/orangecontrib/text/widgets/owtopicmodeling.py
index 5e2348695..4ee38cb78 100644
--- a/orangecontrib/text/widgets/owtopicmodeling.py
+++ b/orangecontrib/text/widgets/owtopicmodeling.py
@@ -267,6 +267,8 @@ def on_done(self, corpus):
if self.model.name == "Latent Dirichlet Allocation":
bound = self.model.model.log_perplexity(infer_ngrams_corpus(corpus))
self.perplexity = "{:.5f}".format(np.exp2(-bound))
+ else:
+ self.perplexity = "n/a"
# for small corpora it is slower to use more processes
# there is no good estimation when multiprocessing is helpful, but it is
# definitely not helpful for corpora smaller than 100
diff --git a/orangecontrib/text/widgets/tests/test_owtopicmodeling.py b/orangecontrib/text/widgets/tests/test_owtopicmodeling.py
index 4424a18db..582d5dcad 100644
--- a/orangecontrib/text/widgets/tests/test_owtopicmodeling.py
+++ b/orangecontrib/text/widgets/tests/test_owtopicmodeling.py
@@ -22,7 +22,6 @@ def test_data(self):
self.assertIsNone(output)
def test_saved_selection(self):
- self.widget.method_index = 1
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.wait_until_finished()
@@ -58,17 +57,16 @@ def test_topic_evaluation(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.wait_until_finished()
- # test LSI
- self.assertEqual(self.widget.perplexity, "n/a")
- self.assertNotEqual(self.widget.coherence, "n/a")
-
# test LDA, which is the only one with log perplexity
+ self.assertNotEqual(self.widget.perplexity, "n/a")
+ self.assertTrue(self.widget.coherence)
+
+ # test LSI
self.widget.method_index = 1
self.widget.commit.now()
self.wait_until_finished()
-
- self.assertNotEqual(self.widget.perplexity, "n/a")
- self.assertTrue(self.widget.coherence)
+ self.assertEqual(self.widget.perplexity, "n/a")
+ self.assertNotEqual(self.widget.coherence, "n/a")
def test_migrate_settings_transform(self):
# 0 used to be LSI in version <2 - it is on index 1 now