Get startedGet started for free

Text generation

1. Text generation

Welcome back! Let's now explore text generation and its real-world applications.

2. How is the output generated?

When we send a prompt to a chat model, it returns the text that it believes is most likely to complete the conversation, which it infers based on the data the model was developed on. If I introduce myself in the prompt, the model greets me in response and asks how it can assist. It's important to note that we may not get the same response from the model every time, as the responses are non-deterministic - in other words, there will always be a degree of uncertainty in the model response.

3. The randomness trade-off

There are many use cases where randomness is undesirable. Think of a customer service chatbot—we wouldn't want the chatbot to provide different guidance to customers with the same issue. However, we would like the model to be flexible to different inputs, so there's often a trade-off in the amount of randomness.

4. Controlling response randomness

We can control the amount of randomness in the response using the temperature parameter. temperature is set to one by default, but ranges from zero to two, where zero is almost entirely deterministic and two is highly random. If we add a temperature of two here, we can see that the model response starts off ok, but quickly spirals into nonsense. Explore the temperature value to find the best value for the use case.

5. Text generation: marketing

As well as completing conversations, text generation can also be used to create brand-new content! For example, let's generate a tagline for an electric car. A well-crafted prompt should be clear and detailed to guide the model's response. Here's what we got—that's not bad! You might have noticed that DeepSeek has a tendency to be quite chatty, which is by design, as it's often used in chatbots.

6. Cleaning up responses

If we want to remove these extra explanations and formatting, we can add an additional instruction to the prompt for the model to return only the tagline and no formatting. There we have it! And notice again, we got a different tagline from the last time.

7. Text generation: product description

Another common use case is creating product descriptions. Here, we'll create a description for a new smartwatch aimed at fitness enthusiasts and busy professionals alike. We start the prompt with the product features, and finish with instructions on the desired tone and target audience. Passing this prompt to the chat model in a request,

8. Text generation: product description

we get something that already looks good enough for any e-commerce website. If we need to iterate further, we can always update the original prompt with more specific information and re-run our request. In the next video, we'll explore how to provide examples to the model, which can greatly improve text generation consistency, but for now,

9. Let's practice!

enjoy exploring use cases for text generation in the exercises!