Optimizing Prompts
Optimize your prompts and capture nuanced requirements
Nomadic’s prompt tuning capabilities enable you to discover and capture nuanced prompt requirements for optimal performance.
When building LLM applications, it’s crucial to recognize that some prompts are more performant than others. MLEs often experiment with hundreds of prompts before discovering optimal prompts. Nomadic makes it easy for you to manage, experiment, and set the best prompting approaches within your system.
Below is a basic example of how you can use Nomadic’s SDK to systematically test different prompt approaches (technique, complexity, and task focus) to discover the best-performing prompt approach.
1. Import Nomadic libraries
2. Set up your project directory and API keys
Make sure you’ve specified the API key to access your model (e.g. OpenAI, Mistral) in {PROJECT_DIRECTORY}/.env.dev
. Nomadic will then establish the connection to your model endpoints.
3. Add a prompt template
4. Upload Evaluation Dataset
Upload your own dataset for evaluating experiments.
Each dataset row should have:
Context
Instruction
Question
Answer
Key | Required | Description | Example |
---|---|---|---|
Context | No | Enhances the prompt. Supplies additional background information to help the model generate accurate responses. | “You are a doctor writing a visit note from a transcript of the doctor-patient conversation.” |
Instruction | No | Enhances the prompt. Provides specific guidance to the model on what action to perform. | “Absolutely do not hallucinate. Capture only factual information.” |
Question | Yes | The user input or query that prompts the model to generate a response. This is the only required key. | “What were the main topics discussed?” |
Answer | No, required only if using a supervised evaluator such as cosine similarity | The expected output or response from the model, which serves as the benchmark for evaluation. | “Investment strategies, retirement planning, and risk management.” |
Example Dataset:
5. Define Prompt Techniques
Nomadic enables you to create a diverse set of prompts from a target prompt.
You can experiment with the following prompt parameters:
Key | Description | Required | Supported Parameters |
---|---|---|---|
prompt_tuning_approach | Choose from prompting techniques. | false | zero-shot - The model attempts to answer without specific examples, few-shot - Provides a few examples to guide the model’s response, chain-of-thought -Encourages the model to show its reasoning process |
prompt_tuning_complexity | Adjust the level of detail in the prompt. | false | simple - Creates straightforward, direct prompts, complex - Generates more detailed, nuanced prompts |
prompt_tuning_focus | Focus on different tasks. | false | Common options (customizable): fact extraction , action points , summary , simplify language , change tone , British English usage , template: [template_format] |
6. Define your evaluation function
Choose one of our off-the shelf evaluation metrics, or define a custom evaluator.
Standard Evaluator
See Evaluations.
Custom Evaluator
Define a custom metric using the Nomadic custom_evaluate
method.
Sample Custom Evaluator:
7. Create your Experiment using the Nomadic library
Experiment with your prompts by leveraging the same Nomadic experimentation library as generic experiments.
8. Run your Experiment!
9. Interpret Results
To identify the best-performing prompt technique, run
The experiment.visualize_results()
function provides a comprehensive visual analysis & statistical summary of the experiment results, focusing on the score distribution and its relationship with various hyperparameters.
To test signifiance, test_significance
runs a Mann-Whitney U test to compare the top-performing parameter combinations against the rest of the results.