W7S169G Exercise Guide
W7S169G Exercise Guide
W7S169G Exercise Guide
IBM Learning
IBM Training
IBM watsonx Foundations
IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM
representative for information on the products and services currently available in your area. Any reference to an IBM product, program,
or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent
product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user's
responsibility to evaluate and verify the operation of any non-IBM product, program, or service.
IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this
document does not grant you any license to these patents. You can send license inquiries, in writing, to:
INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do not allow disclaimer of express or implied
warranties in certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein;
these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s)
and/or the program(s) described in this publication at any time without notice.
Any references in this information to non-IBM websites are provided for convenience only and do not in any manner serve as an
endorsement of those websites. The materials at those websites are not part of the materials for this IBM product and use of those
websites is at your own risk.
IBM may use or distribute any of the information you provide in any way it believes appropriate without incurring any obligation to you.
Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other
publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any
other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of
those products.
This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible,
the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to
actual people or business enterprises is entirely coincidental.
Trademarks
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many
jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM
trademarks is available on the web at “Copyright and trademark information” at www.ibm.com/legal/copytrade.shtml.
This document may not be reproduced in whole or in part without the prior written permission of IBM.
US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
Trademarks
The reader should recognize that the following terms, which appear in the content of this training
document, are official trademarks of IBM or other companies:
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International
Business Machines Corp., registered in many jurisdictions worldwide.
The following are trademarks of International Business Machines Corporation, registered in many
jurisdictions worldwide:
IBM Cloud Pak for Data
Watson Machine Learning
Watson Studio
Watson Knowledge Catalog
Db2
Db2 Big SQL
Db2 Warehouse
Data Virtualization
IBM Cloud File Storage
OpenShift® and Red Hat® are trademarks or registered trademarks of Red Hat, Inc. or its
subsidiaries in the United States and other countries.
Adobe, and the Adobe logo, are either registered trademarks or trademarks of Adobe Systems
Incorporated in the United States, and/or other countries.
Microsoft, Windows, and the Windows logo are trademarks of Microsoft Corporation in the United
States, other countries, or both.
Other product and service names might be trademarks of IBM or other companies.
The rest of the prompt engineering exercises are done in the IBM public cloud by using
the watsonx.ai platform.
Contents
Trademarks .................................................................................................................................................... 3
Exercise 1. Prepare your lab environment ........................................................................................................ 5
1. Prepare your lab environment .................................................................................................................. 6
Section 1. Create an IBM Cloud account. .................................................................................................. 6
Section 2. Log in to watsonx ..................................................................................................................... 6
Section 3. Set up your lab environment.................................................................................................... 9
Exercise 2. Prompt engineering ...................................................................................................................... 16
2. Introduction ............................................................................................................................................ 17
Section 1. Zero-shot prompting .............................................................................................................. 17
Section 2. Single-shot and two-shot prompting ..................................................................................... 20
Section 3. Inspect the foundation model Python code........................................................................... 25
Section 4. Model options and tokens...................................................................................................... 30
Exercise 3. Exercise review and wrap-up ........................................................................................................ 35
3. Exercise review and wrap-up .................................................................................................................. 36
Overview
In this exercise, you set up your IBM Cloud account and log in to the watsox platform. If you
already have an account, you can skip the creation of an IBM Cloud account.
After the creation of an IBM Cloud account, you log in to the IBM cloud and switch to the watsonx
platform.
Objectives
After completing this exercise, you should have an existing IBM Cloud account and be logged in to
watsonx.
To complete all exercises, you need to have a running instance of Watson Machine Learning. You
create a Watson Machine Learning service by using the Lite plan and associate the service with a
project.
At the end of this exercise, you have access to the wasonx.ai prompt lab.
Requirements
__ 2. Click the Navigation Menu (four horizontal bars) in the upper-left quadrant of the page,
scroll down and click watsonx. If you want to experiment with Cloud Pak for Data and all
the data and AI services that the platform provides, you can also select Cloud Pak for
Data.
__ 4. Scroll to the end of the panel on the left and click Log in with your IBM Cloud
credentials.
__ 5. A pop-up window containing the watsonx welcome message appears. Click the check-box
and accept the terms of using the software.
__ 6. Click x in the upper-right quadrant of the pop-up message to skip the tour. The watsonx
welcome screen appears.
Before you can experiment with the Prompt Lab, you need to create a Watson Machine Learning
instance.
__ 4. Enter Prompt Lab in the Name field, attach object storage by clicking on an object storage
instance from the drop-down list and click Create.
__ 5.
__ 6. Attach object storage by clicking on an object storage instance from the drop-down list and
click Create.
__ 7. Click the Assets tab.
__ 8. Click the Navigation menu and click Services > Services catalog.
__ 9. Click the Watson Machine Learning tile under the AI / Machine Learning category.
__ 10. Verify that the Lite plan is selected and click Create.
__ 14. Although the Watson Machine Learning service was created, the service instance needs
to be associated to the project to be able to experiment with the Prompt Lab. Click
Associate service.
__ 15. Click the checkbox next to the Watson Machine Learning instance and click Associate.
__ 16. Click the Navigation menu and click Home to get back to the watsonx welcome screen.
__ 17. Click the Experiment with foundation models and build prompts tile.
You are now ready to start experimenting with the Prompt Lab.
End of exercise
Overview
This exercise covers the following tasks:
• Experimenting with the prompt Lab
• Creating a series of ever more complex prompts
• Inspecting the Python code that the prompt Lab generates
• Changing the default Prompt Lab settings
Introduction
This exercise introduces you to the Prompt Lab in watsonx. First, you experiment with simple
prompts to get a feel for the environment. Second, you create more elaborate prompts to steer the
underlying foundation model in the right direction. Third, you inspect the underlying Python code
generated by the lab. Fourth, you change the underlying foundation model and experiment with
different lab settings.
After this exercise, you should be able to set up and experiment with prompts in the Prompt Lab.
Requirements
• Access to IBM Cloud Pak for Data, IBM watsonx.
• Knowledge of working with graphical user interfaces.
2. Introduction
Verify that you are still logged in to the IBM Cloud and watsonx. If not, go back to Exercise 1 and
revisit how to log in to the IBM Cloud and watsonx.
Erik is new to prompt engineering, so he will first explore the interface with some basic prompts
and gradually increase the complexity of the prompts as he gains more experience.
After the exercise, Erik will recommend some use cases for generative AI and foundation models
to the company.
This setting removes any potentially harmful input and output text, such as hate speech,
abuse, or profanity. The default setting is for the guardrails to be off (no filtering of input or
output text).
__ 2. Scroll to the end of the displayed Prompt Lab page and type in the following prompt in the
Input: text box under the Try section.
The response is underwhelming. After exploring the sample prompts from the IBM
Documentation Tips for writing foundation model prompts: prompt engineering — Docs |
IBM watsonx, Erik decides to take “baby steps” and gradually increase the complexity of
the prompt, incorporating what he learned from studying the tips for writing prompts.
__ 4. A tip to receive a structured response is to include a cue to start the response in the
wanted structure. In this case, add the two characters, "1.", to the prompt. This small
change might improve the response. Click New test + .
__ 5. Add a line of text with “1.” to the previous prompt. Click Generate.
The response is still underwhelming. Erik decides to investigate the current model
parameters.
__ 6. Click the Model parameters icon in the upper-right quadrant (two horizontal lines with
offset circles). Scroll down and inspect the Stopping criteria.
The reason for the underwhelming result might be the minimum and the maximum number
of tokens setting. The Max tokens is set to 20, which gives the model little leeway to
generate a meaningful response (on average 1 token is equivalent to 4 characters).
__ 7. Delete the previous prompts and add a new test with the same prompt. Change the Max
tokens value to 100 and the Min tokens to 50 to “force” the foundation model to generate a
longer response (more characters).
__ 8. Click Generate. The results improved dramatically, but there is much repetition of the
string “Start a dog-“ in the response. After further consideration, Erik decides to increase
the repetition penalty from 1 to 2.
__ 9. Changing the Repetition penalty in the Model parameters panel from 1 to 2 to minimize
repetition. Slide the slider from 1 to 2 or directly type in 2 in the Repetition penalty number
box.
Increasing the repetition penalty creates a dramatic improvement over the previous
responses.
The response is more concise and an improvement over the previous response.
__ 2. Add another example of how to start a landscaping business.
The important keywords trying to steer the model in the right direction are “Act”,
“entrepreneur”, “one-person”, and “successful”.
Click Generate.
This change results in the best response yet. It contains some innovative ideas and
practical advice for starting a dog-walking business.
__ 4. It is always a good idea to test your prompt on multiple examples before you assume that
the prompt is working as intended. Erik decides to give the foundation model one more
example to test its effectiveness in teasing out responses from the foundation model. Erik
decides to prompt the foundation model to list ideas to start a car detailing business.
At the beginning of the prompt, you saw that there are two ways to construct your prompt:
using the Structured or the Freeform interface. Erik has so far focused on the Structured
way of creating a prompt and is curious how it differs from the Freeform way. Click the
Freeform option to switch interfaces.
The interface changes and you are viewing one large prompt containing all the information
previously completed.
After you become familiar with the Prompt Lab, it might be easier, faster, and more
convenient to construct the prompt in the unstructured or freeform way. The response from
the foundation model is unaffected by which interface you prefer.
__ 6. If you would like to generate alternative responses, change the Decoding parameter from
Greedy to Sampling. Selecting the sampling parameter option instructs the foundation
model to customize the variability of word selection. This setting change lets the model
create alternative responses instead of re-creating a previous response. Click Sampling in
the Decoding option.
__ 7. Click Generate.
Important: After you set the decoding parameter to Sampling, your responses might be different
from what is given in this course. This result is as expected as more variability in word selection
might lead to different responses.
__ 5. Click the Notebook tile and give the Python notebook a descriptive name, such as Prompt
Lab. Click the View in project after saving box. Click Save to save the notebook.
The Notebook opens and you can inspect the code, modify the code, and use the notebook
as a template for other Prompt Lab experiments.
Cell 6 of the Jupyter Notebook contains the Python prompt equivalent of what you input in
the Prompt Lab GUI.
__ b. Click API keys from the menu on the left of the screen.
__ c. Click Create.
__ d. Enter a name and description for your API key, such as watsonx and watsonx API key.
__ 9. Click the Home | IBM watsonx tab in your browser to return to the watsonx GUI and your
Jupyter Notebook.
__ 10. Click Cell > Run All to run the notebook.
__ 11. Paste your API key in the browser when asked and press Enter.
__ 12. The rest of the Notebook is executed and the following response is generated.
The response is slightly different from what you got previously as the Decoding parameter
is set to Sampling. The response is pleasing again.
The following models are available (this list might change over time).
based on the same underlying model family (Flan-T5). Read the Note and terms of use and
click Select model.
__ 5. Remove the previous response from the Prompt Lab and click Generate to generate a new
response.
The response is acceptable and Erik can do some more experiments to evaluate this
model for future use.
Information: Each time you enter a prompt, your “input tokens” and “generated tokens” will update
in the lower-left quadrant of the interface. Tokens are an important concept to understand as they
constrain the performance of your model and determine the cost of using foundation models.
Tokens are not a 1:1 match with words in natural language. On average, one token is equal to 4
characters. Before sending your prompt to the model, the prompt's text is tokenized or broken into
smaller subsets of characters than can be better understood by the model. The correlation
between words and tokens is complex. A single word might be broken into multiple tokens,
depending on context (such as where the word appears in a sentence, or what the surrounding
words are). Spaces, newline characters, and punctuation might be included in tokens. The way
words are broken into tokens varies from language to language and from model to model.
Important: It is important to monitor your token usage to know how much information you are
feeding into the model with each prompt, and how much text is generated for you. Depending on
the model selected in Prompt Builder, you see a max of 2048 or 4096 tokens. Keep in mind that
the more expressive you are with your prompt instructions, the less room the model has to
respond back to you. The number of tokens used (input plus generated text) can be found in the
lower-left quadrant of the interface.
__ 6. Click the Sample prompts, Saved prompts and History icons in the left panel of your
prompt session to get additional information on tasks you can perform with suggested
prompts, saved prompts, and a history of your current prompt session.
The Sample prompts might be useful for suggesting more tasks that a foundation model
might solve, and how to get started with a particular task.
The last task for Erik is to recommend to his manager how this new technology might be used in
their company. This recommendation is covered in the next exercise.
End of exercise
Overview
This exercise covers the following tasks:
• Summarizing what you learned and achieved working through the labs.
• Identifying use cases for foundation models in the health products company.
Introduction
This section reviews what you learned experimenting with the Prompt Lab and provides
suggestions for use cases that might benefit the company in their endeavor to master this new
technology, called foundation models.
After this exercise, you should be able to talk intelligently about generative AI and foundation
models with colleagues.
Requirements
• Access to IBM Cloud Pak for Data, IBM watsonx.
• Knowledge of working with graphical user interfaces.