def train_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN(30, 30, len(word2idx)) rnn.fit(sentences, learning_rate=1e-4, show_fig=True, activation=T.nnet.relu, epochs=2000) rnn.save('RNN_D30_M30_epochs2000_relu.npz')
def train_poetry(): # students: tanh didn't work but you should try it sentences, word2idx = get_robert_frost() rnn = SimpleRNN(50, 50, len(word2idx)) rnn.fit(sentences, learning_rate=10e-5, show_fig=True, activation=T.nnet.relu, epochs=2000) rnn.save('RRNN_D50_M50_epochs2000_relu.npz')
def train_poetry(): sentences, word2idx = get_robert_frost() # embedding size = 50, and hidden neurons = 50 rnn = SimpleRNN(50, 50, len(word2idx)) rnn.fit(sentences, learning_rate=10e-5, show_fig=False, activation=T.nnet.relu, epochs=200) rnn.save('RRNN_D50_M50_epochs200_relu.npz')
def train_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN(50, 50, len(word2idx)) rnn.fit(sentences, leraning_rate=1e-4, show_fig=True, activation=T.nnet.relu, epochs=2000) rnn.save('./rnn_class/RRNN_D50_M50_epochs2000_relu.npz')
def train_poetry(epochs=200, learning_rate=10e-5, mu=0.9, show_fig=True): # students: tanh didn't work but you should try it sentences, word2idx = get_robert_frost() rnn = SimpleRNN(30, 30, len(word2idx)) rnn.fit(sentences, learning_rate=learning_rate, mu=mu, show_fig=show_fig, activation=T.nnet.relu, epochs=epochs) rnn.save('RNN_D30_M30_epochs{}_relu.npz'.format(epochs))
def generate_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load("RRNN_D30_M30_epochs1000_relu.npz", activation=T.nnet.relu) V = len(word2idx) pi = np.zeros(V) for sentence in sentences: pi[sentence[0]] += 1 pi/=pi.sum() rnn.generate(pi, word2idx)
def generate_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load('RNN_D30_M30_epochs2000_relu.npz', T.nnet.relu) V = len(word2idx) pi = np.zeros(V) for sentence in sentences: pi[sentence[0]] += 1 pi /= pi.sum() rnn.generate(pi, word2idx)
def generate_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load('RNN_D30_M30_epochs2000_relu.npz', T.nnet.relu) # determine initial state distribution for starting sentences V = len(word2idx) pi = np.zeros(V) for sentence in sentences: pi[sentence[0]] += 1 pi /= pi.sum() rnn.generate(pi, word2idx)
def train_poetry(): sentences, word2idx = get_robert_frost() D = 30 M = 50 epochs = 500 srn = SRN(D, M, len(word2idx)) srn.fit(sentences, learning_rate=10e-5, show_fig=True, activation=T.nnet.relu, epochs=epochs) srn.save('RNN_D%d_M%d_epochs%d_relu.npz' % (D, M, epochs))
def generate_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load('RNN_D30_M30_epochs200_relu.npz', T.nnet.relu) # Create the initial word distribution. V = len(word2idx) pi = np.zeros(V) # creates a vector of length V. for sentence in sentences: pi[sentence[0]] += 1 pi /= pi.sum() rnn.generate(pi, word2idx)
def generate_poetry(session, savefile): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load(savefile, tf.nn.relu, session) # determine initial state distribution for starting sentences V = len(word2idx) pi = np.zeros(V) for sentence in sentences: pi[sentence[0]] += 1 pi /= pi.sum() rnn.generate(pi, word2idx)
def generate_poetry(): sentences, word2idx = get_robert_frost() srn = SRN.load('RNN_D30_M30_epochs300_relu.npz', T.nnet.relu) V = len(word2idx) pi = np.zeros(V) for sentence in sentences: pi[sentence[0]] += 1 pi /= pi.sum() srn.generate(pi, word2idx)
def generate_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load('RNN_D30_M30_epochs200_relu.npz', T.nnet.relu) V = len(word2idx) pi = np.zeros(V) # create the word distribution for sentence in sentences: # get first word's frequency count pi[sentence[0]] += 1 pi /= pi.sum() rnn.generate(pi, word2idx)
def generate_potery(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load('RNN_D30_M30_epochs2000_relu_my.npz', T.nnet.relu) # sprawdzic czy dziala tez bez #rnn = SimpleRNN.load('RNN_D30_M30_epochs2000_relu_my', T.nnet.relu) V = len(word2idx) pi = np.zeros(V) for sentence in sentences: pi[sentence[0]] += 1 pi /= pi.sum() rnn.generate(pi, word2idx)
def generate_poetry_batches(epochs=500): """generate_poetry_batches""" sentences, word2idx = get_robert_frost() idx2word = {v:k for k, v in word2idx.items()} # total number of sentences n_sentences = len(sentences) # total number of words in corpus n_total = sum((len(sentence) + 1) for sentence in sentences) for i in range(epochs): for j in range(n_sentences): if np.random.random() < 0.1: print("generating an END to START") input_sequence = [0] + sentences[j] # [1] is the end token output_sequence = sentences[j] + [1] else: # input sequence is from the start to 2nd last word of X # so that the last word can be predicted input_sequence = [0] + sentences[j][:-1] output_sequence = sentences[j] input_seq_sentence = '' output_seq_sentence = '' for word_idx in input_sequence: input_seq_sentence += idx2word[word_idx] + " " for word_idx in output_sequence: output_seq_sentence += idx2word[word_idx] + " " print("input_seq_sentence: ", input_seq_sentence) print("output_seq_sentence: ", output_seq_sentence) print("n_total: ", n_total) # has to be calculated manually n_total += len(output_sequence) keypressed = input('Press q to quit: ') if keypressed == 'q': break keypressed = input('Press q to quit: ') if keypressed == 'q': break
def train_poetry(session, dims, savefile): sentences, word2idx = get_robert_frost() rnn = SimpleRNN(dims, dims, len(word2idx), tf.nn.relu, session) rnn.fit(sentences, epochs=17, show_fig=True) rnn.save(savefile)
def generate_potery(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load( 'RRNN_D50_M50_epochs2000_relu_my.npz') # sprawdzic czy dziala tez bez #rnn = SimpleRNN.load('RNN_D30_M30_epochs2000_relu_my', T.nnet.relu) rnn.generate(word2idx)
def train_poetry(): # students: tanh didn't work but you should try it sentences, word2idx = get_robert_frost() rnn = SimpleRNN(50, 50, len(word2idx))
def train_poetry(): # students: tanh didn't work but you should try it sentences, word2idx = get_robert_frost() rnn = SimpleRNN(30, 30, len(word2idx)) rnn.fit(sentences, learning_rate=10e-5, show_fig=True, activation=T.nnet.relu, epochs=2000) rnn.save('RNN_D30_M30_epochs2000_relu.npz')
def generate_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load('RRNN_D50_M50_epochs2000_relu.npz', T.nnet.relu) rnn.generate(word2idx)
def generate_poetry(): sentences, word2idx = get_robert_frost() rnn = SimpleRNN.load("RNN_D30_M30_epochs400_relu.npz", activation=T.nnet.relu) rnn.generate(word2idx)
def generate_poetry(): sentences, word2idx = get_robert_frost() rrnn = RRNN.load('RRNN_D30_M30_epochs500_relu.npz', T.nnet.relu) rrnn.generate(word2idx)