Code repository for the EMNLP 2025 paper: Leveraging Semantic Triples for Private Document Generation with Local Differential Privacy Guarantees
Getting Started
Installation
You can now install DP-ST directly as a Python package.
# Install the core runtime engine
pip install dpst
# Install the optional data-preparation extensions required for the initial setup
pip install "dpst[setup]"
Note on Heavy Runtimes: We highly recommend installing the correct flavor of PyTorch matching your hardware's CUDA capability before installing this package.
More installation notes and tips
We have done our best to configure DP-ST and its set environment variables such that it can run as smoothly as possible on all setups. However, vLLM is currently quite finicky, so there may be some holdups with your runtime.
VLLM_ENABLE_V1_MULTIPROCESSING="0": Forces vLLM to run in-process. Under WSL2 (if applicable to you), spawned worker subprocesses fail theUvaBuffercheck (UVA is not available).- You will likely have to run
(uv) pip uninstall torchcodecfollowing installation, as this library creates compatability issues. - For the default embedding model (
jina-embeddings-v3), you may see warnings likeflash_attn is not installed. Using PyTorch native attention implementation.While these are generally safe to ignore, we highly recommend installingflash-attn(already in the requirements), as we have noticed particularly withjina-embeddings-v3that not doing so leads to headaches and odd behavior. This can be done with the following:
git clone https://github.com/Dao-AILab/flash-attention.git
cd flash-attention/
export TORCH_CUDA_ARCH_LIST="12.0"
export FLASH_ATTN_CUDA_ARCHS="120"
export FLASH_ATTENTION_FORCE_BUILD=TRUE
uv pip install . --no-build-isolation --no-cache-dir
Please also make sure to pass hf_token to initizalization, if applicable to reconstruction model you have chosen.
Automated Database & Cluster Setup
In order to run DP-ST, you must first run the preparation stage as described in the paper. This includes booting up your local vector database, extracting triples from a public text corpus, clustering them, and storing them locally.
Ensure your local Weaviate instance is running, then execute the following automated command in your terminal:
dpst setup
Note: This can take a very long time! We recommend you set it and forget it. Alternatively, you can tweak the max_rows parameter of initialize_database to use less texts for the database preparation.
The above replaces the legacy workflow of manually executing Triple2DB.ipynb and triple_cluster.ipynb. The command will automatically stream the FineWeb public corpus dataset, extract/embed triples into Weaviate, run the MiniBatchKMeans allocations (50k, 100k, and 200k), and write the resulting cluster assets straight into the package data directory. If you prefer a more tailored approach, we still recommend using the notebooks.
Usage
Running DP-ST is simple once the automated setup has completed:
from dpst import DPST
# Initialize the engine (specify mode: "50k", "100k", or "200k")
X = DPST(mode="50k", model_checkpoint=MODEL_NAME, hf_token=TOKEN)
# Privatize your text corpus
private_texts = X.privatize([TEXTS], epsilon=DOC_PRIVACY_BUDGET) # or epsilon=LIST_OF_EPSILONS (for epsilon sweeps)
# Cleanup all resources (recommended!)
X.cleanup()
MODEL_NAME refers to the model used for text reconstruction (i.e., the Llama-3.2 models we use in the work), and hf_token is only necessary for gated models on Hugging Face.
Running other DP Methods
In this repository (under the comparison directory), you will find a number of scripts (*_perturb.py) to reproduce the privatized texts as performed in our work.
The code for DP-BART and DP-Prompt can be found in LLMDP.py. DP-MLM can be found here and the code for TEM can be found here.
We also include the evaluation code for cosine similarity (CS.py) and G-Eval (Geval.ipynb), located in evaluation.
NOTE: in all provided notebooks, please make sure to include the correct libraries and link the paths accordingly. This is necessary for the code to run correctly!
Citation
If you use this code in your research, please consider citing the published work:
@inproceedings{meisenbacher-etal-2025-leveraging,
title = "Leveraging Semantic Triples for Private Document Generation with Local Differential Privacy Guarantees",
author = "Meisenbacher, Stephen and
Chevli, Maulik and
Matthes, Florian",
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.455/",
doi = "10.18653/v1/2025.emnlp-main.455",
pages = "8976--8992",
ISBN = "979-8-89176-332-6"
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dpst-0.3.9.tar.gz.
File metadata
- Download URL: dpst-0.3.9.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6267b065870798fcf3902c082a8c4810bb5e19543e13d2d744938dcc5c86debf
|
|
| MD5 |
14378ea815452497ee618424dcbda16e
|
|
| BLAKE2b-256 |
8cf47a82218159e14fc33a210a8ed7a4b5e64f8bce560993d49b0146f52044cc
|
File details
Details for the file dpst-0.3.9-py3-none-any.whl.
File metadata
- Download URL: dpst-0.3.9-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d92189bcc148666daae75b3a9a09436458921948372127317b45ef755379090
|
|
| MD5 |
9e42221887298364c6dfa5dabe6769de
|
|
| BLAKE2b-256 |
e0ffc1d5cc36198550080e0288f2826f625f0795096748e723815b58255f3fe0
|