Skip to content

Prompt engineering exercise answers

Exercise Description
0. Zero-shot generation Generate a marketing message with 5 sentences
1. Generate sentences Write three sentences about birds
2. Working with JSON Generate a JSON file
3. Summarize Summarize a short story
4. Work with code Translate from C++ to C

0. Zero-shot generation

Goal

Generate a marketing message with 5 sentences

A possible solution (English)

A possible solution (Spanish)

Info

Different models may require different instructions. In the case of larger and "creative" models, it may be necessary for the instructions to be more explicit.

It's tempting to think that larger models are "smarter." There's some truth to that, but these models can also be overly creative. As you've seen, you may need to be very explicit to get the desired outcome. Keep in mind that creativity is not necessarily a problem. This is one of the appeals of generative AI and foundational models. But if you're not trying to generate creative content (as in this example: you want your email to mention specific points and not add fictional content), you might consider using a smaller (and less creative) model or providing stricter instructions to control the models.

Tip

You can also see the effect of changing some configuration parameters:

  • Temperature: The higher the value, the more creative the model will be.
  • Top P: A lower value means less variability.
  • Top K: A lower value means less variability.

Click here to go back to this exercise

1. Generate

Goal

Write three sentences about birds

A possible solution (English)

A possible solution (Spanish)

Info

The models handle output requirements differently. Some models (like the flan models) excel with text output (at least with zero-shot prompting). You can guide the output by prompting with a "list" suggestion. Other models, such as the mpt-7b-instruct2, and to a lesser extent, the gpt-geox-20b model, are more capable of understanding the concept of list output without additional instructions.

Click here to go back to this exercise

2. Working with JSON

Goal

Generate a JSON file

A possible solution (English)

A possible solution (Spanish)

Info

While flan models have shown good ability to generate text in natural language, they don't seem to understand how to generate JSON output, at least not with zero-shot prompting. The granite-13b-instruct-v2 and starcoder-15.5bmodel models can generate good JSON output. Different models are trained/tailored for different tasks and abilities. You should look for models trained with domain-specific data focusing on various data structures and capabilities. Also, experiment with the use of Stop sequences to prevent a model from generating unwanted text.

Click here to go back to this exercise

3. Summarize

Goal

Summarize one of the following short stories

A possible solution (English)

A possible solution (Spanish)

Click here to go back to this exercise

4. Code

Goal

Translate from C++ to C

A possible solution

Click here to go back to this exercise