tomoto 0.6.0 → 0.6.2

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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/LICENSE.txt +1 -1
  4. data/ext/tomoto/ct.cpp +1 -1
  5. data/ext/tomoto/dmr.cpp +1 -1
  6. data/ext/tomoto/dt.cpp +1 -1
  7. data/ext/tomoto/extconf.rb +4 -8
  8. data/ext/tomoto/gdmr.cpp +1 -1
  9. data/ext/tomoto/hdp.cpp +1 -1
  10. data/ext/tomoto/hlda.cpp +1 -1
  11. data/ext/tomoto/hpa.cpp +1 -1
  12. data/ext/tomoto/lda.cpp +29 -3
  13. data/ext/tomoto/llda.cpp +1 -1
  14. data/ext/tomoto/mglda.cpp +1 -1
  15. data/ext/tomoto/pa.cpp +1 -1
  16. data/ext/tomoto/plda.cpp +1 -1
  17. data/ext/tomoto/slda.cpp +1 -1
  18. data/lib/tomoto/lda.rb +1 -0
  19. data/lib/tomoto/version.rb +1 -1
  20. data/vendor/EigenRand/EigenRand/Core.h +6 -4
  21. data/vendor/EigenRand/EigenRand/CwiseHeteroBinaryOp.h +265 -0
  22. data/vendor/EigenRand/EigenRand/Dists/Basic.h +345 -12
  23. data/vendor/EigenRand/EigenRand/Dists/Discrete.h +381 -7
  24. data/vendor/EigenRand/EigenRand/Dists/GammaPoisson.h +4 -4
  25. data/vendor/EigenRand/EigenRand/Dists/NormalExp.h +576 -4
  26. data/vendor/EigenRand/EigenRand/EigenRand +4 -4
  27. data/vendor/EigenRand/EigenRand/Macro.h +3 -3
  28. data/vendor/EigenRand/EigenRand/MorePacketMath.h +31 -30
  29. data/vendor/EigenRand/EigenRand/MvDists/Multinomial.h +41 -29
  30. data/vendor/EigenRand/EigenRand/MvDists/MvNormal.h +19 -7
  31. data/vendor/EigenRand/EigenRand/PacketFilter.h +8 -5
  32. data/vendor/EigenRand/EigenRand/PacketRandomEngine.h +3 -3
  33. data/vendor/EigenRand/EigenRand/RandUtils.h +180 -5
  34. data/vendor/EigenRand/EigenRand/arch/AVX/MorePacketMath.h +42 -3
  35. data/vendor/EigenRand/EigenRand/arch/AVX/PacketFilter.h +3 -3
  36. data/vendor/EigenRand/EigenRand/arch/AVX/RandUtils.h +3 -3
  37. data/vendor/EigenRand/EigenRand/arch/AVX512/MorePacketMath.h +312 -0
  38. data/vendor/EigenRand/EigenRand/arch/AVX512/PacketFilter.h +79 -0
  39. data/vendor/EigenRand/EigenRand/arch/AVX512/RandUtils.h +147 -0
  40. data/vendor/EigenRand/EigenRand/arch/NEON/MorePacketMath.h +118 -3
  41. data/vendor/EigenRand/EigenRand/arch/NEON/PacketFilter.h +3 -3
  42. data/vendor/EigenRand/EigenRand/arch/NEON/RandUtils.h +21 -3
  43. data/vendor/EigenRand/EigenRand/arch/SSE/MorePacketMath.h +32 -4
  44. data/vendor/EigenRand/EigenRand/arch/SSE/PacketFilter.h +3 -3
  45. data/vendor/EigenRand/EigenRand/arch/SSE/RandUtils.h +3 -3
  46. data/vendor/EigenRand/EigenRand/doc.h +108 -157
  47. data/vendor/EigenRand/README.md +60 -272
  48. data/vendor/tomotopy/README.kr.rst +27 -5
  49. data/vendor/tomotopy/README.rst +27 -5
  50. data/vendor/tomotopy/README_pypi.rst +583 -0
  51. data/vendor/tomotopy/licenses_bundled/EigenRand +21 -0
  52. data/vendor/tomotopy/src/TopicModel/CT.h +1 -1
  53. data/vendor/tomotopy/src/TopicModel/CTModel.cpp +1 -1
  54. data/vendor/tomotopy/src/TopicModel/DMR.h +1 -1
  55. data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +1 -1
  56. data/vendor/tomotopy/src/TopicModel/DT.h +1 -1
  57. data/vendor/tomotopy/src/TopicModel/DTModel.cpp +1 -1
  58. data/vendor/tomotopy/src/TopicModel/GDMR.h +1 -1
  59. data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +1 -1
  60. data/vendor/tomotopy/src/TopicModel/HDP.h +1 -1
  61. data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +1 -1
  62. data/vendor/tomotopy/src/TopicModel/HLDA.h +1 -1
  63. data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +1 -1
  64. data/vendor/tomotopy/src/TopicModel/HPA.h +1 -1
  65. data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +1 -1
  66. data/vendor/tomotopy/src/TopicModel/LDA.h +1 -1
  67. data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +1 -1
  68. data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +6 -6
  69. data/vendor/tomotopy/src/TopicModel/LLDA.h +1 -1
  70. data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +1 -1
  71. data/vendor/tomotopy/src/TopicModel/MGLDA.h +1 -1
  72. data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +1 -1
  73. data/vendor/tomotopy/src/TopicModel/PA.h +1 -1
  74. data/vendor/tomotopy/src/TopicModel/PAModel.cpp +1 -1
  75. data/vendor/tomotopy/src/TopicModel/PLDA.h +1 -1
  76. data/vendor/tomotopy/src/TopicModel/PLDAModel.cpp +1 -1
  77. data/vendor/tomotopy/src/TopicModel/PT.h +1 -1
  78. data/vendor/tomotopy/src/TopicModel/PTModel.cpp +1 -1
  79. data/vendor/tomotopy/src/TopicModel/SLDA.h +1 -1
  80. data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +1 -1
  81. data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +6 -6
  82. data/vendor/tomotopy/src/Utils/EigenAddonOps.hpp +41 -0
  83. data/vendor/tomotopy/src/Utils/ThreadPool.hpp +6 -6
  84. data/vendor/tomotopy/src/Utils/Utils.hpp +3 -3
  85. data/vendor/tomotopy/src/Utils/avx512_gamma.h +46 -0
  86. data/vendor/tomotopy/src/Utils/avx512_mathfun.h +99 -0
  87. metadata +10 -9
  88. data/vendor/variant/LICENSE +0 -25
  89. data/vendor/variant/LICENSE_1_0.txt +0 -23
  90. data/vendor/variant/README.md +0 -102
  91. data/vendor/variant/include/mapbox/optional.hpp +0 -74
  92. data/vendor/variant/include/mapbox/recursive_wrapper.hpp +0 -122
  93. data/vendor/variant/include/mapbox/variant.hpp +0 -974
  94. data/vendor/variant/include/mapbox/variant_io.hpp +0 -45
