You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ValueError: perplexity must be less than n_samples #6
When the topic number is more than 30 (which is the TSNE's default perplexity setting), the ValueError occurs.
ValueError: perplexity must be less than n_samples
Maybe we shall simply set perplexity to 5, or change it according to the number of topics (e.g. add an n_topic variable to the _report() and _distance() methods)
@caicai555 I have pushed a fixing commit. Could you please test it?
Just upgraded tmplot to 0.0.9 and tested with the same data, which worked when I simply set perplexity of tsne to 5 in the 0.0.8 version. Another error occurs...
AttributeError Traceback (most recent call last)
<ipython-input-5-b777329f9dd5> in <module>
1 import tmplot as tmp
----> 2 tmp.report(model=model, docs=texts)
D:\anaconda\lib\site-packages\tmplot\_report.py in report(model, docs, topics_labels, corpus, layout, show_headers, show_docs, show_words, show_topics, topics_kws, height, width, coords_kws, words_kws, docs_kws, top_docs_kws)
135
136 if 'topics_coords' not in _topics_kws:
--> 137 topics_coords = prepare_coords(model, **_coords_kws)
138 _topics_kws.update({
139 'topics_coords': topics_coords,
D:\anaconda\lib\site-packages\tmplot\_report.py in prepare_coords(model, labels, dist_kws, scatter_kws)
42 theta = get_theta(model)
43 topics_dists = get_topics_dist(phi, **dist_kws)
---> 44 topics_coords = get_topics_scatter(topics_dists, theta, **scatter_kws)
45 topics_coords['label'] = labels or theta.index
46 return topics_coords
D:\anaconda\lib\site-packages\tmplot\_distance.py in get_topics_scatter(topic_dists, theta, method, method_kws)
175 transformer = Isomap(**method_kws)
176
--> 177 coords = transformer.fit_transform(topic_dists)
178
179 topics_xy = DataFrame(coords, columns=['x', 'y'])
D:\anaconda\lib\site-packages\sklearn\manifold\_t_sne.py in fit_transform(self, X, y)
1121 """
1122 self._check_params_vs_input(X)
-> 1123 embedding = self._fit(X)
1124 self.embedding_ = embedding
1125 return self.embedding_
D:\anaconda\lib\site-packages\sklearn\manifold\_t_sne.py in _fit(self, X, skip_num_points)
960
961 t0 = time()
--> 962 distances_nn = knn.kneighbors_graph(mode="distance")
963 duration = time() - t0
964 if self.verbose:
D:\anaconda\lib\site-packages\sklearn\neighbors\_base.py in kneighbors_graph(self, X, n_neighbors, mode)
922
923 elif mode == "distance":
--> 924 A_data, A_ind = self.kneighbors(X, n_neighbors, return_distance=True)
925 A_data = np.ravel(A_data)
926
D:\anaconda\lib\site-packages\sklearn\neighbors\_base.py in kneighbors(self, X, n_neighbors, return_distance)
761 )
762 if use_pairwise_distances_reductions:
--> 763 results = PairwiseDistancesArgKmin.compute(
764 X=X,
765 Y=self._fit_X,
sklearn\metrics\_pairwise_distances_reduction.pyx in sklearn.metrics._pairwise_distances_reduction.PairwiseDistancesArgKmin.compute()
D:\anaconda\lib\site-packages\sklearn\utils\fixes.py in threadpool_limits(limits, user_api)
149 return controller.limit(limits=limits, user_api=user_api)
150 else:
--> 151 return threadpoolctl.threadpool_limits(limits=limits, user_api=user_api)
152
153
D:\anaconda\lib\site-packages\threadpoolctl.py in __init__(self, limits, user_api)
169 self._check_params(limits, user_api)
170
--> 171 self._original_info = self._set_threadpool_limits()
172
173 def __enter__(self):
D:\anaconda\lib\site-packages\threadpoolctl.py in _set_threadpool_limits(self)
266 return None
267
--> 268 modules = _ThreadpoolInfo(prefixes=self._prefixes,
269 user_api=self._user_api)
270 for module in modules:
D:\anaconda\lib\site-packages\threadpoolctl.py in __init__(self, user_api, prefixes, modules)
338
339 self.modules = []
--> 340 self._load_modules()
341 self._warn_if_incompatible_openmp()
342 else:
D:\anaconda\lib\site-packages\threadpoolctl.py in _load_modules(self)
371 self._find_modules_with_dyld()
372 elif sys.platform == "win32":
--> 373 self._find_modules_with_enum_process_module_ex()
374 else:
375 self._find_modules_with_dl_iterate_phdr()
D:\anaconda\lib\site-packages\threadpoolctl.py in _find_modules_with_enum_process_module_ex(self)
483
484 # Store the module if it is supported and selected
--> 485 self._make_module_from_path(filepath)
486 finally:
487 kernel_32.CloseHandle(h_process)
D:\anaconda\lib\site-packages\threadpoolctl.py in _make_module_from_path(self, filepath)
513 if prefix in self.prefixes or user_api in self.user_api:
514 module_class = globals()[module_class]
--> 515 module = module_class(filepath, prefix, user_api, internal_api)
516 self.modules.append(module)
517
D:\anaconda\lib\site-packages\threadpoolctl.py in __init__(self, filepath, prefix, user_api, internal_api)
604 self.internal_api = internal_api
605 self._dynlib = ctypes.CDLL(filepath, mode=_RTLD_NOLOAD)
--> 606 self.version = self.get_version()
607 self.num_threads = self.get_num_threads()
608 self._get_extra_info()
D:\anaconda\lib\site-packages\threadpoolctl.py in get_version(self)
644 lambda: None)
645 get_config.restype = ctypes.c_char_p
--> 646 config = get_config().split()
647 if config[0] == b"OpenBLAS":
648 return config[1].decode("utf-8")
AttributeError: 'NoneType' object has no attribute 'split'
Thx for ur great effort and quick replies on this issue. If you need the exact model file, plz let me know :)
(BTW, I've tried to analyse my texts with your BitermPlus packet, concise and elegant, quite easy to get hang of it. However, I find the results turned out to be different with the same settings on R package BTM (https://github.com/bnosac/BTM) and BTMpy(https://github.com/jasperyang/BTMpy). The latter two gave the same topic distribution and the top words seem to make sense, but the BitermPlus' output is a bit confusing. I am a beginner in BTM and not sure what's behind the problem, maybe you could check it if you got the time?
PS: maybe I should leave an issue there but I don't want to annoy you xd
Thank you for your comments! I will try to reproduce this bug. By the way, what number of iterations have you used with bitermplus? The authors of algorithm refer to 2000 in their paper. I have found 600 to be more or less sufficient.
Thank you for your comments! I will try to reproduce this bug. By the way, what number of iterations have you used with bitermplus? The authors of algorithm refer to 2000 in their paper. I have found 600 to be more or less sufficient.
Due to time restrictions, I have only tried 200 iters maximum XD. I'll test with more iterations later when I return to my lab. What confused me the most is that the results differ even if I get all the settings exactly the same.
Activity
maximtrp commentedon Aug 19, 2022
You are right. Thank you! I will fix it in the next release (will try to make it soon).
maximtrp commentedon Aug 19, 2022
@caicai555 I have pushed a fixing commit. Could you please test it?
caicai555 commentedon Aug 22, 2022
Just upgraded tmplot to 0.0.9 and tested with the same data, which worked when I simply set perplexity of tsne to 5 in the 0.0.8 version. Another error occurs...
maximtrp commentedon Aug 25, 2022
Could you please post the code and data sample which give such an error?
caicai555 commentedon Aug 25, 2022
Just like this one I think. Here come the codes run on jupyter notebook with python=3.8.8
And here's part of the [texts] data, which should be innocent in this issue.
Thx for ur great effort and quick replies on this issue. If you need the exact model file, plz let me know :)
(BTW, I've tried to analyse my texts with your BitermPlus packet, concise and elegant, quite easy to get hang of it. However, I find the results turned out to be different with the same settings on R package BTM (https://github.com/bnosac/BTM) and BTMpy(https://github.com/jasperyang/BTMpy). The latter two gave the same topic distribution and the top words seem to make sense, but the BitermPlus' output is a bit confusing. I am a beginner in BTM and not sure what's behind the problem, maybe you could check it if you got the time?
PS: maybe I should leave an issue there but I don't want to annoy you xd
maximtrp commentedon Aug 26, 2022
Thank you for your comments! I will try to reproduce this bug. By the way, what number of iterations have you used with bitermplus? The authors of algorithm refer to 2000 in their paper. I have found 600 to be more or less sufficient.
caicai555 commentedon Aug 26, 2022
Due to time restrictions, I have only tried 200 iters maximum XD. I'll test with more iterations later when I return to my lab. What confused me the most is that the results differ even if I get all the settings exactly the same.
Thanks again for your warm help :)
fixed tsne perplexity error (#6, #9), minor code improvements, tests …