$git clone https://github.com/CHATS-lab/verbalized-sampling---
| 1 | <div align="center"> |
| 2 | <h1>Verbalized Sampling: How to Mitigate Mode Collapse and Unlock LLM Diversity</h1> |
| 3 | |
| 4 | [](https://pypi.org/project/verbalized-sampling/) [](https://pypi.org/project/verbalized-sampling/) [](https://www.verbalized-sampling.com/) [](https://arxiv.org/abs/2510.01171) [](https://simonucl.notion.site/verbalized-sampling) [](https://huggingface.co/collections/CHATS-Lab/verbalized-sampling) |
| 5 | </div> |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | <p align="center"> |
| 10 | <a href="#quickstart">Quickstart</a> | |
| 11 | <a href="#installation-and-usage">Install</a> | |
| 12 | <a href="#colab-notebooks">Colab</a> | |
| 13 | <a href="#reproducing-paper-results">Reproduce Results</a> | |
| 14 | <a href="https://arxiv.org/abs/2510.01171">Paper</a> | |
| 15 | <a href="https://simonucl.notion.site/verbalized-sampling">Blog</a> | |
| 16 | <a href="https://tinyurl.com/vs-gallery">Examples</a> | |
| 17 | <a href="https://x.com/dch/status/1978471395173740900">Practical Tips</a> | |
| 18 | <a href="https://www.youtube.com/watch?v=VoBdywmdim0">Podcast</a> | |
| 19 | <a href="#citation">Citation</a> |
| 20 | </p> |
| 21 | |
| 22 | **Verbalized Sampling (VS)** is a simple prompting strategy that improves LLM diversity by 2-3x. It works by asking the model to generate multiple responses with their probabilities, then sampling from this distribution. VS is **training-free** (works with any LLM via prompting), **model-agnostic** (GPT, Claude, Gemini, Llama, etc.), **orthogonal to temperature**, and effective across tasks like **creative writing**, **social simulation**, **synthetic data generation**, and **open-ended QA**. |
| 23 | |
| 24 | ## Quickstart |
| 25 | |
| 26 | To try Verbalized Sampling, just copy and paste this into any chatbot (ChatGPT, Claude, Gemini, etc.). For best results, we recommend starting with models like GPT-5, Claude 4 Opus, and Gemini 2.5 Pro: |
| 27 | |
| 28 | ``` |
| 29 | <instructions> |
| 30 | Generate 5 responses to the user query, each within a separate <response> tag. Each <response> must include a <text> and a numeric <probability>. |
| 31 | Please sample at random from the tails of the distribution, such that the probability of each response is less than 0.10. |
| 32 | </instructions> |
| 33 | |
| 34 | Tell me a short story about a bear. |
| 35 | ``` |
| 36 | |
| 37 | If you want more stories, just respond and ask `Tell me 5 more stories` in the same conversation. For even better results, paste this into a `system prompt` instead: |
| 38 | |
| 39 | ``` |
| 40 | You are a helpful assistant. For each query, please generate a set of five possible responses, each within a separate <response> tag. Each <response> must include a <text> and a numeric <probability>. |
| 41 | Please sample at random from the tails of the distribution, such that the probability of each response is less than 0.10. |
| 42 | ``` |
| 43 | For practical tips on getting the most out of this technique and general troubleshooting, please refer to this [X/Twitter thread](https://x.com/dch/status/1978471395173740900)! |
| 44 | |
| 45 | ## Installation and Usage |
| 46 | |
| 47 | For all of the above in a single function call, the ability to automatically sample from the verbalized responses, and LangChain integration, use our Python package: |
| 48 | |
| 49 | ```bash |
| 50 | pip install verbalized-sampling |
| 51 | ``` |
| 52 | |
| 53 | ```python |
| 54 | # Set OPENAI_API_KEY or OPENROUTER_API_KEY in bash |
| 55 | from verbalized_sampling import verbalize |
| 56 | |
| 57 | # Generate distribution of responses |
| 58 | dist = verbalize("Tell me a joke", k=5, tau=0.10, temperature=0.9) |
| 59 | |
| 60 | # Sample from the distribution |
| 61 | joke = dist.sample(seed=42) |
| 62 | print(joke.text) |
| 63 | ``` |
| 64 | |
| 65 | ## Colab Notebooks |
| 66 | |
| 67 | Here are some examples of how to use verbalized sampling for generating more diverse storie |