Martin Gerlach, Tiago P. Peixoto, and Eduardo G. Altmann, “A network approach to topic models,” Science Advances (2018)
Software ported to Scikit-learn format by the Sydney Informatics Hub at the University of Sydney.
Scikit-learn compatible Topic Modelling with Hierarchical Statistical Block Models (Gerlach, Peixoto and Altmann, 2018)
Home Page: http://topsbm.readthedocs.io
License: Other
Martin Gerlach, Tiago P. Peixoto, and Eduardo G. Altmann, “A network approach to topic models,” Science Advances (2018)
Software ported to Scikit-learn format by the Sydney Informatics Hub at the University of Sydney.
This would be a valuable end-to-end test beyond the unit test suite.
Unfortunately, compiling the example on readthedocs results in a timeout.
Eventually we should have them continuously deployed, with either Circle CI or readthedocs.
(Need to get the name right (#3) first)
Can I also run topSBM on a single document?
I am not interested in how topics are distributed over different documents. I just simply want to extract the main topics per document.
I know that the pd.DataFrame(model.groups_[1]['p_tw_d'], columns=titles) gives a matrix with how much each topic correspond per document, but this topic is based on words from all the documents....
Any suggestions?
It is very slow.
Is there any way I could measure how well topsbm is doing quantitatively on my data except for just eyeballing the topics returned?
There are problems with both memory and time consumption of the implementation. We could consider implementing the variational inference described at https://arxiv.org/pdf/1711.05150.pdf. I've previously found an R implementation of this, but have now lost it.
hSBMTransformer is:
Candidate names:
We need to ask the client about naming.
(Need to get the name right (#3) first)
There are different groups (i.e. sets of topics) at different levels of the hierarchy. All of these should be available as transform targets.
By default we might transform redundantly to all levels of the hierarchy, or to the finest, and provide an option to change this (with a memoised model?).
Licence currently has incorrect copyright attribution, and incorrect licence. Licence must be GPL v3. Each file with substantive work should have a copyright notice plus:
This file is part of TopSBM.
TopSBM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TopSBM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TopSBM. If not, see <https://www.gnu.org/licenses/>.
I think you should initially work on defining fit_transform. I would give it the following docstring:
def fit_transform(self, X, y=None):
"""Fit the hSBM topic model
Constructs a graph representation of X, infers clustering, and reports
the cluster probability for each sample in X.
Parameters
----------
X : ndarray or sparse matrix of shape (n_samples, n_features)
Word frequencies for each document, represented as non-negative
integers.
y : ignored
Returns
-------
Xt : ndarray of shape (n_samples, n_components)
"""
This would do basically everything for the simple case of just getting a topic decomposition of some X. It would call private methods as appropriate to modularise the work. The main idea would be to encapsulate the logic for transformation as a function of numeric array X
and any hyper-parameters provided in __init__
.
An initial test would be:
import pytest
from sklearn.datasets import make_multilabel_classification
from hSBM import hSBMTransformer
@pytest.mark.parametrize('sparse', [False, True])
@pytest.mark.parametrize('n_components', [5, 10])
def test_basic_fit_transform(sparse, n_components):
X, y = make_multilabel_classification(random_state=0, n_features=150)
est = hSBMTransformer(n_components=n_components)
Xt = est.fit_transform(X)
assert Xt.shape == (X.shape[0], n_components)
def test_continuous_unacceptable():
# hSBMTransformer should refuse to transform anything but integer data
est = hSBMTransformer()
with pytest.raises(ValueError):
est.fit_transform(np.linspace(0, 1, 1000).reshape(20, 5))
Once this is done, we can further work out what we need to do to make the estimator more useful.
Sphinx/docutils produce spans with "delimiter" and "classifier" classes in dt
nodes in HTML. These are not styled in the rtd default stylesheet.
Running examples kills readthedocs as it runs out of memory. We'll need to precompute the example results :(
avoid indvidual configuration
If so, it is trivial to implement transform
.
But only after we've got the name right
The conda installation can be simplified now that conda-forge has a graph-tool build on it: https://anaconda.org/conda-forge/graph-tool. This may better support cross-platform installs (still no windows), but should be tested.
We need a parameter random_state
that controls randomization with a numpy RandomState. This requires investigating how graph_tool performs random number generation or allows this to be controlled.
Quoting Eduardo
Control over the hierarchy:
The non-hierarchical model we considered in our paper is obtained
calling gt.minimize_blockmodel_dl instead of
gt.minimize_nested_blockmodel_dl.
Instead of a set of solutions in different levels of the hierarchy, we
only obtain one solution. We would have to adapt the 'get_groups'
function in the following way:
- now, the solution of the hierarchical model (state) is projected onto
a given level in the hierachy (state_l)
- if we use the non-hierarchical model, we would skip the projection-part
We could also set the upper and lower limit for the total number of groups.
The advantage of this would be to have more control over the number of
groups and to not have to decide about which level in the hierarchy.
However, the main advantage of the hierarchical model is that it
provides a better prior increasing the resolution of small clusters
(keyword: 'resolution limit' in community detection).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.