def load_custom_rnn():
  root.update()
  filename = filedialog.askopenfilename(initialdir = os.getcwd(), title ='Select file', filetypes=[('Numpy Files', '*.npz')])
  if filename != "":
    try:
      model = RNN(dictionary_size)
      log_message = model.load_model_parameters(filename)
      generate_sonnet1_button['state'] = 'normal'
      generate_sonnet2_button['state'] = 'normal'
      bigram_flag = False
      write_to_log(log_message, logger_index)
      current_model.set("Current Model: Custom RNN")
    except(FileNotFoundError):
      write_to_log("No such file or directory: %s" %filename, logger_index)
      return
Esempio n. 2
0
def load_custom_rnn():
  root.update()
  filename = filedialog.askopenfilename(initialdir = os.getcwd(), title ='Select file', filetypes=[('Numpy Files', '*.npz')])
  if filename != "":
    try:
      model = RNN(dictionary_size)
      log_message = model.load_model_parameters(filename)
      generate_sonnet1_button['state'] = 'normal'
      generate_sonnet2_button['state'] = 'normal'
      bigram_flag = False
      write_to_log(log_message, logger_index)
      current_model.set("Current Model: Custom RNN")
    except(IOError):
      write_to_log("No such file or directory: %s" %filename, logger_index)
      return
def load_rnn():
    iterations = number_iterations.get()
    if iterations == 20:
        filename = "RNNModel20.npz"
    elif iterations == 40:
        filename = "RNNModel40.npz"
    elif iterations == 60:
        filename = "RNNModel60.npz"
    elif iterations == 80:
        filename = "RNNModel80.npz"
    else:
        filename = "RNNModel100.npz"
    model = RNN(dictionary_size)
    log_message = model.load_model_parameters("TrainedModels/" + filename)
    generate_sonnet1_button['state'] = 'normal'
    generate_sonnet2_button['state'] = 'normal'
    generate_sonnet1_image_button['state'] = 'normal'
    generate_sonnet2_image_button['state'] = 'normal'
    bigram_flag = False
    write_to_log(log_message + " iterations=%d" % iterations, logger_index)
    current_model.set("Current Model: RNN %d iterations" % iterations)
def load_rnn_bigram():
  iterations = number_iterations.get()
  if iterations == 20:
    filename = "RNNBigram20.npz"
  elif iterations == 40:
    filename = "RNNBigram40.npz"
  elif iterations == 60:
    filename = "RNNBigram60.npz"
  elif iterations == 80:
    filename = "RNNBigram80.npz"
  else:
    filename = "RNNBigram100.npz"
  model = RNN(cantor_dictionary_size)
  log_message = model.load_model_parameters("TrainedModels/" + filename)
  generate_sonnet1_button['state'] = 'normal'
  generate_sonnet2_button['state'] = 'normal'
  generate_sonnet1_image_button['state'] = 'normal'
  generate_sonnet2_image_button['state'] = 'normal'
  bigram_flag = True
  write_to_log(log_message + " iterations=%d" %iterations, logger_index)
  current_model.set("Current Model: RNN (Bigram) %d iterations" %iterations)
Esempio n. 5
0
# Load the dictionary
rhyming_model, syllable_count, syllable_pronounciation, rhyming_dictionary = generate_rhyming_dictionary(
    training_data)
dictionary, dictionary_size, word_to_index, start_train, end_train, cantor_dictionary, cantor_dictionary_size, cantor_to_index, start_bigram_train, end_bigram_train, starting_bigrams = load_data(
    training_data, syllable_count)

# For graph plotting
loss_array = []
num_examples_array = []

# Train the model
# RNN
if args.mode == "RNN":
    print("Generating RNN Model...")
    model = RNN(dictionary_size)
    print("Training RNN Model with %d iterations..." % number_of_iterations)
    losses = model.train_with_sgd(start_train,
                                  end_train,
                                  nepoch=number_of_iterations)
    for (num_examples, loss) in losses:
        num_examples_array.append(num_examples)
        loss_array.append(loss)
    plt.plot(num_examples_array, loss_array)
    plt.title('Losses of Trained RNN Model %d iterations' %
              number_of_iterations)
    plt.xlabel('number of examples seen')
    plt.ylabel('losses')
    plt.grid(True)
    plt.show()
    model.save_model_parameters(save_to_file)
