Path: blob/master/cpd4.8/notebooks/python_sdk/deployments/foundation_models/Use watsonx, and Google `flan-t5-xxl` to analyze car rental customer satisfaction from text.ipynb
6408 views
Use watsonx, and Google flan-t5-xxl
to analyze car rental customer satisfaction from text
Disclaimers
Use only Projects and Spaces that are available in watsonx context.
Notebook content
This notebook contains the steps and code to demonstrate support of text sentiment analysis in watsonx. It introduces commands for data retrieval, model testing and scoring.
Some familiarity with Python is helpful. This notebook uses Python 3.10.
Learning goal
The goal of this notebook is to demonstrate how to use flan-t5-xxl
model to analyze customer satisfaction from text.
Contents
This notebook contains the following parts:
Install and import the datasets
and dependecies
Connection to WML
Authenticate the Watson Machine Learning service on IBM Cloud Pack for Data. You need to provide platform url
, your username
and api_key
.
Alternatively you can use username
and password
to authenticate WML services.
Defining the project id
The Foundation Model requires project id that provides the context for the call. We will obtain the id from the project in which this notebook runs. Otherwise, please provide the project id.
Download the car_rental_training_data
dataset. The dataset provides insight about customers opinions on car rental. It has a label that consists of values: unsatisfied, satisfied.
Examine donwloaded data.
Define label map.
Inspect data labels distribution.
Prepare train and test sets.
List available models
All avaliable models are presented under ModelTypes class. For more information refer to documentation.
You need to specify model_id
that will be used for inferencing:
Defining the model parameters
You might need to adjust model parameters
for different models or tasks, to do so please refer to documentation.
Initialize the model
Initialize the Model
class with previous set params.
Model's details
Define instructions for the model.
Prepare model inputs - build zero-shot examples from the test set.
Prepare model inputs - build few-shot examples. To build a few-shot example few instances of training data phrases are passed together with the reference sentiment and then appended with a test data phrase.
In this notebook, training phrases are stratified over all possible sentiments for each test case.
Inspect an exemplary few-shot prompt.
Analyze the satisfaction using Google flan-t5-xxl
model.
Analyze the sentiment for a sample of zero-shot inputs from the test set.
Explore model output.
Get the true labels.
Get the sentiment labels returned by the flan-t5-xxl
model.
Calculate the accuracy score.
HINT: Sentiments generated using few-shot input prompts might provide better performance in terms of accuracy then the zero-shot ones. Following cells present test scores for zero-shot prompts received for the flan-t5-xxl
model on the whole test set from this notebook.
The zero-shot test accuracy score:
Summary and next steps
You successfully completed this notebook!.
You learned how to analyze car rental customer satisfaction with Google's flan-t5-xxl
on watsonx.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Mateusz Szewczyk, Software Engineer at Watson Machine Learning.
Copyright © 2023-2025 IBM. This notebook and its source code are released under the terms of the MIT License.