LlamaIndex Packs: DiffPrivateSimpleDatasetPack
The DiffPrivateSimpleDatasetPack llama pack creates differentially private synthetic
examples from an original, sensitive dataset.
Differential Privacy is a privacy preserving technique that obscures source data while preserving original attributes, while minimizing the performance impact on processes that consume the data.
The main motivation for this pack is thus to provide the means to create privacy safe versions of datasets that can be used in subsequent downstream processing (i.e., in a prompt to be passed to an LLM) steps. As noted in the original paper (linked below), the synthetic observations can be used as many times as one desires without any additional privacy costs!
The paper appeared at ICLR 2024 and is entitled: PRIVACY-PRESERVING IN-CONTEXT LEARNING WITH DIFFERENTIALLY PRIVATE FEW-SHOT GENERATION.
How it works?
The pack operates on a dataset represented with the LabelledSimpleDataset type.
This type consists of examples called LabelledSimpleDataExample, which is a data
class that contains two fields, namely: text and reference_label. For example,
a news dataset may have example texts with reference_labels belonging to
{"World", "Business", "Sports", etc.}.
The output of this pack's run() (and arun()) method is another LabelledSimpleDataset,
but represents privacy-safe, synthetically generated examples.
Supported LLMs
To use this pack, an LLM that produces LogProbs must be used as it is used in
the differential-privacy generation logic for the next token. The demos found in
the examples folder use OpenAI completion LLMs (chat completion LLMs were
also used, but these did not produce quality results.)
CLI Usage
You can download llamapacks directly using llamaindex-cli, which comes installed with the llama-index python package:
llamaindex-cli download-llamapack DiffPrivateSimpleDatasetPack --download-dir ./pack
You can then inspect the files at ./pack and use them as a template for your own project!
Code Usage
You can download the pack from PyPi and then use it your llama-index applications.
pip install llama-index-packs-diff-private-simple-dataset
A DiffPrivateSimpleDatasetPack object is constructed with the following params:
- an
LLM(must returnCompletionResponse), - its associated
tokenizer, - a
PromptBundleobject that contains the parameters required for prompting the LLM to produce the synthetic observations - a
LabelledSimpleDataset - [Optional]
sephamore_counter_sizeused to help reduce chances of experiencing aRateLimitErrorwhen calling the LLM's completions API. - [Optional]
sleep_time_in_secondsused to help reduce chances of experiencing aRateLimitErrorwhen calling the LLM"s completions API.
from llama_index.packs.diff_private_simple_dataset import (
DiffPrivateSimpleDatasetPack,
)
from llama_index.packs.diff_private_simple_dataset.base import PromptBundle
llm = ...
tokenizer = ...
prompt = PromptBundle(instruction=..., text_heading=..., label_heading=...)
dp_simple_dataset_pack = DiffPrivateSimpleDatasetPack(
llm=llm,
tokenizer=tokenizer,
prompt_bundle=prompt_bundle,
simple_dataset=simple_dataset,
)
If you would like to customize this pack further, then you can download it as a template:
from llama_index.core import SimpleDirectoryReader
from llama_index.core.llama_pack import download_llama_pack
# download and install dependencies
DiffPrivateSimpleDatasetPack = download_llama_pack(
"DiffPrivateSimpleDatasetPack", "./dense_pack"
)
dp_simple_dataset_pack = DiffPrivateSimpleDatasetPack(
llm=llm,
tokenizer=tokenizer,
prompt_bundle=prompt_bundle,
simple_dataset=simple_dataset,
)
The run() function is a light wrapper around query_engine.query(). A few
params are required:
t_max: The max number of tokens you would like to generate (the algorithm adds some logic per token in order to satisfy differential privacy).sigma: Controls the variance of the noise distribution associated with differential privacy noise mechanism. A value ofsigmaamounts to a level ofepsilonsatisfied in differential privacy.num_splits: The differential privacy algorithm implemented here relies on disjoint splits of the original dataset.num_samples_per_split: The number of private, in-context examples to include in the generation of the synthetic example.
synthetic_dataset = dp_simple_dataset_pack.run(
sizes={"World": 1, "Sports": 1, "Sci/Tech": 0, "Business": 0},
t_max=10, #
sigma=0.5,
num_splits=2,
num_samples_per_split=8,
)
print(response)
Examples
- See examples/basic_demo folder for a notebook the consists of a basic demo
on how to use the
DiffPrivateSimpleDatasetPack. - Also see examples/symptom_2_disease for a more Python program that generates a synthetic version of the Symptom2Disease dataset.
Metadata
Release files for llama-index-packs-diff-private-simple-dataset 0.4.1
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 |
|---|---|---|---|---|
| llama_index_packs_diff_private_simple_dataset-0.4.1.tar.gz | 10.1 kB | Without provenance | Details for llama_index_packs_diff_private_simple_dataset-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llama_index_packs_diff_private_simple_dataset-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for llama_index_packs_diff_private_simple_dataset-0.4.1-py3-none-any.whl |
Total release size: 20.9 kB
Release files / llama_index_packs_diff_private_simple_dataset-0.4.1.tar.gz
| Download URL | llama_index_packs_diff_private_simple_dataset-0.4.1.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fe55e461fe275cd07f0466a1c062d89c67434a8eb02af8575acea9416400154
|
|
BLAKE2b-256 checksum How to use checksums |
b5a06e2f3f90673733ebcd1fe8137cfd9aa8daeccaf749e352f0019e1f20a9b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / llama_index_packs_diff_private_simple_dataset-0.4.1-py3-none-any.whl
| Download URL | llama_index_packs_diff_private_simple_dataset-0.4.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b88ba65317832931d36153ab1ab35420172068ed622de9fafd6c0675a4b8a26a
|
|
BLAKE2b-256 checksum How to use checksums |
ccf93bbd765b4ebd01ef62334330e1fe431dbf21925c9d5f06578944c2b13252
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Security for llama-index-packs-diff-private-simple-dataset 0.4.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.