Skip to main content

maretopic

EMNLP 2026 License GitHub Repo

maretopic is the official implementation of MARETopic (Manifold-Aware and Rank-based Exemplars Topic Modeling), a training-free topic model that casts topic discovery as rank-based prototype selection.

📢 Accepted at EMNLP 2026 (Main Conference). If you use this package, please see the citation below.


🔍 Overview

Neural topic models produce topics as latent vectors or distributions over the vocabulary — objects with no grounding in any specific text. Clustering-based pipelines pick representative documents only afterwards, by ranking cluster members against a centroid.

MARETopic makes the document the topic. A greedy algorithm selects exactly K leader documents whose neighborhoods cover the corpus, and each leader is the topic: a real text you can open and read.

The selection never uses absolute distances. Documents are encoded, projected onto a low-dimensional manifold, and turned into ranked lists — ordinal neighborhood structure, which is far less affected by the hubness and anisotropy of high-dimensional embedding spaces.

Key properties:

  • Training-free: no gradient updates, no variational inference.
  • Exactly K topics: the number of topics is an input, not an outcome of density parameters.
  • Interpretable by construction: every topic is a corpus document.
  • Out-of-sample inference: unseen documents are scored against the leaders without refitting.

📦 Installation

pip install maretopic

To also run the TopMost integration and the example:

pip install "maretopic[topmost]"

The latest development version can be installed directly from source:

pip install "maretopic[topmost] @ git+https://github.com/thcastilho/maretopic"

Dependencies: numpy, scikit-learn, tqdm, sentence-transformers, umap-learn, and interpretable-embeddings (which provides the canonical GRaCE and RaDE implementations).

Requires Python ≥ 3.9.


🧠 Variants

Both variants share the same greedy criterion: pick the candidate that maximizes a score while penalizing redundancy with the leaders already chosen. They differ in how those two quantities are computed, and neither is a reduced form of the other.

MARETopic_Corr — scoring="correlation"

Candidates are scored by a query performance predictor (Reciprocal Density: how strongly a document's neighbors agree on neighborhood membership) and penalized by a rank correlation measure (JaccardMax: maximum Jaccard overlap across prefix depths). Either measure can be swapped without touching the rest of the pipeline.

MARETopic_Diff — scoring="diffusion"

A rank-weighted affinity matrix W is raised to a power, A = W². Its diagonal scores the candidate and its off-diagonal entries penalize redundancy, so the variant needs neither a QPP nor a correlation measure — and runs faster.


🛠 Usage

from maretopic import MARETopic

model = MARETopic(
    num_topics=50,        # K
    top_K=100,            # ranked-list depth
    umap_dim=5,           # 0 disables the UMAP projection
    mmr_diversity=0.3,    # inter-topic MMR weight for keyword extraction
    scoring="correlation" # or "diffusion"
)

model.fit(train_texts)

for words in model.get_top_words():
    print(words)

Each topic is anchored on a real document, and get_leaders() returns their indices in the training corpus:

for topic_id, leader in enumerate(model.get_leaders()):
    print(f"topic {topic_id} is the document: {train_texts[leader][:120]}...")

Unseen documents are projected with the fitted reducer and scored against the leaders — no refitting:

theta = model.transform(test_texts)   # (n_documents, num_topics)
assignments = theta.argmax(axis=1)

Reproducibility

UMAP runs without a fixed random_state, so results vary slightly between fits — the same behavior as BERTopic. Report the mean and standard deviation over several runs, as the paper does. Passing umap_random_state fixes the seed at the cost of UMAP's parallelism.


🔗 TopMost integration

maretopic.topmost.MARETopicTrainer implements the same trainer interface as TopMost's own BERTopicTrainer and FASTopicTrainer, so MARETopic drops into a TopMost evaluation pipeline. Nothing in your topmost installation needs to be patched.

from topmost import BasicDataset, download_dataset
from topmost.eva import clustering, topic_coherence, topic_diversity
from maretopic.topmost import MARETopicTrainer

download_dataset("20NG", cache_path="./data")
dataset = BasicDataset("./data/20NG", read_labels=True, as_tensor=True)

trainer = MARETopicTrainer(dataset, num_topics=50, num_top_words=15)
top_words, train_theta = trainer.train()
train_theta, test_theta = trainer.export_theta()

A complete, runnable version — both variants, all four metrics — is in examples/evaluate_20ng.py.


📁 Package Structure

maretopic/
│
├── model.py         # MARETopic class: fit, transform, get_top_words, get_leaders
├── embeddings.py    # SBERT encoding + ranked-list construction (BallTree)
├── words.py         # c-TF-IDF + inter-topic MMR keyword extraction
└── topmost.py       # MARETopicTrainer adapter for the TopMost toolkit

Leader selection and the training document–topic matrix are delegated to interpretable-embeddings (GRaCE for the correlation variant, RaDE for the diffusion variant), so the algorithms have a single canonical implementation.


📚 Citation

If you use this package in your research, please cite:

Almeida, T. C. C., Pedronette, D. C. G. A Manifold-Aware Topic Modeling Approach via Rank-Based Prototypes Accepted at the 2026 Conference on Empirical Methods in Natural Language Processing (EMNLP), Main Conference.

@inproceedings{almeida2026maretopic,
  title     = {A Manifold-Aware Topic Modeling Approach via Rank-Based Prototypes},
  author    = {Almeida, Thiago C. C. and Pedronette, Daniel C. G.},
  booktitle = {Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing (EMNLP)},
  year      = {2026},
  publisher = {Association for Computational Linguistics}
}

MARETopic builds directly on two earlier methods from the same line of work:

Almeida, T. C. C., Letício, G. R., Valem, L. P., Freitas, A., Pedronette, D. C. G. Effective Graph and Rank-based Contextual Embeddings for Textual and Multimedia Data 2025 International Joint Conference on Neural Networks (IJCNN), Rome – Italy. GRaCE

De Fernando, F. A., Pedronette, D. C. G., De Sousa, G. J., Valem, L. P., Guilherme, I. R. RaDE+: A semantic rank-based graph embedding algorithm International Journal of Information Management Data Insights, 2(2), 100078, 2022. RaDE+


🤝 Contact

  • Thiago César Castilho Almeida: tc.almeida@unesp.br
  • Daniel Carlos Guimarães Pedronette: daniel.pedronette@unesp.br

Metadata

Release files for maretopic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maretopic 0.1.0
File Size Uploaded Provenance
maretopic-0.1.0.tar.gz 23.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for maretopic 0.1.0
File Interpreter ABI Platform
maretopic-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.3 kB

Release files / maretopic-0.1.0.tar.gz

Download URL maretopic-0.1.0.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b5b8c0e1f3b667516c09eb5020be3cf57e9ccf334bc04ca887c70a850d9f811f
BLAKE2b-256 checksum
How to use checksums
d7ff11b9b0f37d9c95dc7b8db967034be5b8e57417c77cc2da7f57fc72723283
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.

Transparency log

Release files / maretopic-0.1.0-py3-none-any.whl

Download URL maretopic-0.1.0-py3-none-any.whl
Size 22.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e1ae434cbd37c2aeaf57e914090dbbed70f231ae782745cc6863cf5149fb72f
BLAKE2b-256 checksum
How to use checksums
baf7d61dc0e3160686f26a5691437fbf536cfc6d645a3b00914257657c4b012f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.

Transparency log

Security for maretopic 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for maretopic-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page