repr(idx2char[target_idx]))) # Buffer size to shuffle the dataset # (TF data is designed to work with possibly infinite sequences, # so it doesn't attempt to shuffle the entire sequence in memory. Instead, # it maintains a buffer in which it shuffles elements). BUFFER_SIZE = 10000 dataset = dataset.shuffle(BUFFER_SIZE).batch(BATCH_SIZE, drop_remainder=True) model = Model(len(char2idx), EMBEDDING_DIM, UNITS) # Using adam optimizer with default arguments optimizer = tf.train.AdamOptimizer() model.build(tf.TensorShape([BATCH_SIZE, SEQ_LENGTH])) model.summary() # Training step EPOCHS = 30 # Directory where the checkpoints will be saved checkpoint_dir = os.getenv('TRAINING_CHECKPOINT_DIR', './data/training_checkpoints') # Name of the checkpoint files checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt") # Checkpoint instance checkpoint = tf.train.Checkpoint(optimizer=optimizer, model=model)
import time import os print("Starting up") with open(os.getenv('VOCAB_FILE', './data/vocab.txt'), 'r') as text_file: vocab = text_file.read().split("\n") (char2idx, idx2char) = vocab_to_char2idx_idx2char(vocab) model = Model(len(char2idx), EMBEDDING_DIM, UNITS) checkpoint_dir = os.getenv('TRAINING_CHECKPOINT_DIR', './data/training_checkpoints') model.load_weights(tf.train.latest_checkpoint(checkpoint_dir)) model.build(tf.TensorShape([1, None])) # Number of characters to generate num_generate = 1000 # You can change the start string to experiment start_string = 'Q' # Converting our start string to numbers (vectorizing) input_eval = [char2idx[s] for s in start_string] input_eval = tf.expand_dims(input_eval, 0) # Empty string to store our results text_generated = [] # Low temperatures results in more predictable text.