Now that you have a trained language model, it can be used. In this case, you can use it to generate new sequences of text that have the same statistical properties as the source text. This is not practical, at least not for this example, but it gives a concrete example of what the language model has learned.
- Begin by loading the training sequences again. You may do so by using the
load_document()
function, which we developed initially. This is done by using the following code:
def load_document(name): file = open(name, 'r') text = file.read() file.close() return text # load sequences of cleaned text input_filename = 'junglebook_sequences.txt' doc = load_document(input_filename) lines = doc.split('\n')
The output of the preceding code is illustrated in the following screenshot:
- Note that the input filename is now
'junglebook_sequences.txt'
, which will load the saved training sequences into the memory. We need the text so that...