tmplot 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tmplot-0.1.0/src/tmplot.egg-info → tmplot-0.1.2}/PKG-INFO +21 -5
- {tmplot-0.1.0 → tmplot-0.1.2}/README.md +4 -2
- {tmplot-0.1.0 → tmplot-0.1.2}/pyproject.toml +7 -3
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot/__init__.py +1 -1
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot/_distance.py +2 -1
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot/_helpers.py +28 -26
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot/_metrics.py +1 -2
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot/_stability.py +6 -6
- {tmplot-0.1.0 → tmplot-0.1.2/src/tmplot.egg-info}/PKG-INFO +21 -5
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot.egg-info/requires.txt +1 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/LICENSE +0 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/MANIFEST.in +0 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/setup.cfg +0 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot/_report.py +0 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot/_vis.py +0 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot.egg-info/SOURCES.txt +0 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot.egg-info/dependency_links.txt +0 -0
- {tmplot-0.1.0 → tmplot-0.1.2}/src/tmplot.egg-info/top_level.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tmplot
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Visualization of Topic Modeling Results
|
|
5
|
-
Author-email: Maksim
|
|
5
|
+
Author-email: Maksim Terpilovskii <maximtrp@gmail.com>
|
|
6
6
|
License: MIT License
|
|
7
7
|
|
|
8
8
|
Copyright (c) 2021 Maksim Terpilowski
|
|
@@ -34,20 +34,36 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
34
34
|
Classifier: Programming Language :: Python :: 3.9
|
|
35
35
|
Classifier: Programming Language :: Python :: 3.10
|
|
36
36
|
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
38
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
38
39
|
Classifier: Topic :: Text Processing :: General
|
|
39
40
|
Requires-Python: >=3.8
|
|
40
41
|
Description-Content-Type: text/markdown
|
|
42
|
+
License-File: LICENSE
|
|
43
|
+
Requires-Dist: numpy
|
|
44
|
+
Requires-Dist: seaborn
|
|
45
|
+
Requires-Dist: pandas
|
|
46
|
+
Requires-Dist: scikit-learn
|
|
47
|
+
Requires-Dist: scipy
|
|
48
|
+
Requires-Dist: altair
|
|
49
|
+
Requires-Dist: ipywidgets
|
|
50
|
+
Requires-Dist: tqdm
|
|
41
51
|
Provides-Extra: test
|
|
52
|
+
Requires-Dist: pytest; extra == "test"
|
|
53
|
+
Requires-Dist: coverage; extra == "test"
|
|
42
54
|
Provides-Extra: models
|
|
43
|
-
|
|
55
|
+
Requires-Dist: tomotopy>=0.8.0; extra == "models"
|
|
56
|
+
Requires-Dist: gensim; extra == "models"
|
|
57
|
+
Requires-Dist: bitermplus; extra == "models"
|
|
44
58
|
|
|
45
59
|
# tmplot
|
|
46
60
|
|
|
61
|
+
[](https://app.codacy.com/gh/maximtrp/tmplot/coverage)
|
|
62
|
+
[](https://app.codacy.com/gh/maximtrp/tmplot)
|
|
47
63
|
[](https://github.com/maximtrp/tmplot/actions/workflows/python-package.yml)
|
|
48
64
|
[](https://tmplot.readthedocs.io/en/latest/?badge=latest)
|
|
49
|
-
[](https://pepy.tech/project/tmplot)
|
|
50
|
-

|
|
65
|
+
[](https://pepy.tech/project/tmplot)
|
|
66
|
+
[](https://pypi.org/project/tmplot)
|
|
51
67
|
[](https://github.com/maximtrp/tmplot/issues)
|
|
52
68
|
|
|
53
69
|
**tmplot** is a Python package for analysis and visualization of topic modeling results. It provides the interactive report interface that borrows much from LDAvis/pyLDAvis and builds upon it offering a number of metrics for calculating topic distances and a number of algorithms for calculating scatter coordinates of topics. It can be used to select closest and stable topics across multiple models.
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# tmplot
|
|
2
2
|
|
|
3
|
+
[](https://app.codacy.com/gh/maximtrp/tmplot/coverage)
|
|
4
|
+
[](https://app.codacy.com/gh/maximtrp/tmplot)
|
|
3
5
|
[](https://github.com/maximtrp/tmplot/actions/workflows/python-package.yml)
|
|
4
6
|
[](https://tmplot.readthedocs.io/en/latest/?badge=latest)
|
|
5
|
-
[](https://pepy.tech/project/tmplot)
|
|
6
|
-

|
|
7
|
+
[](https://pepy.tech/project/tmplot)
|
|
8
|
+
[](https://pypi.org/project/tmplot)
|
|
7
9
|
[](https://github.com/maximtrp/tmplot/issues)
|
|
8
10
|
|
|
9
11
|
**tmplot** is a Python package for analysis and visualization of topic modeling results. It provides the interactive report interface that borrows much from LDAvis/pyLDAvis and builds upon it offering a number of metrics for calculating topic distances and a number of algorithms for calculating scatter coordinates of topics. It can be used to select closest and stable topics across multiple models.
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tmplot"
|
|
7
|
-
|
|
7
|
+
dynamic = ["version"]
|
|
8
8
|
description = "Visualization of Topic Modeling Results"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
11
11
|
license.file = "LICENSE"
|
|
12
12
|
authors = [
|
|
13
|
-
{ name = "Maksim
|
|
13
|
+
{ name = "Maksim Terpilovskii", email = "maximtrp@gmail.com" },
|
|
14
14
|
]
|
|
15
15
|
keywords = [
|
|
16
16
|
"data science",
|
|
@@ -23,6 +23,7 @@ classifiers = [
|
|
|
23
23
|
"Programming Language :: Python :: 3.9",
|
|
24
24
|
"Programming Language :: Python :: 3.10",
|
|
25
25
|
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
26
27
|
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
27
28
|
"Topic :: Text Processing :: General",
|
|
28
29
|
]
|
|
@@ -41,9 +42,12 @@ dependencies = [
|
|
|
41
42
|
]
|
|
42
43
|
|
|
43
44
|
[project.optional-dependencies]
|
|
44
|
-
test = ["pytest"]
|
|
45
|
+
test = ["pytest", "coverage"]
|
|
45
46
|
models = ["tomotopy>=0.8.0", "gensim", "bitermplus"]
|
|
46
47
|
|
|
48
|
+
[tool.setuptools.dynamic]
|
|
49
|
+
version = {attr = "tmplot.__version__"}
|
|
50
|
+
|
|
47
51
|
[tool.pytest.ini_options]
|
|
48
52
|
log_cli = true
|
|
49
53
|
log_cli_level = "INFO"
|
|
@@ -152,7 +152,7 @@ def get_topics_scatter(
|
|
|
152
152
|
method_kws.setdefault('init', 'pca')
|
|
153
153
|
method_kws.setdefault('learning_rate', 'auto')
|
|
154
154
|
method_kws.setdefault(
|
|
155
|
-
'perplexity', min(50, max(topic_dists.shape[0] // 2,
|
|
155
|
+
'perplexity', min(50, max(topic_dists.shape[0] // 2, 1)))
|
|
156
156
|
transformer = TSNE(**method_kws)
|
|
157
157
|
|
|
158
158
|
elif method == 'sem':
|
|
@@ -161,6 +161,7 @@ def get_topics_scatter(
|
|
|
161
161
|
|
|
162
162
|
elif method == 'mds':
|
|
163
163
|
method_kws.setdefault('dissimilarity', 'precomputed')
|
|
164
|
+
method_kws.setdefault('normalized_stress', 'auto')
|
|
164
165
|
transformer = MDS(**method_kws)
|
|
165
166
|
|
|
166
167
|
elif method == 'lle':
|
|
@@ -10,6 +10,7 @@ from typing import Union, Optional, Sequence, List
|
|
|
10
10
|
from functools import partial
|
|
11
11
|
from math import log
|
|
12
12
|
from numpy import ndarray, zeros, argsort, array, arange, vstack
|
|
13
|
+
from numpy import log as nplog
|
|
13
14
|
from pandas import concat, Series, DataFrame
|
|
14
15
|
|
|
15
16
|
tomotopy_installed = find_spec('tomotopy')
|
|
@@ -96,26 +97,26 @@ def _is_tomotopy(model: object) -> bool:
|
|
|
96
97
|
tomotopyLDA, tomotopyLLDA, tomotopyCT, tomotopyDMR, tomotopyHDP,
|
|
97
98
|
tomotopyPT, tomotopySLDA, tomotopyGDMR]
|
|
98
99
|
return any(map(partial(isinstance, model), tomotopy_models))
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
|
|
101
|
+
__warn_package_installation("tomotopy")
|
|
102
|
+
return False
|
|
102
103
|
|
|
103
104
|
|
|
104
105
|
def _is_gensim(model: object) -> bool:
|
|
105
106
|
if gensim_installed:
|
|
106
107
|
gensim_models = [gensimLDA, gensimLDAMC]
|
|
107
108
|
return any(map(partial(isinstance, model), gensim_models))
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
|
|
110
|
+
__warn_package_installation("gensim")
|
|
111
|
+
return False
|
|
111
112
|
|
|
112
113
|
|
|
113
114
|
def _is_btmplus(model: object) -> bool:
|
|
114
115
|
if bitermplus_installed:
|
|
115
116
|
return isinstance(model, BTM)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
|
|
118
|
+
__warn_package_installation("bitermplus")
|
|
119
|
+
return False
|
|
119
120
|
|
|
120
121
|
|
|
121
122
|
def get_theta(
|
|
@@ -225,7 +226,7 @@ def get_top_docs(
|
|
|
225
226
|
if all([model is None, theta is None]):
|
|
226
227
|
raise ValueError("Please pass a model or a theta matrix to function")
|
|
227
228
|
|
|
228
|
-
if model and not
|
|
229
|
+
if model and theta is not None:
|
|
229
230
|
theta = get_theta(model, corpus=corpus).values
|
|
230
231
|
|
|
231
232
|
def _select_docs(docs, theta, topic_id: int):
|
|
@@ -258,13 +259,13 @@ def calc_topics_marg_probs(
|
|
|
258
259
|
Union[pandas.DataFrame, numpy.ndarray]
|
|
259
260
|
Marginal topics probabilities.
|
|
260
261
|
"""
|
|
261
|
-
if topic_id:
|
|
262
|
+
if topic_id is not None:
|
|
262
263
|
if isinstance(theta, ndarray):
|
|
263
264
|
return theta[topic_id, :].sum()
|
|
264
|
-
|
|
265
|
+
if isinstance(theta, DataFrame):
|
|
265
266
|
return theta.iloc[topic_id, :].sum()
|
|
266
|
-
|
|
267
|
-
|
|
267
|
+
|
|
268
|
+
return theta.sum(axis=1)
|
|
268
269
|
|
|
269
270
|
|
|
270
271
|
def calc_terms_marg_probs(
|
|
@@ -284,13 +285,13 @@ def calc_terms_marg_probs(
|
|
|
284
285
|
Union[numpy.ndarray, pandas.Series]
|
|
285
286
|
Marginal terms probabilities.
|
|
286
287
|
"""
|
|
287
|
-
if word_id:
|
|
288
|
+
if word_id is not None:
|
|
288
289
|
if isinstance(phi, ndarray):
|
|
289
290
|
return phi[word_id, :].sum()
|
|
290
|
-
|
|
291
|
+
if isinstance(phi, DataFrame):
|
|
291
292
|
return phi.iloc[word_id, :].sum()
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
|
|
294
|
+
return phi.sum(axis=1)
|
|
294
295
|
|
|
295
296
|
|
|
296
297
|
def get_salient_terms(
|
|
@@ -323,12 +324,12 @@ def get_salient_terms(
|
|
|
323
324
|
def _p_tw(phi, w, t):
|
|
324
325
|
return phi[w, t] * p_t[t] / p_w[w]
|
|
325
326
|
|
|
326
|
-
saliency = array(
|
|
327
|
-
terms_freqs[w] * sum(
|
|
327
|
+
saliency = array((
|
|
328
|
+
terms_freqs[w] * sum((
|
|
328
329
|
_p_tw(phi, w, t) * log(_p_tw(phi, w, t) / p_t[t])
|
|
329
|
-
for t in range(phi.shape[1])
|
|
330
|
+
for t in range(phi.shape[1])))
|
|
330
331
|
for w in range(phi.shape[0])
|
|
331
|
-
|
|
332
|
+
))
|
|
332
333
|
# saliency(term w) = frequency(w)
|
|
333
334
|
# * [sum_t p(t | w) * log(p(t | w)/p(t))] for topics t
|
|
334
335
|
# p(t | w) = p(w | t) * p(t) / p(w)
|
|
@@ -367,7 +368,7 @@ def calc_terms_probs_ratio(
|
|
|
367
368
|
pandas.DataFrame
|
|
368
369
|
Words conditional and marginal probabilities.
|
|
369
370
|
"""
|
|
370
|
-
p_cond_name = 'Conditional term probability, p(w|t)'
|
|
371
|
+
p_cond_name = 'Conditional term probability, p(w | t)'
|
|
371
372
|
p_cond = phi.iloc[:, topic]\
|
|
372
373
|
.rename(p_cond_name)\
|
|
373
374
|
if isinstance(phi, DataFrame)\
|
|
@@ -424,7 +425,8 @@ def get_relevant_terms(
|
|
|
424
425
|
phi_topic = phi.iloc[:, topic]\
|
|
425
426
|
if isinstance(phi, DataFrame)\
|
|
426
427
|
else phi[:, topic]
|
|
427
|
-
|
|
428
|
-
relevance =
|
|
429
|
-
|
|
428
|
+
|
|
429
|
+
# relevance = lambda * log(p(w | t)) + (1 - lambda) * log(p(w | t) / p(w))
|
|
430
|
+
relevance = lambda_ * nplog(phi_topic)\
|
|
431
|
+
+ (1 - lambda_) * nplog(phi_topic / phi.sum(axis=1))
|
|
430
432
|
return relevance.sort_values(ascending=False)
|
|
@@ -2,7 +2,7 @@ __all__ = ['get_closest_topics', 'get_stable_topics']
|
|
|
2
2
|
from typing import List, Tuple, Any
|
|
3
3
|
import numpy as np
|
|
4
4
|
import tqdm
|
|
5
|
-
from ._distance import _dist_klb, _dist_sklb, _dist_jsd, _dist_jef, _dist_hel
|
|
5
|
+
from ._distance import _dist_klb, _dist_sklb, _dist_jsd, _dist_jef, _dist_hel, \
|
|
6
6
|
_dist_bhat, _dist_jac, _dist_tv
|
|
7
7
|
from ._helpers import get_phi
|
|
8
8
|
|
|
@@ -50,12 +50,13 @@ def get_closest_topics(
|
|
|
50
50
|
Returns
|
|
51
51
|
-------
|
|
52
52
|
closest_topics : np.ndarray
|
|
53
|
-
Closest topics indices in one two-dimensional array.
|
|
53
|
+
Closest topics indices in one two-dimensional array (topics ✕ models).
|
|
54
54
|
Columns correspond to the compared models (their indices),
|
|
55
55
|
rows are the closest topics pairs.
|
|
56
56
|
dist : np.ndarray
|
|
57
|
-
|
|
58
|
-
values
|
|
57
|
+
Closest topics distances (e.g., Kullback-Leibler or Jaccard index
|
|
58
|
+
values). Shape of this array corresponds to the shape of the first
|
|
59
|
+
returned argument.
|
|
59
60
|
|
|
60
61
|
Example
|
|
61
62
|
-------
|
|
@@ -75,7 +76,6 @@ def get_closest_topics(
|
|
|
75
76
|
model_ref_phi = get_phi(model_ref)
|
|
76
77
|
|
|
77
78
|
# Number of topics
|
|
78
|
-
print(type(model_ref_phi))
|
|
79
79
|
topics_num = model_ref_phi.shape[1]
|
|
80
80
|
|
|
81
81
|
# Array with the closest topics ids
|
|
@@ -105,7 +105,7 @@ def get_closest_topics(
|
|
|
105
105
|
for t_ref in range(topics_num):
|
|
106
106
|
for t in range(topics_num):
|
|
107
107
|
all_vs_all_dists[t_ref, t] = dist_func(
|
|
108
|
-
model_ref_phi.iloc[t_ref
|
|
108
|
+
model_ref_phi.iloc[:, t_ref], get_phi(model).iloc[:, t])
|
|
109
109
|
|
|
110
110
|
# Creating two arrays for the closest topics ids and distance values
|
|
111
111
|
if method == "jac":
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tmplot
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Visualization of Topic Modeling Results
|
|
5
|
-
Author-email: Maksim
|
|
5
|
+
Author-email: Maksim Terpilovskii <maximtrp@gmail.com>
|
|
6
6
|
License: MIT License
|
|
7
7
|
|
|
8
8
|
Copyright (c) 2021 Maksim Terpilowski
|
|
@@ -34,20 +34,36 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
34
34
|
Classifier: Programming Language :: Python :: 3.9
|
|
35
35
|
Classifier: Programming Language :: Python :: 3.10
|
|
36
36
|
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
38
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
38
39
|
Classifier: Topic :: Text Processing :: General
|
|
39
40
|
Requires-Python: >=3.8
|
|
40
41
|
Description-Content-Type: text/markdown
|
|
42
|
+
License-File: LICENSE
|
|
43
|
+
Requires-Dist: numpy
|
|
44
|
+
Requires-Dist: seaborn
|
|
45
|
+
Requires-Dist: pandas
|
|
46
|
+
Requires-Dist: scikit-learn
|
|
47
|
+
Requires-Dist: scipy
|
|
48
|
+
Requires-Dist: altair
|
|
49
|
+
Requires-Dist: ipywidgets
|
|
50
|
+
Requires-Dist: tqdm
|
|
41
51
|
Provides-Extra: test
|
|
52
|
+
Requires-Dist: pytest; extra == "test"
|
|
53
|
+
Requires-Dist: coverage; extra == "test"
|
|
42
54
|
Provides-Extra: models
|
|
43
|
-
|
|
55
|
+
Requires-Dist: tomotopy>=0.8.0; extra == "models"
|
|
56
|
+
Requires-Dist: gensim; extra == "models"
|
|
57
|
+
Requires-Dist: bitermplus; extra == "models"
|
|
44
58
|
|
|
45
59
|
# tmplot
|
|
46
60
|
|
|
61
|
+
[](https://app.codacy.com/gh/maximtrp/tmplot/coverage)
|
|
62
|
+
[](https://app.codacy.com/gh/maximtrp/tmplot)
|
|
47
63
|
[](https://github.com/maximtrp/tmplot/actions/workflows/python-package.yml)
|
|
48
64
|
[](https://tmplot.readthedocs.io/en/latest/?badge=latest)
|
|
49
|
-
[](https://pepy.tech/project/tmplot)
|
|
50
|
-

|
|
65
|
+
[](https://pepy.tech/project/tmplot)
|
|
66
|
+
[](https://pypi.org/project/tmplot)
|
|
51
67
|
[](https://github.com/maximtrp/tmplot/issues)
|
|
52
68
|
|
|
53
69
|
**tmplot** is a Python package for analysis and visualization of topic modeling results. It provides the interactive report interface that borrows much from LDAvis/pyLDAvis and builds upon it offering a number of metrics for calculating topic distances and a number of algorithms for calculating scatter coordinates of topics. It can be used to select closest and stable topics across multiple models.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|