Commit 4b633f14 authored by Ilya Prokhorov's avatar Ilya Prokhorov

Generate with tries

parent 87bca7f9
from textgenrnn import textgenrnn
from os import path
import sys
from random import uniform
weights_filename = "textgenrnn_weights.hdf5"
vocab_filename = "textgenrnn_vocab.json"
......@@ -18,8 +19,9 @@ if len(sys.argv) == 2:
command_mode_state_array = command_mode_state.split(",")
if len(command_mode_state_array) != 2:
print("Incorrect silent mode, must be - mode,dataset_filename - for example: python main.py generate,dataset_quotes_ru.txt")
print("Incorrect silent mode, must be - mode,dataset_filename - for example: python main.py generate,10")
print("Modes: train_reset/train_resume/generate")
exit(4)
if command_mode == False:
state = input("train_reset/train_resume/generate? ")
......@@ -40,10 +42,21 @@ elif state == "train_resume":
textgen = textgenrnn(weights_path = weights_filename, vocab_path = vocab_filename, config_path = config_filename)
if command_mode == False and (state == "train_reset" or state == "train_resume"):
dataset_file = input("dataset filename? (%s) " % default_dataset_filename)
if len(dataset_file) < 1:
dataset_file = default_dataset_filename
if command_mode == False:
if state == "train_reset" or state == "train_resume":
dataset_file = input("dataset filename? (%s) " % default_dataset_filename)
if len(dataset_file) < 1:
dataset_file = default_dataset_filename
elif state == "generate":
tries = input("tries? (1) ")
if len(tries) > 0:
try:
tries = int(tries)
except:
print("Incorrect generate phrase tries number - must be integer number, for example - 10")
else:
tries = 1
elif command_mode == True:
dataset_file = command_mode_state_array[1]
......@@ -64,5 +77,13 @@ elif state == "generate":
print("There is no weights to generate, train first... Exit")
exit(3)
textgen = textgenrnn(weights_path = weights_filename, vocab_path = vocab_filename, config_path = config_filename)
textgen.generate()
\ No newline at end of file
if command_mode == True:
tries = command_mode_state_array[1]
try:
tries = int(tries)
except:
print("Incorrect generate phrase tries number - must be integer number, for example - generate,10")
for tryStep in range(0, tries):
textgen = textgenrnn(weights_path = weights_filename, vocab_path = vocab_filename, config_path = config_filename)
textgen.generate(temperature = uniform(0.8, 1.5))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment