Experimenting with top_p
Same launch, new products! Luna Gear needs three names for upcoming add-ons: a built-in phone-charger lid, an insulated water-bottle holder, and a clip-on side pocket. They want one focused list that sounds established and one quirky list that stands out.
The anthropic
library, client
and addons_list
string are preloaded.
This exercise is part of the course
Introduction to Claude Models
Exercise instructions
- Set a low
top_p
value for focused, conventional vocabulary (0.1-0.3). - Set a high
top_p
value for diverse, creative vocabulary (0.7-0.9). - Print both response contents to display the generated names.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Focused naming with low top_p
focused_response = client.messages.create(
model="claude-3-7-sonnet-latest", top_p=____, max_tokens=50,
messages=[{"role": "user",
"content": f"Generate feature names for each of these TerraPack add-ons: {addons_list}"}])
# Diverse naming with high top_p
diverse_response = client.messages.create(
model="claude-3-7-sonnet-latest", top_p=____, max_tokens=50,
messages=[{"role": "user",
"content": f"Generate feature names for each of these TerraPack add-ons: {addons_list}"}])
print("Focused names:", ____)
print("\nDiverse names:", ____)