May 2019
Intermediate to advanced
272 pages
7h 19m
English
The code for sampling the generator trained on characters is similar to the code used to sample the generator trained on words. We first load the model, create a Z vector, get the Softmax output from the generator, and sample it by taking the mode of the distribution, that is, by sampling the index with the highest probability and converting it into a character using our token_to_id function:
import numpy as npfrom utils import load_model, sampledef inference(model_path, weights_path): G = load_model(model_path, weights_path) z = np.random.uniform(-1, 1, 1) res = G.inference(z) text = sample(res) print(text)
In the following table, we provide two examples of a few short sentences generated with the same fixed ...
Read now
Unlock full access