Created
September 4, 2020 14:43
-
-
Save pranjalAI/8ead3558e9c65db7d5a81da6e62c3b51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for _ in range(10): | |
try: | |
states_values = enc_model.predict( str_to_tokens( input( 'Enter question : ' ) ) ) | |
empty_target_seq = np.zeros( ( 1 , 1 ) ) | |
empty_target_seq[0, 0] = tokenizer.word_index['start'] | |
stop_condition = False | |
decoded_translation = '' | |
while not stop_condition : | |
dec_outputs , h , c = dec_model.predict([ empty_target_seq ] + states_values ) | |
sampled_word_index = np.argmax( dec_outputs[0, -1, :] ) | |
sampled_word = None | |
for word , index in tokenizer.word_index.items() : | |
if sampled_word_index == index : | |
decoded_translation += ' {}'.format( word ) | |
sampled_word = word | |
if sampled_word == 'end' or len(decoded_translation.split()) > maxlen_answers: | |
stop_condition = True | |
empty_target_seq = np.zeros( ( 1 , 1 ) ) | |
empty_target_seq[ 0 , 0 ] = sampled_word_index | |
states_values = [ h , c ] | |
print( " ".join(decoded_translation.strip().split(" ")[:-1]) ) | |
except: | |
print("Sorry, I don't understand. Please try again.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment