def generate_model(): text = read_text("../data/shakespeare") vocab = read_corpus(text) char_idx = {u: i for i, u in enumerate(vocab)} idx2char = np.array(vocab) dataset = start_model(char_idx, text) # build model model = build_model(vocab_size=len(vocab), embedding_dim=300, rnn_units=1024, batch_size=128) model.compile(optimizer='adam', loss=loss) epochs = 1 checkpoint_prefix = os.path.join("./train", "ckpt_{epoch}") # callback function called at the end of epoch training checkpoint_callback = tf.keras.callbacks.ModelCheckpoint( filepath=checkpoint_prefix, save_weights_only=True) new_model = build_model(vocab_size=len(vocab), embedding_dim=300, rnn_units=1024, batch_size=1) return new_model, char_idx, idx2char
def test_start_model(self): text = read_text("../data/shakespeare/") vocab = read_corpus(text) char_idx = {u: i for i, u in enumerate(vocab)} test = start_model(char_idx, text) self.assertNotEqual(test, None)
def setUpClass(cls): cls.grail = read_text('data/grail.txt') cls.emma = read_text('data/emma.txt') cls.wsj = read_text('data/wsj')
def setUpClass(cls): cls.text = read_text('data/grail.txt') cls.vocab = Vocabulary(cls.text)
def test_read_corpus(self): text = read_text("../data/shakespeare/") vocab = read_corpus(text) self.assertNotEqual(vocab, "")
def test_read_text(self): text = read_text("../data/shakespeare/") self.assertNotEqual(text, "") self.assertRegex(text, "[A-Za-z]*")