Optimize Jobs
You can use the built in optimizer to find the optimal model and hyperparameters for your jobs.
In this guide, we will use the lab
from the phospho
package to run an event extraction task on a dataset.
First, we will run on a subset of the dataset with several models:
- the OpenAI API
- the Mistral AI API
- a local Ollama model
Then, we will use the lab
optimizer to find the best model and hyperparameters for the task in term of performance, speed and price.
Finally, we will use the lab
to run the best model on the full dataset and compare the results with the subset.
Feel free to only use the APIs or Ollama models you want.
Installation and setup
You will need:
- an OpenAI API key (find yours here)
- a Mistral AI API key (find yours here)
- Ollama running on your local machine, with the Mistral 7B model installed. You can find the installation instructions for Ollama here
(Optional) Install Ollama
If you want to use Ollama, install the Ollama app on your desktop, launch it, and install the python package to interact with it:
Test your installation by running the following script:
Define the phospho workload and jobs
Loading a message dataset
Let’s load a dataset of messages from huggingface, so we can run our extraction job on it.
Apply the optimizer to the pipeline
For the purpose of this demo, we consider a considertion good enough if it matches gpt-4 on at least 80% of the dataset. Good old Paretto.
You can check the current configuration of the workload with:
To run the optimizer, just run the following:
For us, mistral:mistral-small-latest
was selected.
Run our workload on the full dataset, with optimized parameters
We can now run the workload on the full dataset, with the optimized model.
Analyze the results
In our case:
Going further
You can use the lab
to run other tasks, such as:
- Named Entity Recognition
- Sentiment Analysis
- Evaluations
- And more!
You can also play around with differnet models, different hyperparameters, and different datasets.
You want to have such analysis on your own LLM app, in real time? Check out the cloud hosted version of phospho, available on phospho.ai
Was this page helpful?