if not args.mode or not args.iteration:
    parser.error("Must provide mode and number of iterations")
    sys.exit(0)

number_of_iterations = int(args.iteration)

rhyming_model, syllable_count, syllable_pronounciation, rhyming_dictionary = generate_rhyming_dictionary(
    training_data)
dictionary, dictionary_size, word_to_index, start_train, end_train, cantor_dictionary, cantor_dictionary_size, cantor_to_index, start_bigram_train, end_bigram_train, starting_bigrams = load_data(
    training_data, syllable_count)

# Generate the neural network mode
# RNN
if args.mode == "RNN":
    print("Generating RNN Model...")
    model = RNN(dictionary_size)
    if number_of_iterations == 20:
        model.load_model_parameters('TrainedModels/RNNModel20.npz')
    elif number_of_iterations == 40:
        model.load_model_parameters('TrainedModels/RNNModel40.npz')
    elif number_of_iterations == 60:
        model.load_model_parameters('TrainedModels/RNNModel60.npz')
    elif number_of_iterations == 80:
        model.load_model_parameters('TrainedModels/RNNModel80.npz')
    else:
        model.load_model_parameters('TrainedModels/RNNModel100.npz')
# GRU
elif args.mode == "GRU":
    print("Generating GRU Model...")
    model = GRU(dictionary_size)
    if number_of_iterations == 20:
# Index for log message
global logger_index
logger_index = 0.0
# Check if generate using bigram or not
bigram_flag = False
# Base width and height of the image
base_width = 440
base_height = 440

# Load rhyming dictionary
rhyming_model, syllable_count, syllable_pronounciation, rhyming_dictionary = generate_rhyming_dictionary(
    training_data)
dictionary, dictionary_size, word_to_index, start_train, end_train, cantor_dictionary, cantor_dictionary_size, cantor_to_index, start_bigram_train, end_bigram_train, starting_bigrams = load_data(
    training_data, syllable_count)
model = RNN(dictionary_size)


# Load the premade RNN model based on the number of iterations
def load_rnn():
    iterations = number_iterations.get()
    if iterations == 20:
        filename = "RNNModel20.npz"
    elif iterations == 40:
        filename = "RNNModel40.npz"
    elif iterations == 60:
        filename = "RNNModel60.npz"
    elif iterations == 80:
        filename = "RNNModel80.npz"
    else:
        filename = "RNNModel100.npz"
# Must at least provide mode and iteration
if not args.mode or not args.iteration:
  parser.error("Must provide mode and number of iterations")
  sys.exit(0)

number_of_iterations = int(args.iteration)

rhyming_model, syllable_count, syllable_pronounciation, rhyming_dictionary = generate_rhyming_dictionary(training_data)
dictionary, dictionary_size, word_to_index, start_train, end_train, cantor_dictionary, cantor_dictionary_size, cantor_to_index, start_bigram_train, end_bigram_train, starting_bigrams = load_data(training_data, syllable_count)

# Generate the neural network mode
# RNN
if args.mode == "RNN":
  print("Generating RNN Model...")
  model = RNN(dictionary_size)
  if number_of_iterations == 20:
    model.load_model_parameters('TrainedModels/RNNModel20.npz')
  elif number_of_iterations == 40:
    model.load_model_parameters('TrainedModels/RNNModel40.npz')
  elif number_of_iterations == 60:
    model.load_model_parameters('TrainedModels/RNNModel60.npz')
  elif number_of_iterations == 80:
    model.load_model_parameters('TrainedModels/RNNModel80.npz')
  else:
    model.load_model_parameters('TrainedModels/RNNModel100.npz')
# GRU
elif args.mode == "GRU":
  print("Generating GRU Model...")
  model = GRU(dictionary_size)
  if number_of_iterations == 20: