Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save santhalakshminarayana/7c11b48d1b07f8bdc90b4db2712cf63e to your computer and use it in GitHub Desktop.
Save santhalakshminarayana/7c11b48d1b07f8bdc90b4db2712cf63e to your computer and use it in GitHub Desktop.
Indian Name Generator - Name Generation - Medium
def generate(base_name):
if len(base_name):
base_name = base_name[:window]
x = np.zeros((1,window,len(int_to_char)))
seq_word = []
ind_list = [char_to_int[i] for i in base_name]
for i,ind in enumerate(ind_list):
x[0 ,i ,ind] = 1
seq_word.append(ind)
probs = np.squeeze(model.predict(x)).tolist()
probs = probs/ np.sum(probs)
gen_text = str(np.random.choice(a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', '.'],
size = 1, p = probs)[0])
not_end = True
text_length = 0
while text_length < 25 and not_end:
text_length += 1
seq_word = seq_word[1:]
seq_word.append(char_to_int[gen_text[-1]])
x = np.zeros((1,window,len(int_to_char)))
for i,ind in enumerate(seq_word):
x[0, i, ind] = 1
probs = np.squeeze(model.predict(x)).tolist()
probs = probs/ np.sum(probs)
gen_text = gen_text + int_to_char[np.random.choice(a=range(28),size=1,p=probs)[0]]
if gen_text[-1] == '.':
not_end = False
return(gen_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment