A novel multimodal topic modeling framework that leverages Vision-Language Models (VLMs) to discover coherent topics from documents containing both text and images.
We introduce CEMTM, a context-enhanced multimodal topic model designed to infer coherent and interpretable topic structures from both short and long documents containing text and images. CEMTM builds on fine-tuned large vision language models (LVLMs) to obtain contextualized embeddings, and employs a distributional attention mechanism to weight token-level contributions to topic inference. A reconstruction objective aligns topic-based representations with the document embedding, encouraging semantic consistency across modalities. Unlike existing approaches, CEMTM can process multiple images per document without repeated encoding and maintains interpretability through explicit word-topic and document-topic distributions. Extensive experiments on six multimodal benchmarks show that CEMTM consistently outperforms unimodal and multimodal baselines, achieving a remarkable average LLM score of 2.61. Further analysis shows its effectiveness in downstream few-shot retrieval and its ability to capture visually grounded semantics in complex domains such as scientific articles.
CEMTM (Contextual Embedding-based Topic Model) addresses the limitations of traditional topic models by incorporating multimodal information through contextualized embeddings. This approach:
CEMTM consists of four key components working together to extract topics from multimodal documents:
H โ โ^(NรD) where N is sequence length, D is embedding dimensione_d โ โ^Dt_i = softmax(W_t h_i) where t_i โ โ^K (K topics)ฮผ and ฯยฒ parameters for importance distributionฮฑ_i ~ N(ฮผ_i, ฯ_iยฒ) followed by ฮฒ_i = softmax(ฮฑ) for importance weightse_d' = f_dec(โ_i ฮฒ_i t_i) where f_dec is a linear decodere_d and e_d'The model optimizes the following objective:
L = L_rec + ฮป_ent L_ent + ฮป_kl L_kl
Where:
||e_d - e_d'||ยฒโ_i ฮฒ_i log ฮฒ_iInstall the required packages:
pip install -r requirements.txt
NLTK Data: Required for text preprocessing
python -c "import nltk; nltk.download('stopwords')"
Word Embeddings (for evaluation metrics): Download GloVe embeddings for the WE (Word Embedding) metric:
mkdir -p data/embeddings
wget http://nlp.stanford.edu/data/glove.6B.zip
unzip glove.6B.zip -d data/embeddings/
OpenAI API Key (optional, for LLM evaluation):
export OPENAI_API_KEY="your-api-key-here"
CEMTM has been evaluated on multiple multimodal datasets:
Each dataset loader handles the specific format and preprocessing requirements automatically.
Choose one of the supported datasets and set up the data directory:
mkdir -p data/corpus/annotations data/corpus/train2014
# Download MS-COCO 2014 train images and annotations
# Place captions_train2014.json in data/corpus/annotations/
# Place images in data/corpus/train2014/
wikiweb2m.jsonl and image folders in data/corpus/metadata.json and images/ folder in data/corpus/tqa.json and images/ folder in data/corpus/hateful_memes.jsonl and img/ folder in data/corpus/t4sa.csv and images/ folder in data/corpus/stories.json and images/ folder in data/corpus/Understanding the main configuration parameters:
model:
d_model: 4096 # VLM embedding dimension (depends on chosen VLM)
n_topics: 50 # Number of topics to discover
transformer_layers: 2 # Layers in importance network
transformer_heads: 8 # Multi-head attention heads
dropout: 0.1 # Regularization
training:
batch_size: 4 # Adjust based on GPU memory
num_epochs: 20 # Training epochs
gradient_clip: 1.0 # Gradient clipping for stability
device: cuda # Use GPU for faster training
loss:
lambda_entropy: 0.01 # Entropy regularization weight
lambda_kl: 0.1 # KL divergence weight
optimizer:
name: adamw
lr: 5e-5 # Learning rate
weight_decay: 0.01 # L2 regularization
scheduler:
name: linear # Learning rate schedule
warmup_steps: 500 # Warmup period
Train the CEMTM model:
python scripts/train_cemtm.py --config config/config.yaml
Training outputs:
outputs/logs/Evaluate trained model on topic quality metrics:
python scripts/evaluate_topics.py --config config/config.yaml
After training, you can verify the quality of the generated vocabulary using the vocabulary checker tool:
python scripts/check_vocabulary.py --vocab_path outputs/vocabulary.json
This tool provides:
When to Use:
vocab_size or min_word_freq parametersConfiguration Parameters:
You can adjust vocabulary generation in config/config.yaml:
data:
vocab_size: 2000 # Maximum vocabulary size
min_word_freq: 5 # Minimum frequency threshold (filters rare words)
Tips:
min_word_freq to filter more rare words (e.g., 10-20)min_word_freq or increase vocab_sizemin_word_freqCEMTM provides comprehensive evaluation through multiple metrics:
Topic Diversity (TD): Measures the proportion of unique words across all topics
Inverse Rank-Biased Overlap (I-RBO): Measures topic distinctiveness
Normalized Pointwise Mutual Information (NPMI): Measures topic coherence
Word Embedding Score (WE): Semantic coherence based on word embeddings
CEMTM/
โโโ config/
โ โโโ config.yaml # Configuration file
โโโ data/
โ โโโ dataset.py # Dataset loaders
โ โโโ preprocessing.py # Text/image preprocessing
โโโ evaluation/
โ โโโ llm_api.py # OpenAI API interface
โ โโโ metrics.py # Evaluation metrics
โ โโโ topic_extraction.py # Topic analysis utilities
โโโ losses/
โ โโโ losses.py # Loss functions
โโโ model/
โ โโโ cemtm.py # Main CEMTM model
โ โโโ encoder.py # Topic encoder
โ โโโ importance_net.py # Importance network
โ โโโ vlm2vec.py # Vision-Language Model wrapper
โโโ scripts/
โ โโโ evaluate_topics.py # Evaluation script
โ โโโ train_cemtm.py # Training script
โโโ trainer/
โ โโโ trainer.py # Training logic
โ โโโ utils.py # Training utilities
โโโ requirements.txt # Dependencies
CUDA Out of Memory:
batch_size in config.yamldevice: cpu for CPU-only trainingImport Errors:
pip install -r requirements.txtDataset Loading Errors:
Evaluation Errors:
CEMTM builds upon and extends several lines of research:
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues, please:
This research was supported by the Natural Sciences and Engineering Research Council of Canada (NSERC).
Ce projet a รฉtรฉ financรฉ par le Conseil de recherches en sciences naturelles et en gรฉnie du Canada (CRSNG).
@inproceedings{abaskohi-etal-2025-cemtm,
title = "{CEMTM}: Contextual Embedding-based Multimodal Topic Modeling",
author = "Abaskohi, Amirhossein and
Li, Raymond and
Li, Chuyuan and
Joty, Shafiq and
Carenini, Giuseppe",
editor = "Christodoulopoulos, Christos and
Chakraborty, Tanmoy and
Rose, Carolyn and
Peng, Violet",
booktitle = "Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing",
month = nov,
year = "2025",
address = "Suzhou, China",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2025.emnlp-main.590/",
doi = "10.18653/v1/2025.emnlp-main.590",
pages = "11675--11692",
ISBN = "979-8-89176-332-6",
abstract = "We introduce CEMTM, a context-enhanced multimodal topic model designed to infer coherent and interpretable topic structures from both short and long documents containing text and images. CEMTM builds on fine-tuned large vision language models (LVLMs) to obtain contextualized embeddings, and employs a distributional attention mechanism to weight token-level contributions to topic inference. A reconstruction objective aligns topic-based representations with the document embedding, encouraging semantic consistency across modalities. Unlike existing approaches, CEMTM can process multiple images per document without repeated encoding and maintains interpretability through explicit word-topic and document-topic distributions. Extensive experiments on six multimodal benchmarks show that CEMTM consistently outperforms unimodal and multimodal baselines, achieving a remarkable average LLM score of 2.61. Further analysis shows its effectiveness in downstream few-shot retrieval and its ability to capture visually grounded semantics in complex domains such as scientific articles."
}
11 commits
Python
100.0%
A novel multimodal topic modeling framework that leverages Vision-Language Models (VLMs) to discover coherent topics from documents containing both text and images.
We introduce CEMTM, a context-enhanced multimodal topic model designed to infer coherent and interpretable topic structures from both short and long documents containing text and images. CEMTM builds on fine-tuned large vision language models (LVLMs) to obtain contextualized embeddings, and employs a distributional attention mechanism to weight token-level contributions to topic inference. A reconstruction objective aligns topic-based representations with the document embedding, encouraging semantic consistency across modalities. Unlike existing approaches, CEMTM can process multiple images per document without repeated encoding and maintains interpretability through explicit word-topic and document-topic distributions. Extensive experiments on six multimodal benchmarks show that CEMTM consistently outperforms unimodal and multimodal baselines, achieving a remarkable average LLM score of 2.61. Further analysis shows its effectiveness in downstream few-shot retrieval and its ability to capture visually grounded semantics in complex domains such as scientific articles.
CEMTM (Contextual Embedding-based Topic Model) addresses the limitations of traditional topic models by incorporating multimodal information through contextualized embeddings. This approach:
CEMTM consists of four key components working together to extract topics from multimodal documents:
H โ โ^(NรD) where N is sequence length, D is embedding dimensione_d โ โ^Dt_i = softmax(W_t h_i) where t_i โ โ^K (K topics)ฮผ and ฯยฒ parameters for importance distributionฮฑ_i ~ N(ฮผ_i, ฯ_iยฒ) followed by ฮฒ_i = softmax(ฮฑ) for importance weightse_d' = f_dec(โ_i ฮฒ_i t_i) where f_dec is a linear decodere_d and e_d'The model optimizes the following objective:
L = L_rec + ฮป_ent L_ent + ฮป_kl L_kl
Where:
||e_d - e_d'||ยฒโ_i ฮฒ_i log ฮฒ_iInstall the required packages:
pip install -r requirements.txt
NLTK Data: Required for text preprocessing
python -c "import nltk; nltk.download('stopwords')"
Word Embeddings (for evaluation metrics): Download GloVe embeddings for the WE (Word Embedding) metric:
mkdir -p data/embeddings
wget http://nlp.stanford.edu/data/glove.6B.zip
unzip glove.6B.zip -d data/embeddings/
OpenAI API Key (optional, for LLM evaluation):
export OPENAI_API_KEY="your-api-key-here"
CEMTM has been evaluated on multiple multimodal datasets:
Each dataset loader handles the specific format and preprocessing requirements automatically.
Choose one of the supported datasets and set up the data directory:
mkdir -p data/corpus/annotations data/corpus/train2014
# Download MS-COCO 2014 train images and annotations
# Place captions_train2014.json in data/corpus/annotations/
# Place images in data/corpus/train2014/
wikiweb2m.jsonl and image folders in data/corpus/metadata.json and images/ folder in data/corpus/tqa.json and images/ folder in data/corpus/hateful_memes.jsonl and img/ folder in data/corpus/t4sa.csv and images/ folder in data/corpus/stories.json and images/ folder in data/corpus/Understanding the main configuration parameters:
model:
d_model: 4096 # VLM embedding dimension (depends on chosen VLM)
n_topics: 50 # Number of topics to discover
transformer_layers: 2 # Layers in importance network
transformer_heads: 8 # Multi-head attention heads
dropout: 0.1 # Regularization
training:
batch_size: 4 # Adjust based on GPU memory
num_epochs: 20 # Training epochs
gradient_clip: 1.0 # Gradient clipping for stability
device: cuda # Use GPU for faster training
loss:
lambda_entropy: 0.01 # Entropy regularization weight
lambda_kl: 0.1 # KL divergence weight
optimizer:
name: adamw
lr: 5e-5 # Learning rate
weight_decay: 0.01 # L2 regularization
scheduler:
name: linear # Learning rate schedule
warmup_steps: 500 # Warmup period
Train the CEMTM model:
python scripts/train_cemtm.py --config config/config.yaml
Training outputs:
outputs/logs/Evaluate trained model on topic quality metrics:
python scripts/evaluate_topics.py --config config/config.yaml
After training, you can verify the quality of the generated vocabulary using the vocabulary checker tool:
python scripts/check_vocabulary.py --vocab_path outputs/vocabulary.json
This tool provides:
When to Use:
vocab_size or min_word_freq parametersConfiguration Parameters:
You can adjust vocabulary generation in config/config.yaml:
data:
vocab_size: 2000 # Maximum vocabulary size
min_word_freq: 5 # Minimum frequency threshold (filters rare words)
Tips:
min_word_freq to filter more rare words (e.g., 10-20)min_word_freq or increase vocab_sizemin_word_freqCEMTM provides comprehensive evaluation through multiple metrics:
Topic Diversity (TD): Measures the proportion of unique words across all topics
Inverse Rank-Biased Overlap (I-RBO): Measures topic distinctiveness
Normalized Pointwise Mutual Information (NPMI): Measures topic coherence
Word Embedding Score (WE): Semantic coherence based on word embeddings
CEMTM/
โโโ config/
โ โโโ config.yaml # Configuration file
โโโ data/
โ โโโ dataset.py # Dataset loaders
โ โโโ preprocessing.py # Text/image preprocessing
โโโ evaluation/
โ โโโ llm_api.py # OpenAI API interface
โ โโโ metrics.py # Evaluation metrics
โ โโโ topic_extraction.py # Topic analysis utilities
โโโ losses/
โ โโโ losses.py # Loss functions
โโโ model/
โ โโโ cemtm.py # Main CEMTM model
โ โโโ encoder.py # Topic encoder
โ โโโ importance_net.py # Importance network
โ โโโ vlm2vec.py # Vision-Language Model wrapper
โโโ scripts/
โ โโโ evaluate_topics.py # Evaluation script
โ โโโ train_cemtm.py # Training script
โโโ trainer/
โ โโโ trainer.py # Training logic
โ โโโ utils.py # Training utilities
โโโ requirements.txt # Dependencies
CUDA Out of Memory:
batch_size in config.yamldevice: cpu for CPU-only trainingImport Errors:
pip install -r requirements.txtDataset Loading Errors:
Evaluation Errors:
CEMTM builds upon and extends several lines of research:
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues, please:
This research was supported by the Natural Sciences and Engineering Research Council of Canada (NSERC).
Ce projet a รฉtรฉ financรฉ par le Conseil de recherches en sciences naturelles et en gรฉnie du Canada (CRSNG).
@inproceedings{abaskohi-etal-2025-cemtm,
title = "{CEMTM}: Contextual Embedding-based Multimodal Topic Modeling",
author = "Abaskohi, Amirhossein and
Li, Raymond and
Li, Chuyuan and
Joty, Shafiq and
Carenini, Giuseppe",
editor = "Christodoulopoulos, Christos and
Chakraborty, Tanmoy and
Rose, Carolyn and
Peng, Violet",
booktitle = "Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing",
month = nov,
year = "2025",
address = "Suzhou, China",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2025.emnlp-main.590/",
doi = "10.18653/v1/2025.emnlp-main.590",
pages = "11675--11692",
ISBN = "979-8-89176-332-6",
abstract = "We introduce CEMTM, a context-enhanced multimodal topic model designed to infer coherent and interpretable topic structures from both short and long documents containing text and images. CEMTM builds on fine-tuned large vision language models (LVLMs) to obtain contextualized embeddings, and employs a distributional attention mechanism to weight token-level contributions to topic inference. A reconstruction objective aligns topic-based representations with the document embedding, encouraging semantic consistency across modalities. Unlike existing approaches, CEMTM can process multiple images per document without repeated encoding and maintains interpretability through explicit word-topic and document-topic distributions. Extensive experiments on six multimodal benchmarks show that CEMTM consistently outperforms unimodal and multimodal baselines, achieving a remarkable average LLM score of 2.61. Further analysis shows its effectiveness in downstream few-shot retrieval and its ability to capture visually grounded semantics in complex domains such as scientific articles."
}
11 commits
Python
100.0%