Repository navigation
Add DSL: a topic model trained on soft labels from a small language model - #141
Open
raymondzmc wants to merge 1 commit into
Open
raymondzmc wants to merge 1 commit into
raymondzmc wants to merge 1 commit into
Conversation
DSL (Li et al., ICML 2026) replaces the bag-of-words reconstruction target with the next-token distribution of a small causal language model that is asked for the document's theme, and uses the model's last hidden state as the document representation. - SoftLabelEncoder: an ExternalEncoder that returns the hidden states, and the vocabulary logits from the same forward pass - DSL: a ProdLDA-style autoencoder trained with KL to the soft labels - docs page with citation, model overview rows, tests on a tiny random model
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! I'm the first author of Improving Topic Modeling by Distilling Soft Labels from Language Models (DSL, ICML 2026), and I'd like to contribute it to Turftopic. I'm opening this early, as CONTRIBUTING suggests, and am happy to reshape it.
What DSL is
Autoencoding topic models reconstruct a document's bag-of-words. DSL changes the target and the input, and nothing else:
A bag-of-words target can only weight words that occur in the document. The soft label also weights theme words the document never uses, which helps most on short texts.
What this PR adds
turftopic.encoders.SoftLabelEncoder: anExternalEncoderaround a Hugging Face causal LM.encode()returns the hidden states;extract()returns the vocabulary logits and hidden states from one forward pass.turftopic.DSL: aContextualModelwith a ProdLDA-style autoencoder in plain PyTorch, trained with KL to the soft labels.fit_transformaccepts precomputedembeddings=andlogits=.docs/DSL.mdwith a citation section, a nav entry and rows in the model overview tables.tests/test_dsl.py, which runs on a tiny random GPT-2 so CI does not download a real LM.No new dependencies: it uses
torchand thetransformersthatsentence-transformersalready brings in.Results
Same vectorizer for every model (2000 most frequent non-stop words), mean ± std over 3 seeds, number of topics = number of gold labels. DSL uses
baidu/ERNIE-4.5-0.3B-PT(0.3B parameters); the other models useall-MiniLM-L6-v2. Purity and NMI compare the top topic per document with the gold labels. Coherence is the mean pairwiseword2vec-google-news-300similarity of the top 10 words (thec_exof your benchmark script), and diversity is the share of unique top words.20 Newsgroups (18,205 documents, headers, footers and quotes removed, 20 topics)
AutoEncodingTopicModel(combined=False)AutoEncodingTopicModel(combined=True)SemanticSignalSeparationKeyNMFGMMDSLTweetTopic (single-label tweets, 19 topics)
AutoEncodingTopicModel(combined=False)DSLDSL improves clearly on the autoencoding models it is closest to. On 20 Newsgroups
GMMstill assigns documents more accurately. I have not run your full leaderboard; if you would like DSL on it I can add an entry to the benchmark script, though it needs a GPU for the language model pass.Things you may want changed
DSLandSoftLabelEncoderare placeholders for whatever fits your conventions.default_vectorizer(). Phrase vectorizers are not a good fit.FASTopicin a follow-up if you want that.