Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Oct 25, 2021
1 parent 11460f1 commit 1d401ab
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions orangecontrib/text/widgets/owldavis.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def clear_all(self):
self.clear()
self.hideAxis("left")
self.hideAxis("top")
self.marg_prob_item = None

def update_graph(self, words, term_topic_freq, marginal_probability):
self.clear()
Expand Down Expand Up @@ -92,13 +93,14 @@ def update_axes(self, words):
self.setLabel(axis="top", text="weights")

ticks = [list(enumerate(words))]
# todo: ticks lengths - labels can be long truncate them
# it can be done together with implementing plot settings
self.getAxis("left").setTicks(ticks)

def __get_index_at(self, p: QPointF):
y = p.y()
index = round(y)
index = round(p.y())
widths = self.marg_prob_item.opts["width"]
if 0 <= index < len(widths) and abs(y - index) <= self.bar_width / 2:
if 0 <= index < len(widths) and abs(p.y() - index) <= self.bar_width / 2:
width = widths[index]
if 0 <= p.x() <= width:
return index
Expand Down Expand Up @@ -178,8 +180,10 @@ def compute_relevance(self, topic):

@staticmethod
def compute_distributions(data):
# term-topic column is multiplied by marginal topic probability
# how likely is the term in a topic * how likely is the topic
"""
term-topic column is multiplied by marginal topic probability
how likely is the term in a topic * how likely is the topic
"""
topic_frequency = data.get_column_view("Marginal Topic Probability")[0].astype(float)
return data.X * topic_frequency[:, None]

Expand Down Expand Up @@ -225,12 +229,13 @@ def clear(self):
self.term_topic_matrix = None
self.term_frequency = None

# todo: report


if __name__ == "__main__":
corpus = Corpus.from_file('deerwester')
lda = LdaWrapper(num_topics=5)
lda.fit_transform(corpus, chunk_number=100)
topics = lda.get_all_topics_table()
print(topics.metas)

WidgetPreview(OWLDAvis).run(topics)

0 comments on commit 1d401ab

Please sign in to comment.