@@ -0,0 +1,583 @@
1
+ tomotopy
2
+ ========
3
+
4
+ .. image:: https://badge.fury.io/py/tomotopy.svg
5
+ :target: https://pypi.python.org/pypi/tomotopy
6
+
7
+ .. image:: https://zenodo.org/badge/186155463.svg
8
+ :target: https://zenodo.org/badge/latestdoi/186155463
9
+
10
+ 🌐
11
+ **English**,
12
+ `한국어`_.
13
+
14
+ .. _한국어: README.kr.rst
15
+
16
+ What is tomotopy?
17
+ ------------------
18
+
19
+ `tomotopy` is a Python extension of `tomoto` (Topic Modeling Tool) which is a Gibbs-sampling based topic model library written in C++.
20
+ It utilizes a vectorization of modern CPUs for maximizing speed.
21
+ The current version of `tomoto` supports several major topic models including
22
+
23
+ * Latent Dirichlet Allocation (`tomotopy.LDAModel`)
24
+ * Labeled LDA (`tomotopy.LLDAModel`)
25
+ * Partially Labeled LDA (`tomotopy.PLDAModel`)
26
+ * Supervised LDA (`tomotopy.SLDAModel`)
27
+ * Dirichlet Multinomial Regression (`tomotopy.DMRModel`)
28
+ * Generalized Dirichlet Multinomial Regression (`tomotopy.GDMRModel`)
29
+ * Hierarchical Dirichlet Process (`tomotopy.HDPModel`)
30
+ * Hierarchical LDA (`tomotopy.HLDAModel`)
31
+ * Multi Grain LDA (`tomotopy.MGLDAModel`)
32
+ * Pachinko Allocation (`tomotopy.PAModel`)
33
+ * Hierarchical PA (`tomotopy.HPAModel`)
34
+ * Correlated Topic Model (`tomotopy.CTModel`)
35
+ * Dynamic Topic Model (`tomotopy.DTModel`)
36
+ * Pseudo-document based Topic Model (`tomotopy.PTModel`).
37
+
38
+ Please visit https://bab2min.github.io/tomotopy to see more information.
39
+
40
+ Getting Started
41
+ ---------------
42
+ You can install tomotopy easily using pip. (https://pypi.org/project/tomotopy/)
43
+ ::
44
+
45
+ $ pip install --upgrade pip
46
+ $ pip install tomotopy
47
+
48
+ The supported OS and Python versions are:
49
+
50
+ * Linux (x86-64) with Python >= 3.6
51
+ * macOS >= 10.13 with Python >= 3.6
52
+ * Windows 7 or later (x86, x86-64) with Python >= 3.6
53
+ * Other OS with Python >= 3.6: Compilation from source code required (with c++14 compatible compiler)
54
+
55
+ After installing, you can start tomotopy by just importing.
56
+ ::
57
+
58
+ import tomotopy as tp
59
+ print(tp.isa) # prints 'avx512', 'avx2', 'sse2' or 'none'
60
+
61
+ Currently, tomotopy can exploits AVX512, AVX2 or SSE2 SIMD instruction set for maximizing performance.
62
+ When the package is imported, it will check available instruction sets and select the best option.
63
+ If `tp.isa` tells `none`, iterations of training may take a long time.
64
+ But, since most of modern Intel or AMD CPUs provide SIMD instruction set, the SIMD acceleration could show a big improvement.
65
+
66
+ Here is a sample code for simple LDA training of texts from 'sample.txt' file.
67
+ ::
68
+
69
+ import tomotopy as tp
70
+ mdl = tp.LDAModel(k=20)
71
+ for line in open('sample.txt'):
72
+ mdl.add_doc(line.strip().split())
73
+
74
+ for i in range(0, 100, 10):
75
+ mdl.train(10)
76
+ print('Iteration: {}\tLog-likelihood: {}'.format(i, mdl.ll_per_word))
77
+
78
+ for k in range(mdl.k):
79
+ print('Top 10 words of topic #{}'.format(k))
80
+ print(mdl.get_topic_words(k, top_n=10))
81
+
82
+ mdl.summary()
83
+
84
+ Performance of tomotopy
85
+ -----------------------
86
+ `tomotopy` uses Collapsed Gibbs-Sampling(CGS) to infer the distribution of topics and the distribution of words.
87
+ Generally CGS converges more slowly than Variational Bayes(VB) that `gensim's LdaModel`_ uses, but its iteration can be computed much faster.
88
+ In addition, `tomotopy` can take advantage of multicore CPUs with a SIMD instruction set, which can result in faster iterations.
89
+
90
+ .. _gensim's LdaModel: https://radimrehurek.com/gensim/models/ldamodel.html
91
+
92
+ Following chart shows the comparison of LDA model's running time between `tomotopy` and `gensim`.
93
+ The input data consists of 1000 random documents from English Wikipedia with 1,506,966 words (about 10.1 MB).
94
+ `tomotopy` trains 200 iterations and `gensim` trains 10 iterations.
95
+
96
+ .. image:: https://bab2min.github.io/tomotopy/images/tmt_i5.png
97
+
98
+ Performance in Intel i5-6600, x86-64 (4 cores)
99
+
100
+ .. image:: https://bab2min.github.io/tomotopy/images/tmt_xeon.png
101
+
102
+ Performance in Intel Xeon E5-2620 v4, x86-64 (8 cores, 16 threads)
103
+
104
+ Although `tomotopy` iterated 20 times more, the overall running time was 5~10 times faster than `gensim`. And it yields a stable result.
105
+
106
+ It is difficult to compare CGS and VB directly because they are totaly different techniques.
107
+ But from a practical point of view, we can compare the speed and the result between them.
108
+ The following chart shows the log-likelihood per word of two models' result.
109
+
110
+ .. image:: https://bab2min.github.io/tomotopy/images/LLComp.png
111
+
112
+ The SIMD instruction set has a great effect on performance. Following is a comparison between SIMD instruction sets.
113
+
114
+ .. image:: https://bab2min.github.io/tomotopy/images/SIMDComp.png
115
+
116
+ Fortunately, most of recent x86-64 CPUs provide AVX2 instruction set, so we can enjoy the performance of AVX2.
117
+
118
+ Model Save and Load
119
+ -------------------
120
+ `tomotopy` provides `save` and `load` method for each topic model class,
121
+ so you can save the model into the file whenever you want, and re-load it from the file.
122
+ ::
123
+
124
+ import tomotopy as tp
125
+
126
+ mdl = tp.HDPModel()
127
+ for line in open('sample.txt'):
128
+ mdl.add_doc(line.strip().split())
129
+
130
+ for i in range(0, 100, 10):
131
+ mdl.train(10)
132
+ print('Iteration: {}\tLog-likelihood: {}'.format(i, mdl.ll_per_word))
133
+
134
+ # save into file
135
+ mdl.save('sample_hdp_model.bin')
136
+
137
+ # load from file
138
+ mdl = tp.HDPModel.load('sample_hdp_model.bin')
139
+ for k in range(mdl.k):
140
+ if not mdl.is_live_topic(k): continue
141
+ print('Top 10 words of topic #{}'.format(k))
142
+ print(mdl.get_topic_words(k, top_n=10))
143
+
144
+ # the saved model is HDP model,
145
+ # so when you load it by LDA model, it will raise an exception
146
+ mdl = tp.LDAModel.load('sample_hdp_model.bin')
147
+
148
+ When you load the model from a file, a model type in the file should match the class of methods.
149
+
150
+ See more at `tomotopy.LDAModel.save` and `tomotopy.LDAModel.load` methods.
151
+
152
+ Interactive Model Viewer
153
+ ------------------------
154
+
155
+ You can see the result of modeling using the interactive viewer since v0.13.0.
156
+ See the _ for a demo video.
157
+
158
+ ::
159
+
160
+ import tomotopy as tp
161
+ model = tp.LDAModel(...)
162
+ # ... some training codes ...
163
+ tp.viewer.open_viewer(model, host="localhost", port=9999)
164
+ # And open http://localhost:9999 in your web browser!
165
+
166
+ If you have a saved model file, you can also use the following command line.
167
+
168
+ ::
169
+
170
+ python -m tomotopy.viewer a_trained_model.bin --host localhost --port 9999
171
+
172
+ See more at `tomotopy.viewer` module.
173
+
174
+ Documents in the Model and out of the Model
175
+ -------------------------------------------
176
+ We can use Topic Model for two major purposes.
177
+ The basic one is to discover topics from a set of documents as a result of trained model,
178
+ and the more advanced one is to infer topic distributions for unseen documents by using trained model.
179
+
180
+ We named the document in the former purpose (used for model training) as **document in the model**,
181
+ and the document in the later purpose (unseen document during training) as **document out of the model**.
182
+
183
+ In `tomotopy`, these two different kinds of document are generated differently.
184
+ A **document in the model** can be created by `tomotopy.LDAModel.add_doc` method.
185
+ `add_doc` can be called before `tomotopy.LDAModel.train` starts.
186
+ In other words, after `train` called, `add_doc` cannot add a document into the model because the set of document used for training has become fixed.
187
+
188
+ To acquire the instance of the created document, you should use `tomotopy.LDAModel.docs` like:
189
+
190
+ ::
191
+
192
+ mdl = tp.LDAModel(k=20)
193
+ idx = mdl.add_doc(words)
194
+ if idx < 0: raise RuntimeError("Failed to add doc")
195
+ doc_inst = mdl.docs[idx]
196
+ # doc_inst is an instance of the added document
197
+
198
+ A **document out of the model** is generated by `tomotopy.LDAModel.make_doc` method. `make_doc` can be called only after `train` starts.
199
+ If you use `make_doc` before the set of document used for training has become fixed, you may get wrong results.
200
+ Since `make_doc` returns the instance directly, you can use its return value for other manipulations.
201
+
202
+ ::
203
+
204
+ mdl = tp.LDAModel(k=20)
205
+ # add_doc ...
206
+ mdl.train(100)
207
+ doc_inst = mdl.make_doc(unseen_doc) # doc_inst is an instance of the unseen document
208
+
209
+ Inference for Unseen Documents
210
+ ------------------------------
211
+ If a new document is created by `tomotopy.LDAModel.make_doc`, its topic distribution can be inferred by the model.
212
+ Inference for unseen document should be performed using `tomotopy.LDAModel.infer` method.
213
+
214
+ ::
215
+
216
+ mdl = tp.LDAModel(k=20)
217
+ # add_doc ...
218
+ mdl.train(100)
219
+ doc_inst = mdl.make_doc(unseen_doc)
220
+ topic_dist, ll = mdl.infer(doc_inst)
221
+ print("Topic Distribution for Unseen Docs: ", topic_dist)
222
+ print("Log-likelihood of inference: ", ll)
223
+
224
+ The `infer` method can infer only one instance of `tomotopy.Document` or a `list` of instances of `tomotopy.Document`.
225
+ See more at `tomotopy.LDAModel.infer`.
226
+
227
+ Corpus and transform
228
+ --------------------
229
+ Every topic model in `tomotopy` has its own internal document type.
230
+ A document can be created and added into suitable for each model through each model's `add_doc` method.
231
+ However, trying to add the same list of documents to different models becomes quite inconvenient,
232
+ because `add_doc` should be called for the same list of documents to each different model.
233
+ Thus, `tomotopy` provides `tomotopy.utils.Corpus` class that holds a list of documents.
234
+ `tomotopy.utils.Corpus` can be inserted into any model by passing as argument `corpus` to `__init__` or `add_corpus` method of each model.
235
+ So, inserting `tomotopy.utils.Corpus` just has the same effect to inserting documents the corpus holds.
236
+
237
+ Some topic models requires different data for its documents.
238
+ For example, `tomotopy.DMRModel` requires argument `metadata` in `str` type,
239
+ but `tomotopy.PLDAModel` requires argument `labels` in `List[str]` type.
240
+ Since `tomotopy.utils.Corpus` holds an independent set of documents rather than being tied to a specific topic model,
241
+ data types required by a topic model may be inconsistent when a corpus is added into that topic model.
242
+ In this case, miscellaneous data can be transformed to be fitted target topic model using argument `transform`.
243
+ See more details in the following code:
244
+
245
+ ::
246
+
247
+ from tomotopy import DMRModel
248
+ from tomotopy.utils import Corpus
249
+
250
+ corpus = Corpus()
251
+ corpus.add_doc("a b c d e".split(), a_data=1)
252
+ corpus.add_doc("e f g h i".split(), a_data=2)
253
+ corpus.add_doc("i j k l m".split(), a_data=3)
254
+
255
+ model = DMRModel(k=10)
256
+ model.add_corpus(corpus)
257
+ # You lose `a_data` field in `corpus`,
258
+ # and `metadata` that `DMRModel` requires is filled with the default value, empty str.
259
+
260
+ assert model.docs[0].metadata == ''
261
+ assert model.docs[1].metadata == ''
262
+ assert model.docs[2].metadata == ''
263
+
264
+ def transform_a_data_to_metadata(misc: dict):
265
+ return {'metadata': str(misc['a_data'])}
266
+ # this function transforms `a_data` to `metadata`
267
+
268
+ model = DMRModel(k=10)
269
+ model.add_corpus(corpus, transform=transform_a_data_to_metadata)
270
+ # Now docs in `model` has non-default `metadata`, that generated from `a_data` field.
271
+
272
+ assert model.docs[0].metadata == '1'
273
+ assert model.docs[1].metadata == '2'
274
+ assert model.docs[2].metadata == '3'
275
+
276
+ Parallel Sampling Algorithms
277
+ ----------------------------
278
+ Since version 0.5.0, `tomotopy` allows you to choose a parallelism algorithm.
279
+ The algorithm provided in versions prior to 0.4.2 is `COPY_MERGE`, which is provided for all topic models.
280
+ The new algorithm `PARTITION`, available since 0.5.0, makes training generally faster and more memory-efficient, but it is available at not all topic models.
281
+
282
+ The following chart shows the speed difference between the two algorithms based on the number of topics and the number of workers.
283
+
284
+ .. image:: https://bab2min.github.io/tomotopy/images/algo_comp.png
285
+
286
+ .. image:: https://bab2min.github.io/tomotopy/images/algo_comp2.png
287
+
288
+ Performance by Version
289
+ ----------------------
290
+ Performance changes by version are shown in the following graph.
291
+ The time it takes to run the LDA model train with 1000 iteration was measured.
292
+ (Docs: 11314, Vocab: 60382, Words: 2364724, Intel Xeon Gold 5120 @2.2GHz)
293
+
294
+ .. image:: https://bab2min.github.io/tomotopy/images/lda-perf-t1.png
295
+
296
+ .. image:: https://bab2min.github.io/tomotopy/images/lda-perf-t4.png
297
+
298
+ .. image:: https://bab2min.github.io/tomotopy/images/lda-perf-t8.png
299
+
300
+ Pining Topics using Word Priors
301
+ -------------------------------
302
+ Since version 0.6.0, a new method `tomotopy.LDAModel.set_word_prior` has been added. It allows you to control word prior for each topic.
303
+ For example, we can set the weight of the word 'church' to 1.0 in topic 0, and the weight to 0.1 in the rest of the topics by following codes.
304
+ This means that the probability that the word 'church' is assigned to topic 0 is 10 times higher than the probability of being assigned to another topic.
305
+ Therefore, most of 'church' is assigned to topic 0, so topic 0 contains many words related to 'church'.
306
+ This allows to manipulate some topics to be placed at a specific topic number.
307
+
308
+ ::
309
+
310
+ import tomotopy as tp
311
+ mdl = tp.LDAModel(k=20)
312
+
313
+ # add documents into `mdl`
314
+
315
+ # setting word prior
316
+ mdl.set_word_prior('church', [1.0 if k == 0 else 0.1 for k in range(20)])
317
+
318
+ See `word_prior_example` in `example.py` for more details.
319
+
320
+
321
+ Examples
322
+ --------
323
+ You can find an example python code of tomotopy at https://github.com/bab2min/tomotopy/blob/main/examples/ .
324
+
325
+ You can also get the data file used in the example code at https://drive.google.com/file/d/18OpNijd4iwPyYZ2O7pQoPyeTAKEXa71J/view .
326
+
327
+ License
328
+ ---------
329
+ `tomotopy` is licensed under the terms of MIT License,
330
+ meaning you can use it for any reasonable purpose and remain in complete ownership of all the documentation you produce.
331
+
332
+ History
333
+ -------
334
+ * 0.13.0 (2024-08-05)
335
+ * New features
336
+ * Major features of Topic Model Viewer `tomotopy.viewer.open_viewer()` are ready now.
337
+ * `tomotopy.LDAModel.get_hash()` is added. You can get 128bit hash value of the model.
338
+ * Add an argument `ngram_list` to `tomotopy.utils.SimpleTokenizer`.
339
+ * Bug fixes
340
+ * Fixed inconsistent `spans` bug after `Corpus.concat_ngrams` is called.
341
+ * Optimized the bottleneck of `tomotopy.LDAModel.load()` and `tomotopy.LDAModel.save()` and improved its speed more than 10 times.
342
+
343
+ * 0.12.7 (2023-12-19)
344
+ * New features
345
+ * Added Topic Model Viewer `tomotopy.viewer.open_viewer()`
346
+ * Optimized the performance of `tomotopy.utils.Corpus.process()`
347
+ * Bug fixes
348
+ * `Document.span` now returns the ranges in character unit, not in byte unit.
349
+
350
+ * 0.12.6 (2023-12-11)
351
+ * New features
352
+ * Added some convenience features to `tomotopy.LDAModel.train` and `tomotopy.LDAModel.set_word_prior`.
353
+ * `LDAModel.train` now has new arguments `callback`, `callback_interval` and `show_progres` to monitor the training progress.
354
+ * `LDAModel.set_word_prior` now can accept `Dict[int, float]` type as its argument `prior`.
355
+
356
+ * 0.12.5 (2023-08-03)
357
+ * New features
358
+ * Added support for Linux ARM64 architecture.
359
+
360
+ * 0.12.4 (2023-01-22)
361
+ * New features
362
+ * Added support for macOS ARM64 architecture.
363
+ * Bug fixes
364
+ * Fixed an issue where `tomotopy.Document.get_sub_topic_dist()` raises a bad argument exception.
365
+ * Fixed an issue where exception raising sometimes causes crashes.
366
+
367
+ * 0.12.3 (2022-07-19)
368
+ * New features
369
+ * Now, inserting an empty document using `tomotopy.LDAModel.add_doc()` just ignores it instead of raising an exception. If the newly added argument `ignore_empty_words` is set to False, an exception is raised as before.
370
+ * `tomotopy.HDPModel.purge_dead_topics()` method is added to remove non-live topics from the model.
371
+ * Bug fixes
372
+ * Fixed an issue that prevents setting user defined values for nuSq in `tomotopy.SLDAModel` (by @jucendrero).
373
+ * Fixed an issue where `tomotopy.utils.Coherence` did not work for `tomotopy.DTModel`.
374
+ * Fixed an issue that often crashed when calling `make_dic()` before calling `train()`.
375
+ * Resolved the problem that the results of `tomotopy.DMRModel` and `tomotopy.GDMRModel` are different even when the seed is fixed.
376
+ * The parameter optimization process of `tomotopy.DMRModel` and `tomotopy.GDMRModel` has been improved.
377
+ * Fixed an issue that sometimes crashed when calling `tomotopy.PTModel.copy()`.
378
+
379
+ * 0.12.2 (2021-09-06)
380
+ * An issue where calling `convert_to_lda` of `tomotopy.HDPModel` with `min_cf > 0`, `min_df > 0` or `rm_top > 0` causes a crash has been fixed.
381
+ * A new argument `from_pseudo_doc` is added to `tomotopy.Document.get_topics` and `tomotopy.Document.get_topic_dist`.
382
+ This argument is only valid for documents of `PTModel`, it enables to control a source for computing topic distribution.
383
+ * A default value for argument `p` of `tomotopy.PTModel` has been changed. The new default value is `k * 10`.
384
+ * Using documents generated by `make_doc` without calling `infer` doesn't cause a crash anymore, but just print warning messages.
385
+ * An issue where the internal C++ code isn't compiled at clang c++17 environment has been fixed.
386
+
387
+ * 0.12.1 (2021-06-20)
388
+ * An issue where `tomotopy.LDAModel.set_word_prior()` causes a crash has been fixed.
389
+ * Now `tomotopy.LDAModel.perplexity` and `tomotopy.LDAModel.ll_per_word` return the accurate value when `TermWeight` is not `ONE`.
390
+ * `tomotopy.LDAModel.used_vocab_weighted_freq` was added, which returns term-weighted frequencies of words.
391
+ * Now `tomotopy.LDAModel.summary()` shows not only the entropy of words, but also the entropy of term-weighted words.
392
+
393
+ * 0.12.0 (2021-04-26)
394
+ * Now `tomotopy.DMRModel` and `tomotopy.GDMRModel` support multiple values of metadata (see https://github.com/bab2min/tomotopy/blob/main/examples/dmr_multi_label.py )
395
+ * The performance of `tomotopy.GDMRModel` was improved.
396
+ * A `copy()` method has been added for all topic models to do a deep copy.
397
+ * An issue was fixed where words that are excluded from training (by `min_cf`, `min_df`) have incorrect topic id. Now all excluded words have `-1` as topic id.
398
+ * Now all exceptions and warnings that generated by `tomotopy` follow standard Python types.
399
+ * Compiler requirements have been raised to C++14.
400
+
401
+ * 0.11.1 (2021-03-28)
402
+ * A critical bug of asymmetric alphas was fixed. Due to this bug, version 0.11.0 has been removed from releases.
403
+
404
+ * 0.11.0 (2021-03-26) (removed)
405
+ * A new topic model `tomotopy.PTModel` for short texts was added into the package.
406
+ * An issue was fixed where `tomotopy.HDPModel.infer` causes a segmentation fault sometimes.
407
+ * A mismatch of numpy API version was fixed.
408
+ * Now asymmetric document-topic priors are supported.
409
+ * Serializing topic models to `bytes` in memory is supported.
410
+ * An argument `normalize` was added to `get_topic_dist()`, `get_topic_word_dist()` and `get_sub_topic_dist()` for controlling normalization of results.
411
+ * Now `tomotopy.DMRModel.lambdas` and `tomotopy.DMRModel.alpha` give correct values.
412
+ * Categorical metadata supports for `tomotopy.GDMRModel` were added (see https://github.com/bab2min/tomotopy/blob/main/examples/gdmr_both_categorical_and_numerical.py ).
413
+ * Python3.5 support was dropped.
414
+
415
+ * 0.10.2 (2021-02-16)
416
+ * An issue was fixed where `tomotopy.CTModel.train` fails with large K.
417
+ * An issue was fixed where `tomotopy.utils.Corpus` loses their `uid` values.
418
+
419
+ * 0.10.1 (2021-02-14)
420
+ * An issue was fixed where `tomotopy.utils.Corpus.extract_ngrams` craches with empty input.
421
+ * An issue was fixed where `tomotopy.LDAModel.infer` raises exception with valid input.
422
+ * An issue was fixed where `tomotopy.HLDAModel.infer` generates wrong `tomotopy.Document.path`.
423
+ * Since a new parameter `freeze_topics` for `tomotopy.HLDAModel.train` was added, you can control whether to create a new topic or not when training.
424
+
425
+ * 0.10.0 (2020-12-19)
426
+ * The interface of `tomotopy.utils.Corpus` and of `tomotopy.LDAModel.docs` were unified. Now you can access the document in corpus with the same manner.
427
+ * `__getitem__` of `tomotopy.utils.Corpus` was improved. Not only indexing by int, but also by Iterable[int], slicing are supported. Also indexing by uid is supported.
428
+ * New methods `tomotopy.utils.Corpus.extract_ngrams` and `tomotopy.utils.Corpus.concat_ngrams` were added. They extracts n-gram collocations using PMI and concatenates them into a single words.
429
+ * A new method `tomotopy.LDAModel.add_corpus` was added, and `tomotopy.LDAModel.infer` can receive corpus as input.
430
+ * A new module `tomotopy.coherence` was added. It provides the way to calculate coherence of the model.
431
+ * A paramter `window_size` was added to `tomotopy.label.FoRelevance`.
432
+ * An issue was fixed where NaN often occurs when training `tomotopy.HDPModel`.
433
+ * Now Python3.9 is supported.
434
+ * A dependency to py-cpuinfo was removed and the initializing of the module was improved.
435
+
436
+ * 0.9.1 (2020-08-08)
437
+ * Memory leaks of version 0.9.0 was fixed.
438
+ * `tomotopy.CTModel.summary()` was fixed.
439
+
440
+ * 0.9.0 (2020-08-04)
441
+ * The `tomotopy.LDAModel.summary()` method, which prints human-readable summary of the model, has been added.
442
+ * The random number generator of package has been replaced with `EigenRand`_. It speeds up the random number generation and solves the result difference between platforms.
443
+ * Due to above, even if `seed` is the same, the model training result may be different from the version before 0.9.0.
444
+ * Fixed a training error in `tomotopy.HDPModel`.
445
+ * `tomotopy.DMRModel.alpha` now shows Dirichlet prior of per-document topic distribution by metadata.
446
+ * `tomotopy.DTModel.get_count_by_topics()` has been modified to return a 2-dimensional `ndarray`.
447
+ * `tomotopy.DTModel.alpha` has been modified to return the same value as `tomotopy.DTModel.get_alpha()`.
448
+ * Fixed an issue where the `metadata` value could not be obtained for the document of `tomotopy.GDMRModel`.
449
+ * `tomotopy.HLDAModel.alpha` now shows Dirichlet prior of per-document depth distribution.
450
+ * `tomotopy.LDAModel.global_step` has been added.
451
+ * `tomotopy.MGLDAModel.get_count_by_topics()` now returns the word count for both global and local topics.
452
+ * `tomotopy.PAModel.alpha`, `tomotopy.PAModel.subalpha`, and `tomotopy.PAModel.get_count_by_super_topic()` have been added.
453
+
454
+ .. _EigenRand: https://github.com/bab2min/EigenRand
455
+
456
+ * 0.8.2 (2020-07-14)
457
+ * New properties `tomotopy.DTModel.num_timepoints` and `tomotopy.DTModel.num_docs_by_timepoint` have been added.
458
+ * A bug which causes different results with the different platform even if `seeds` were the same was partially fixed.
459
+ As a result of this fix, now `tomotopy` in 32 bit yields different training results from earlier version.
460
+
461
+ * 0.8.1 (2020-06-08)
462
+ * A bug where `tomotopy.LDAModel.used_vocabs` returned an incorrect value was fixed.
463
+ * Now `tomotopy.CTModel.prior_cov` returns a covariance matrix with shape `[k, k]`.
464
+ * Now `tomotopy.CTModel.get_correlations` with empty arguments returns a correlation matrix with shape `[k, k]`.
465
+
466
+ * 0.8.0 (2020-06-06)
467
+ * Since NumPy was introduced in tomotopy, many methods and properties of tomotopy return not just `list`, but `numpy.ndarray` now.
468
+ * Tomotopy has a new dependency `NumPy >= 1.10.0`.
469
+ * A wrong estimation of `tomotopy.HDPModel.infer` was fixed.
470
+ * A new method about converting HDPModel to LDAModel was added.
471
+ * New properties including `tomotopy.LDAModel.used_vocabs`, `tomotopy.LDAModel.used_vocab_freq` and `tomotopy.LDAModel.used_vocab_df` were added into topic models.
472
+ * A new g-DMR topic model(`tomotopy.GDMRModel`) was added.
473
+ * An error at initializing `tomotopy.label.FoRelevance` in macOS was fixed.
474
+ * An error that occured when using `tomotopy.utils.Corpus` created without `raw` parameters was fixed.
475
+
476
+ * 0.7.1 (2020-05-08)
477
+ * `tomotopy.Document.path` was added for `tomotopy.HLDAModel`.
478
+ * A memory corruption bug in `tomotopy.label.PMIExtractor` was fixed.
479
+ * A compile error in gcc 7 was fixed.
480
+
481
+ * 0.7.0 (2020-04-18)
482
+ * `tomotopy.DTModel` was added into the package.
483
+ * A bug in `tomotopy.utils.Corpus.save` was fixed.
484
+ * A new method `tomotopy.Document.get_count_vector` was added into Document class.
485
+ * Now linux distributions use manylinux2010 and an additional optimization is applied.
486
+
487
+ * 0.6.2 (2020-03-28)
488
+ * A critical bug related to `save` and `load` was fixed. Version 0.6.0 and 0.6.1 have been removed from releases.
489
+
490
+ * 0.6.1 (2020-03-22) (removed)
491
+ * A bug related to module loading was fixed.
492
+
493
+ * 0.6.0 (2020-03-22) (removed)
494
+ * `tomotopy.utils.Corpus` class that manages multiple documents easily was added.
495
+ * `tomotopy.LDAModel.set_word_prior` method that controls word-topic priors of topic models was added.
496
+ * A new argument `min_df` that filters words based on document frequency was added into every topic model's __init__.
497
+ * `tomotopy.label`, the submodule about topic labeling was added. Currently, only `tomotopy.label.FoRelevance` is provided.
498
+
499
+ * 0.5.2 (2020-03-01)
500
+ * A segmentation fault problem was fixed in `tomotopy.LLDAModel.add_doc`.
501
+ * A bug was fixed that `infer` of `tomotopy.HDPModel` sometimes crashes the program.
502
+ * A crash issue was fixed of `tomotopy.LDAModel.infer` with ps=tomotopy.ParallelScheme.PARTITION, together=True.
503
+
504
+ * 0.5.1 (2020-01-11)
505
+ * A bug was fixed that `tomotopy.SLDAModel.make_doc` doesn't support missing values for `y`.
506
+ * Now `tomotopy.SLDAModel` fully supports missing values for response variables `y`. Documents with missing values (NaN) are included in modeling topic, but excluded from regression of response variables.
507
+
508
+ * 0.5.0 (2019-12-30)
509
+ * Now `tomotopy.PAModel.infer` returns both topic distribution nd sub-topic distribution.
510
+ * New methods get_sub_topics and get_sub_topic_dist were added into `tomotopy.Document`. (for PAModel)
511
+ * New parameter `parallel` was added for `tomotopy.LDAModel.train` and `tomotopy.LDAModel.infer` method. You can select parallelism algorithm by changing this parameter.
512
+ * `tomotopy.ParallelScheme.PARTITION`, a new algorithm, was added. It works efficiently when the number of workers is large, the number of topics or the size of vocabulary is big.
513
+ * A bug where `rm_top` didn't work at `min_cf` < 2 was fixed.
514
+
515
+ * 0.4.2 (2019-11-30)
516
+ * Wrong topic assignments of `tomotopy.LLDAModel` and `tomotopy.PLDAModel` were fixed.
517
+ * Readable __repr__ of `tomotopy.Document` and `tomotopy.Dictionary` was implemented.
518
+
519
+ * 0.4.1 (2019-11-27)
520
+ * A bug at init function of `tomotopy.PLDAModel` was fixed.
521
+
522
+ * 0.4.0 (2019-11-18)
523
+ * New models including `tomotopy.PLDAModel` and `tomotopy.HLDAModel` were added into the package.
524
+
525
+ * 0.3.1 (2019-11-05)
526
+ * An issue where `get_topic_dist()` returns incorrect value when `min_cf` or `rm_top` is set was fixed.
527
+ * The return value of `get_topic_dist()` of `tomotopy.MGLDAModel` document was fixed to include local topics.
528
+ * The estimation speed with `tw=ONE` was improved.
529
+
530
+ * 0.3.0 (2019-10-06)
531
+ * A new model, `tomotopy.LLDAModel` was added into the package.
532
+ * A crashing issue of `HDPModel` was fixed.
533
+ * Since hyperparameter estimation for `HDPModel` was implemented, the result of `HDPModel` may differ from previous versions.
534
+ If you want to turn off hyperparameter estimation of HDPModel, set `optim_interval` to zero.
535
+
536
+ * 0.2.0 (2019-08-18)
537
+ * New models including `tomotopy.CTModel` and `tomotopy.SLDAModel` were added into the package.
538
+ * A new parameter option `rm_top` was added for all topic models.
539
+ * The problems in `save` and `load` method for `PAModel` and `HPAModel` were fixed.
540
+ * An occassional crash in loading `HDPModel` was fixed.
541
+ * The problem that `ll_per_word` was calculated incorrectly when `min_cf` > 0 was fixed.
542
+
543
+ * 0.1.6 (2019-08-09)
544
+ * Compiling errors at clang with macOS environment were fixed.
545
+
546
+ * 0.1.4 (2019-08-05)
547
+ * The issue when `add_doc` receives an empty list as input was fixed.
548
+ * The issue that `tomotopy.PAModel.get_topic_words` doesn't extract the word distribution of subtopic was fixed.
549
+
550
+ * 0.1.3 (2019-05-19)
551
+ * The parameter `min_cf` and its stopword-removing function were added for all topic models.
552
+
553
+ * 0.1.0 (2019-05-12)
554
+ * First version of **tomotopy**
555
+
556
+ Bindings for Other Languages
557
+ ------------------------------
558
+ * Ruby: https://github.com/ankane/tomoto
559
+
560
+ Bundled Libraries and Their License
561
+ ------------------------------------
562
+ * Eigen:
563
+ This application uses the MPL2-licensed features of Eigen, a C++ template library for linear algebra.
564
+ A copy of the MPL2 license is available at https://www.mozilla.org/en-US/MPL/2.0/.
565
+ The source code of the Eigen library can be obtained at http://eigen.tuxfamily.org/.
566
+
567
+ * EigenRand: `MIT License
568
+ <licenses_bundled/EigenRand>`_
569
+
570
+ Citation
571
+ ---------
572
+ ::
573
+
574
+ @software{minchul_lee_2022_6868418,
575
+ author = {Minchul Lee},
576
+ title = {bab2min/tomotopy: 0.12.3},
577
+ month = jul,
578
+ year = 2022,
579
+ publisher = {Zenodo},
580
+ version = {v0.12.3},
581
+ doi = {10.5281/zenodo.6868418},
582
+ url = {https://doi.org/10.5281/zenodo.6868418}
583
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020, bab2min
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -24,7 +24,7 @@ namespace tomoto
24
24
  {
25
25
  public:
26
26
  using DefaultDocType = DocumentCTM<TermWeight::one>;
27
- static ICTModel* create(TermWeight _weight, const CTArgs& args,
27
+ static std::unique_ptr<ICTModel> create(TermWeight _weight, const CTArgs& args,
28
28
  bool scalarRng = false);
29
29
 
30
30
  virtual void setNumBetaSample(size_t numSample) = 0;
@@ -7,7 +7,7 @@ namespace tomoto
7
7
 
8
8
  TMT_INSTANTIATE_DOC(DocumentCTM);
9
9
 
10
- ICTModel* ICTModel::create(TermWeight _weight, const CTArgs& args, bool scalarRng)
10
+ std::unique_ptr<ICTModel> ICTModel::create(TermWeight _weight, const CTArgs& args, bool scalarRng)
11
11
  {
12
12
  TMT_SWITCH_TW(_weight, scalarRng, CTModel, args);
13
13
  }
@@ -32,7 +32,7 @@ namespace tomoto
32
32
  {
33
33
  public:
34
34
  using DefaultDocType = DocumentDMR<TermWeight::one>;
35
- static IDMRModel* create(TermWeight _weight, const DMRArgs& args,
35
+ static std::unique_ptr<IDMRModel> create(TermWeight _weight, const DMRArgs& args,
36
36
  bool scalarRng = false);
37
37
 
38
38
  virtual void setAlphaEps(Float _alphaEps) = 0;
@@ -7,7 +7,7 @@ namespace tomoto
7
7
 
8
8
  TMT_INSTANTIATE_DOC(DocumentDMR);
9
9
 
10
- IDMRModel* IDMRModel::create(TermWeight _weight, const DMRArgs& args, bool scalarRng)
10
+ std::unique_ptr<IDMRModel> IDMRModel::create(TermWeight _weight, const DMRArgs& args, bool scalarRng)
11
11
  {
12
12
  TMT_SWITCH_TW(_weight, scalarRng, DMRModel, args);
13
13
  }
@@ -45,7 +45,7 @@ namespace tomoto
45
45
  {
46
46
  public:
47
47
  using DefaultDocType = DocumentDTM<TermWeight::one>;
48
- static IDTModel* create(TermWeight _weight, const DTArgs& args,
48
+ static std::unique_ptr<IDTModel> create(TermWeight _weight, const DTArgs& args,
49
49
  bool scalarRng = false);
50
50
 
51
51
  virtual size_t getT() const = 0;
@@ -7,7 +7,7 @@ namespace tomoto
7
7
 
8
8
  TMT_INSTANTIATE_DOC(DocumentDTM);
9
9
 
10
- IDTModel* IDTModel::create(TermWeight _weight, const DTArgs& args, bool scalarRng)
10
+ std::unique_ptr<IDTModel> IDTModel::create(TermWeight _weight, const DTArgs& args, bool scalarRng)
11
11
  {
12
12
  TMT_SWITCH_TW(_weight, scalarRng, DTModel, args);
13
13
  }
@@ -32,7 +32,7 @@ namespace tomoto
32
32
  {
33
33
  public:
34
34
  using DefaultDocType = DocumentDMR<TermWeight::one>;
35
- static IGDMRModel* create(TermWeight _weight, const GDMRArgs& args,
35
+ static std::unique_ptr<IGDMRModel> create(TermWeight _weight, const GDMRArgs& args,
36
36
  bool scalarRng = false);
37
37
 
38
38
  virtual Float getSigma0() const = 0;