Download BERTopic/tests/test_plotting/test_approximate.py from kisejin/TopicModelingRepo: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/kisejin/TopicModelingRepo/resolve/5ecdc19ebac471cb51415c4e2fa755d81931c0ee/BERTopic/tests/test_plotting/test_approximate.py
- Command line
-
hf download hf://kisejin/TopicModelingRepo@5ecdc19ebac471cb51415c4e2fa755d81931c0ee/BERTopic/tests/test_plotting/test_approximate.py
-
curl -L -o test_approximate.py https://huggingface.co/kisejin/TopicModelingRepo/resolve/5ecdc19ebac471cb51415c4e2fa755d81931c0ee/BERTopic/tests/test_plotting/test_approximate.py
1.41 kB
| import copy | |
| import pytest | |
| def test_approximate_distribution(batch_size, padding, model, documents, request): | |
| topic_model = copy.deepcopy(request.getfixturevalue(model)) | |
| # Calculate only on a document-level based on tokensets | |
| topic_distr, _ = topic_model.approximate_distribution(documents, padding=padding, batch_size=batch_size) | |
| assert topic_distr.shape[1] == len(topic_model.topic_labels_) - topic_model._outliers | |
| # Use the distribution visualization | |
| for i in range(3): | |
| topic_model.visualize_distribution(topic_distr[i]) | |
| # Calculate distribution on a token-level | |
| topic_distr, topic_token_distr = topic_model.approximate_distribution(documents[:100], calculate_tokens=True) | |
| assert topic_distr.shape[1] == len(topic_model.topic_labels_) - topic_model._outliers | |
| assert len(topic_token_distr) == len(documents[:100]) | |
| for token_distr in topic_token_distr: | |
| assert token_distr.shape[1] == len(topic_model.topic_labels_) - topic_model._outliers | |