Panza is an automated email assistant customized to your writing style and past email history. \ Its main features are as follows:
mbox
format (see tutorial below).For most email clients, it is possible to download a user's past emails in a machine-friendly .mbox format. For example, GMail allows you to do this via Google Takeout, whereas Thunderbird allows one to do this via various plugins.
One key part of Panza is a dataset-generation technique we call data playback: Given some of your past emails in .mbox format, we automatically create a training set for Panza by using a pretrained LLM to summarize the emails in instruction form; each email becomes a (synthetic instruction, real email)
pair.
Given a dataset consisting of all pairs, we use these pairs to "play back" your sent emails: the LLM receives only the instruction, and has to generate the "ground truth" email as a training target.
We find that this approach is very useful for the LLM to "learn" the user's writing style.
We then use parameter-efficient finetuning to train the LLM on this dataset, locally. We found that we get the best results with the RoSA method, which combines low-rank (LoRA) and sparse finetuning. If parameter efficiency is not a concern, that is, you have a more powerful GPU, then regular, full-rank/full-parameter finetuning can also be used. We find that a moderate amount of further training strikes the right balance between matching the writer's style without memorizing irrelevant details in past emails.
Once we have a custom user model, Panza can be run locally together with a Retrieval-Augmented Generation (RAG) module. Specifically, this functionality stores past emails in a database and provides a few relevant emails as context for each new query. This allows Panza to better insert specific details, such as a writer's contact information or frequently used Zoom links.
The overall structure of Panza is as follows:
source prepare_env.sh
. This script will create a conda environment named panza
and install the required packages.As an alternative to the conda option above, you can run the following commands to pull a docker image with all the dependencies installed.
docker pull istdaslab/panzamail
or alternatively, you can build the image yourself:
docker build . -f Dockerfile -t istdaslab/panzamail
Then run it with:
docker run -it --gpus all istdaslab/panzamail /bin/bash
In the docker you can activate the panza
environment with:
micromamba activate panza
To quickly get started with building your own personalized email assistant, follow the steps bellow:
At the end of this step you should have the downloaded emails placed inside data/Sent.mbox
.
Panza is configured through a set of environment variables defined in scripts/config.sh
and shared along all running scripts.
The LLM prompt is controlled by a set of prompt_preambles
that give the model more insight about its role, the user and how to reuse existing emails for Retrieval-Augmented Generation (RAG). See more details in the prompting section.
:warning: Before continuing, make sure you complete the following setup:
PANZA_EMAIL_ADDRESS
inside scripts/config.sh
with your own email address.prompt_preambles/user_preamble.txt
with your own information. If you choose, this can even be empty.huggingface-cli login
.wandb login
. Then, set PANZA_WANDB_DISABLED=False
in scripts/config.sh
.You are now ready to move to scripts
.
cd scripts
Run ./extract_emails.sh
. This extracts your emails in text format to data/<username>_clean.jsonl
which you can manually inspect.
If you wish to eliminate any emails from the training set (e.g. containing certain personal information), you can simply remove the corresponding rows.
Simply run ./prepare_dataset.sh
.
data/<username>_clean_summarized.jsonl
and you can inspect the "summary"
field.data/train.jsonl
and data/test.jsonl
.data/<username>.pkl
and data/<username>.faiss
.
We currently support LLaMA3-8B-Instruct
and Mistral-Instruct-v0.2
LLMs as base models; the former is the default, but we obtained good results with either model.
[Recommended] For parameter efficient fine-tuning, run ./train_rosa.sh
.
If a larger GPU is available and full-parameter fine-tuning is possible, run ./train_fft.sh
.
We have prepopulated the training scripts with parameter values that worked best for us. We recommend you try those first, but you can also experiment with different hyper-parameters by passing extra arguments to the training script, such as LR
, LORA_LR
, NUM_EPOCHS
. All the trained models are saved in the checkpoints
directory.
Examples:
./train_rosa.sh # Will use the default parameters.
./train_rosa.sh LR=1e-6 LORA_LR=1e-6 NUM_EPOCHS=7 # Will override LR, LORA_LR, and NUM_EPOCHS.
./run_panza_gui.sh MODEL=<path-to-your-trained-model>
to serve the trained model in a friendly GUI../run_panza_cli.sh
instead.You can experiment with the following arguments:
MODEL
is not specified, it will use a pretrained Meta-Llama-3-8B-Instruct
model by default, although Panza also works with Mistral-7B-Instruct-v2
. Try it out to compare the syle difference!PANZA_DISABLE_RAG_INFERENCE=1
.Example:
./run_panza_gui.sh \
MODEL=/local/path/to/this/repo/checkpoints/models/panza-rosa_1e-6-seed42_7908 \
PANZA_DISABLE_RAG_INFERENCE=0 # this is the default behaviour, so you can omit it
:email: Have fun with your new email writing assistant! :email:
Panza was conceived by Nir Shavit and Dan Alistarh and built by the Distributed Algorithms and Systems group at IST Austria. The contributors are (in alphabetical order):
Dan Alistarh, Eugenia Iofinova, Eldar Kurtic, Ilya Markov, Armand Nicolicioiu, Mahdi Nikdan, Andrei Panferov, and Nir Shavit.
Contact: dan.alistarh@ist.ac.at
We thank our collaborators Michael Goin and Tony Wang at NeuralMagic and MIT for their helpful testing and feedback.