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.
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tmplot
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Visualization of Topic Modeling Results
5
- Author-email: Maksim Terpilowski <maximtrp@gmail.com>
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
- License-File: LICENSE
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
+ [![Codacy coverage](https://img.shields.io/codacy/coverage/5939b1cf99bc4f9d91de11c0d3ff9e50)](https://app.codacy.com/gh/maximtrp/tmplot/coverage)
62
+ [![Codacy grade](https://img.shields.io/codacy/grade/5939b1cf99bc4f9d91de11c0d3ff9e50)](https://app.codacy.com/gh/maximtrp/tmplot)
47
63
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/maximtrp/tmplot/python-package.yml?label=tests)](https://github.com/maximtrp/tmplot/actions/workflows/python-package.yml)
48
64
  [![Documentation Status](https://readthedocs.org/projects/tmplot/badge/?version=latest)](https://tmplot.readthedocs.io/en/latest/?badge=latest)
49
- [![Downloads](https://pepy.tech/badge/tmplot)](https://pepy.tech/project/tmplot)
50
- ![PyPI](https://img.shields.io/pypi/v/tmplot)
65
+ [![Downloads](https://static.pepy.tech/badge/tmplot)](https://pepy.tech/project/tmplot)
66
+ [![PyPI](https://img.shields.io/pypi/v/tmplot)](https://pypi.org/project/tmplot)
51
67
  [![Issues](https://img.shields.io/github/issues/maximtrp/tmplot.svg)](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
+ [![Codacy coverage](https://img.shields.io/codacy/coverage/5939b1cf99bc4f9d91de11c0d3ff9e50)](https://app.codacy.com/gh/maximtrp/tmplot/coverage)
4
+ [![Codacy grade](https://img.shields.io/codacy/grade/5939b1cf99bc4f9d91de11c0d3ff9e50)](https://app.codacy.com/gh/maximtrp/tmplot)
3
5
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/maximtrp/tmplot/python-package.yml?label=tests)](https://github.com/maximtrp/tmplot/actions/workflows/python-package.yml)
4
6
  [![Documentation Status](https://readthedocs.org/projects/tmplot/badge/?version=latest)](https://tmplot.readthedocs.io/en/latest/?badge=latest)
5
- [![Downloads](https://pepy.tech/badge/tmplot)](https://pepy.tech/project/tmplot)
6
- ![PyPI](https://img.shields.io/pypi/v/tmplot)
7
+ [![Downloads](https://static.pepy.tech/badge/tmplot)](https://pepy.tech/project/tmplot)
8
+ [![PyPI](https://img.shields.io/pypi/v/tmplot)](https://pypi.org/project/tmplot)
7
9
  [![Issues](https://img.shields.io/github/issues/maximtrp/tmplot.svg)](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
- version = "0.1.0"
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 Terpilowski", email = "maximtrp@gmail.com" },
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"
@@ -5,4 +5,4 @@ from ._stability import * # noqa: F401, F403
5
5
  from ._vis import * # noqa: F401, F403
6
6
  from ._metrics import * # noqa: F401, F403
7
7
 
8
- __version__ = '0.1.0'
8
+ __version__ = '0.1.2'
@@ -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, 5)))
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
- else:
100
- __warn_package_installation("tomotopy")
101
- return False
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
- else:
109
- __warn_package_installation("gensim")
110
- return False
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
- else:
117
- __warn_package_installation("bitermplus")
118
- return False
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 theta:
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
- elif isinstance(theta, DataFrame):
265
+ if isinstance(theta, DataFrame):
265
266
  return theta.iloc[topic_id, :].sum()
266
- else:
267
- return theta.sum(axis=1)
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
- elif isinstance(phi, DataFrame):
291
+ if isinstance(phi, DataFrame):
291
292
  return phi.iloc[word_id, :].sum()
292
- else:
293
- return phi.sum(axis=1)
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
- # relevance = lambda * p(w | t) + (1 - lambda) * p(w | t)/p(w)
428
- relevance = lambda_ * phi_topic\
429
- + (1 - lambda_) * phi_topic / phi.sum(axis=1)
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)
@@ -1,8 +1,7 @@
1
- __all__ = [
2
- 'entropy']
3
1
  """Metrics module"""
4
2
  from math import log
5
3
  import numpy as np
4
+ __all__ = ['entropy']
6
5
 
7
6
 
8
7
  def entropy(phi: np.ndarray, max_probs: bool = 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
- Kullback-Leibler (if ``method`` is set to ``klb``) or Jaccard index
58
- values corresponding to the matrix of the closest topics.
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, :], get_phi(model).iloc[t, :])
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.0
3
+ Version: 0.1.2
4
4
  Summary: Visualization of Topic Modeling Results
5
- Author-email: Maksim Terpilowski <maximtrp@gmail.com>
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
- License-File: LICENSE
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
+ [![Codacy coverage](https://img.shields.io/codacy/coverage/5939b1cf99bc4f9d91de11c0d3ff9e50)](https://app.codacy.com/gh/maximtrp/tmplot/coverage)
62
+ [![Codacy grade](https://img.shields.io/codacy/grade/5939b1cf99bc4f9d91de11c0d3ff9e50)](https://app.codacy.com/gh/maximtrp/tmplot)
47
63
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/maximtrp/tmplot/python-package.yml?label=tests)](https://github.com/maximtrp/tmplot/actions/workflows/python-package.yml)
48
64
  [![Documentation Status](https://readthedocs.org/projects/tmplot/badge/?version=latest)](https://tmplot.readthedocs.io/en/latest/?badge=latest)
49
- [![Downloads](https://pepy.tech/badge/tmplot)](https://pepy.tech/project/tmplot)
50
- ![PyPI](https://img.shields.io/pypi/v/tmplot)
65
+ [![Downloads](https://static.pepy.tech/badge/tmplot)](https://pepy.tech/project/tmplot)
66
+ [![PyPI](https://img.shields.io/pypi/v/tmplot)](https://pypi.org/project/tmplot)
51
67
  [![Issues](https://img.shields.io/github/issues/maximtrp/tmplot.svg)](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.
@@ -14,3 +14,4 @@ bitermplus
14
14
 
15
15
  [test]
16
16
  pytest
17
+ coverage
File without changes
File without changes
File without changes
File without changes
File without changes