Session Ready
Exercise

Generate sentence with context

In this exercise, you are going to experiment on a pre-trained model for text generation. The model is already loaded in the environment in the model variable, as well as the initialize_params() and get_next_token() functions.

This later uses the pre-trained model to predict the next character and return three variables: the next character next_char, the updated sentence res and the the shifted text seq that will be used to predict the next one.

You will define a function that receives a pre-trained model and a string that will be the start of the generated sentence as inputs. This is a good practice to generate text with context. The sentence limit of 100 characters is an example, you can use other limits (or even without limit) in your applications.

Instructions
100 XP
  • Pass the initial_text variable to the initialize_params() function.
  • Create conditions to stop the loop when the counter reaches 100 or a dot (r'.') is found.
  • Pass the initial values res, seq to the get_next_token() function to obtain the next char.
  • Print the example phrase generated by the defined function.