DeSiMaTe: Detect Similar Markdown Text
An automated tool for detecting similar text in large collections of documents, written in Python.
desimate is designed to be used as a CLI tool.
Given a set of Markdown documents, it splits each of them into fragments (paragraphs, lists, tables, code blocks, etc.), stores them in a DuckDB database, embeds them with a learned string-embedding model, and clusters the fragments according to their similarity.
The pipeline is composed of the following steps, each available as a dedicated subcommand:
run: run the complete pipeline on a set of documents. It is the easiest way for quick results. Alternatively, you can use subcommands to control each step of the pipeline:parse: parse the given documents into fragments at a configurable granularity, and store them in a DuckDB database.create-training-dataset: sample values from the database into a JSON Lines file, to be used for training.train: train a string-embedding model (a character-level convolutional network such as NeuroSEED or CNN-ED) such that the Euclidean distance between two embeddings approximates the Levenshtein distance between the embedded strings.embed: embed the fragments with the trained model (syntactic embedding), or with a given sentence transformer (semantic embedding), and store the results in the database.cluster: group the fragments into clusters of near-duplicates, either directly with the Levenshtein distance (small datasets) or with a grid-based agglomerative clustering that uses the embeddings as a cheap first filter and the Levenshtein distance to refine the results (large datasets).
This project is developed by Guillaume Cardoen at the Software Engineering Lab of the University of Mons (Belgium).
Installation
desimate requires a Python 3.14 or newer interpreter. The easiest way to install desimate is to install it from PyPI
pip install desimate
Another easy way to install desimate is via pip from this GitHub repository
pip install git+https://github.com/sgl-umons/desimate
Alternatively, you can clone this repository and install it locally
git clone https://github.com/sgl-umons/desimate
cd desimate
pip install . # or uv sync and uv run
You may wish to use desimate in a virtual environment
python -m venv venv
source venv/bin/activate
pip install desimate
Usage
After installation, the desimate command-line tool should be available in your shell. All commands accept a --config option (defaulting to ./config.toml) pointing to a TOML file whose content is used as default for the command options:
Usage: desimate [OPTIONS] COMMAND [ARGS]...
Options:
--config PATH The path to a TOML configuration file.
--help Show this message and exit.
Commands:
cluster Cluster the values stored in the database.
create-training-dataset Sample values from the database, and write
them in a JSON Lines file.
embed Embed the values stored in the database (or
a given input file) with a model.
parse Parse the given inputs, and store the
extracted fragments in the database.
process Run the full pipeline (parse, embed and
cluster) in a single command.
train Train a string-embedding model.
The easiest way to use desimate is through the process subcommand.
Usage: desimate process [OPTIONS] [INPUTS]...
Run the full pipeline in a single command: parse the given inputs (if any is
given), embed the values with the given model, and cluster the values of the
database. The embedding step is only run if `--model` is given, and the
clustering step is only run if `--distance` is given.
Positional arguments:
[INPUTS]... The files or directories (given one or multiple times;
directories are traversed recursively) to parse.
Options:
-i, --input-list FILE A file containing a list of additional inputs
(one path per line) to add to the inputs.
-p, --parser [markdown|text] The parser to use at which the fragments are
extracted.
-g, --granularity TEXT The granularity at which the fragments are
extracted.
-m, --model FILE The trained model used to embed the values.
-f, --focus-on TEXT Only keep the fragments of the given type (can
be given multiple times); every other fragment
is removed from the database. (Everything is
kept is not given.
-o, --output FILE The path where the cluster labels will be
saved as a NumPy array.
-d, --distance INTEGER The maximum distance for the clustering. When
given, the clustering step is run.
--syntactic Use the syntactic embedding, i.e., a trained
model (default).
--semantic Use the semantic embedding, i.e., a sentence
transformer.
--batch-size INTEGER The batch size used for the inference
(default: 1024).
--db, --database FILE The DuckDB database used throughout the
pipeline. [required]
--help Show this message and exit.
For Markdown, each granularity is a list of Markdown AST node types at which the traversal stops, i.e., the fragment types that will be extracted. The default configuration defines two granularities:
paragraph: fragments are paragraphs, lists and tables (default);md-line: fragments are the smallest line-level elements (text, list items, table cells and table rows).
Other granularities (line and file) are available through the text parser, which read the file as pure text.
Examples
As an example, the following commands will parse every Markdown file of the all_content directory into the my_dataset.db database, keeping only the paragraph, table, list and code fragments.
The fragments can be parsed, embedded and clustered, with a maximum distance of 15, in a single command:
desimate process all_content --db my_dataset.db --model model.torch -d 15 -o clusters.parquet -f paragraph -f table -f list -f code
Alternatively, you can use subcommands to do each step at a time.
desimate parse all_content --db my_dataset.db -f paragraph -f table -f list -f code
A training set can then be sampled from the database:
desimate create-training-dataset training.jsonl --count 25000 --db my_dataset.db
An embedding model can be trained on this dataset:
desimate train nscnn --input training.jsonl --output model.torch --n-training 20000 --n-query 5000
License
Distributed under GNU Lesser General Public License v3.
Metadata
Release files for desimate 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| desimate-0.2.0.tar.gz | 32.4 kB | With provenance | Details for desimate-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| desimate-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for desimate-0.2.0-py3-none-any.whl |
Total release size: 79.9 kB
Release files / desimate-0.2.0.tar.gz
| Download URL | desimate-0.2.0.tar.gz |
|---|---|
| Size | 32.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9bbdaa491d063ad0125610d7624e7bee3f3069d9e0c29841ac59a610857beb54
|
|
BLAKE2b-256 checksum How to use checksums |
48f60264ecb0098f7d12745781413ce945769b658b778d3cf628dc8bd04d68bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / desimate-0.2.0-py3-none-any.whl
| Download URL | desimate-0.2.0-py3-none-any.whl |
|---|---|
| Size | 47.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bad232bbdb0cd8c22ebf9120bf8d957b5e79a2a8082790d26f4b5fe80cd1a8bd
|
|
BLAKE2b-256 checksum How to use checksums |
30d4ccc340e71c3949caf6dd265768d84e762a585e90a92b0b497bab7cb80f0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logSecurity for desimate 0.2.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
Both files in this release have been uploaded with provenance metadata.
Attestation for desimate-0.2.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 Nov 10, 2026.
Transparency logA 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.