Dynamic KeyNMF Framework
- Dynamic KeyNMF is a topic modeling framework that unifies transformer-based keyword importance scoring with NMF to capture evolving topics in large text corpora.
- It factorizes a non-negative keyword-importance matrix using coordinate descent, yielding semantically rich topics compared to traditional token-count models.
- The dynamic phase slices the corpus over time and optionally enforces temporal smoothness, enabling fine-grained analysis of topic emergence and resonance.
Dynamic KeyNMF is a topic modeling framework that unifies transformer-based keyword importance scoring with non-negative matrix factorization (NMF) to enable tracking the evolution of topics across contiguous time periods in large text corpora. The central innovation lies in constructing a non-negative “keyword-importance” matrix using contextualized embeddings from pretrained transformers, enabling more semantically meaningful topic induction compared to token-count-based approaches. Dynamic KeyNMF incorporates both static and dynamic phases, with optional temporal regularization, and was designed to support high-resolution analysis of topical information dynamics in settings such as Chinese diaspora media in the leadup to electoral events (Kristensen-McLachlan et al., 2024).
1. Construction of the Keyword-Importance Matrix
Given a corpus of documents and a vocabulary of candidate keywords, an embedding model (e.g., multilingual Sentence-BERT) generates dense representations for each document and each token. For each document , its embedding is computed, as well as for candidate tokens . The set of top- tokens for is selected to maximize the sum of cosine similarities . The keyword-importance matrix is then defined by:
This matrix is non-negative by construction. Unlike traditional document-term matrices filled by TF–IDF or raw counts, encodes semantic strength directly via contextual similarities.
2. Static KeyNMF Decomposition
The static phase factorizes into and , where is the number of topics. The factorization minimizes the Frobenius norm:
Optimization is performed via non-negative least squares, using coordinate-descent updates. Convergence is declared when the relative change in loss drops below (e.g., ).
The coordinate-descent update for (for fixed ) is:
where is a small step-size. Updates for are symmetric.
3. Dynamic Slicing and Topic Evolution
To track topic evolution over time slices, Dynamic KeyNMF operates as follows:
- Compute the static factorization over the entire corpus to obtain and .
- For each time slice , extract (documents from slice ) and the corresponding (rows of ).
- Fix and re-solve for slice-specific :
- Define the raw “temporal importance” of topic at time :
- Normalize to obtain a pseudo-distribution:
This pseudo-distribution enables downstream information dynamics analyses such as novelty, transience, and resonance.
4. Optional Temporal Smoothness Regularization
Dynamic KeyNMF supports, but does not require, temporal smoothness regularization over topic assignments across time slices. The joint dynamic-NMF objective adds slice-to-slice continuity penalties:
where and are non-negative smoothness weights, typically chosen small (–$0.1$) via cross-validation or grid search. The objective is optimized by alternating projected-gradient or coordinate-descent updates.
5. Preprocessing, Hyperparameters, and Practical Pipeline
Preprocessing steps include tokenization (e.g., jieba for Chinese), stopword removal, and candidate vocabulary construction. The main pipeline follows:
- Embedding & Keyword Extraction: For each , compute and for all . Select top tokens per doc by .
- Matrix Construction: Assemble as above.
- Static NMF: Initialize and randomly, update via coordinate descent to convergence.
- Dynamic Slicing: For each time , extract , , solve for ; compute .
- (Optional) Information Dynamics: Compute windowed Jensen–Shannon divergence between topic distributions for novelty, transience, and resonance analysis.
Key hyperparameters include (topics, typically 10–50), (keywords per doc, typically 15), (convergence threshold), (step size), , (smoothness), (window size for novelty calculations), and the smoothing span for dynamics curves.
6. Computational Complexity and Scaling
- Embedding: for documents.
- Keyword Selection: .
- Static NMF: Each iteration , for iterations.
- Dynamic H Re-Estimation: Per slice, .
- Total: , with documents, time slices, average slice size , and vocabulary size .
For corpora with , , and , static NMF computations dominate resource usage.
7. Evaluation Metrics and Benchmarks
Dynamic KeyNMF is evaluated using several metrics:
| Metric | Description | Computed As |
|---|---|---|
| Topic-diversity () | Fraction of unique words in union of top topic words | Standard toolkit |
| Internal coherence () | Avg. pairwise cosine among top topic words | Standard toolkit |
| External coherence () | Same as but using external embeddings | Standard toolkit |
| (Optional) NPMI | Normalized pointwise mutual information (coherence) | Standard toolkit |
These allow comparison against LDA, CTM, BERTopic, Top2Vec, etc., using e.g., the topic-benchmark Python package.
Dynamic KeyNMF has demonstrated competitive performance on several Chinese datasets, substantiating its suitability for high-resolution analysis of topical information dynamics in multilingual and non-Western corpora (Kristensen-McLachlan et al., 2024).