To fine tune a model for data classification based on Gemini 2.5 flash model. So here is what we're going to do. We will fine tune a model to classify text and then test it out using our prompt gallery.
You can enter instruction to classify tex and then the model will return postive, neutal or negative as output as shown here.
To get started, go to Vertext AI -> then select Tuning. Then click on "Create tuned model".
Provide a name to it and select the default. Click on "Continue".
Next, we will provide dataset that you can get from github here.
We need to provide the dataset. Provide the following details when you are in the next screen.
For tuning dataset, select the 100 sample. And for validation, select the 20 sample dataset.
In case you're curious, the dataset looks like this. It follows Gemini new format requirements.
{"systemInstruction": {"role": "", "parts": [{"text":
"Classify the sentiment of the following text."}]}, "contents":
[{"role": "user", "parts": [{"text": "Brilliant! Will buy again."}]}, {"role":
"model", "parts": [{"text": "Positive"}]}]}
{"systemInstruction": {"role": "", "parts": [{"text":
"Classify the sentiment of the following text."}]}, "contents":
[{"role": "user", "parts": [{"text": "Brilliant! Will buy again."}]},
{"role": "model", "parts": [{"text": "Positive"}]}]}
Once you're done, click on "Start tuning". It does take sometime to do it.
When the trainig completes, you can see something like this
And you can see some metrics here
To test it, click on "Test" button as shown here
System prompt appears and here, you can ask it to classify text. Then provide some of the sample data from your training and you will see the model would output "positive" or etc.
Once the model has been successfully fine tuned, it gets deploy automatically to an endpoint that you can access using REST API.
The endpoint would have the following pattern
https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/endpoints/ENDPOINT_ID
To be able to hit your endpoint, you need to ensure that the configuration is right.
Let's issue a curl command to get back some responses. To get the bearer token for your request, you can simply run
gcloud auth print-access-token
Next, run the following command to get some predictions
curl --location 'your-model-deployment-endpooint:streamGenerateContent' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-gcloud-bearer-token' \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Brilliant! Will buy again."
}
]
}
]
}'
And you should be able to get some output
There's a way to get sample for your testing. Go to Vertex AI -> Tuning -> select your model -> click on the blue "Test" button.
Then a model prompt appears. Then you can prompt your model like what we did above earlier. Then under "Get code" -> select cUrl as shown in the diagram below.
Then we would be able to get a sample payload for our testing.
Comments