tasks/vowels/interact.py
def main():
    """
    Runs an interactive shell where the user can submit input with their chosen deliminator and see the output of the
    DNC's latest checkpoint. 
    :return: None
    """
    dir_path = os.path.dirname(os.path.realpath(__file__))
    ckpts_dir = os.path.join(dir_path, 'checkpoints')
    lexicon_dictionary = load(os.path.join(dir_path, 'data', 'encoded', 'lexicon-dict.pkl'))
    target_code = lexicon_dictionary["#"]

    graph = tf.Graph()
    with graph.as_default():
        with tf.compat.v1.Session(graph=graph) as session:

            ncomputer = DNC(
                RecurrentController,
                input_size=len(lexicon_dictionary),
                output_size=len(lexicon_dictionary),
                max_sequence_length=100,
                memory_words_num=256,
                memory_word_size=64,
                memory_read_heads=4,
            )

            ncomputer.restore(session, ckpts_dir, 'step-100001')

            outputs, _ = ncomputer.get_outputs()
            softmaxed = tf.nn.softmax(outputs)

            print("This is an interactive shell script. Here a user may test a trained neural network by passing it "
                  "custom inputs and seeing if they elicid the desired output. \n Please note that a user may only "
                  "test inputs that consists of words in the neural network's lexicon. If the user would like to quit"
                  " the program, they can type ':q!' when prompted for an input. \n If the user would like to see the"
                  " network's lexicon, they can type ':dict' when prompted for an input. Otherwise, the user may "
                  "simply type the sequence of inputs that they would like to use and then hit the enter key. \n "
                  "They will then be asked to specify the deliminator that distinguishes one word from another word."
                  " The input will then be split using that deliminator. \n If all resulting inputs are in the "
                  "network's lexicon, the network will then be fed these inputs and its output will be printed for "
                  "the user along with its expected output.")

            my_input = input("Input:")
            while my_input != ":q!":
                if my_input == ":dict":
                    print("The neural network has been trained to recognize the following words:")
                    print(lexicon_dictionary)
                    my_input = input("Input:")
                    continue
                deliminator = input("Deliminator:")
                story = my_input.split(deliminator)
                if not set(story).issubset(lexicon_dictionary):
                    print("You may only test key in the lexicon dictionary.")
                    my_input = input("Input:")
                    continue

                desired_answers = get_solution(story)
                encoded_story = []
                encoded_answers = []
                for an_input in story:
                    encoded_story.append(lexicon_dictionary[an_input])
                for an_output in desired_answers:
                    encoded_answers.append(lexicon_dictionary[an_output])
                input_vec, _, seq_len, _ = prepare_sample([encoded_story], encoded_answers, target_code, 
                                                          len(lexicon_dictionary))
                softmax_output = session.run(softmaxed, feed_dict={
                    ncomputer.input_data: input_vec,
                    ncomputer.sequence_length: seq_len
                })

                softmax_output = np.squeeze(softmax_output, axis=0)
                given_answers = np.argmax(softmax_output[:len(desired_answers)], axis=1)

                print("Output: ", [list(lexicon_dictionary.keys())[list(lexicon_dictionary.values()).index(an_answer)] 
                                   for an_answer in given_answers])
                is_correct = True
                if len(given_answers) != len(encoded_answers):
                    is_correct = False
                else:
                    for i in range(len(given_answers)):
                        if given_answers[i] != encoded_answers[i]:
                            is_correct = False
                if is_correct:
                    print("Correct!")
                else:
                    print("Expected: ", desired_answers)

                my_input = input("Input:")

    Runs an interactive shell where the user can submit input with their chosen deliminator and see the output of the
    DNC's latest checkpoint. 
    :return: None
    
Runs an interactive shell where the user can submit input with their chosen deliminator and see the output of the
DNC's latest checkpoint.
Runs an interactive shell where the user can submit input with their chosen deliminator and see the output of the DNC ' s latest checkpoint .
def main():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    ckpts_dir = os.path.join(dir_path, 'checkpoints')
    lexicon_dictionary = load(os.path.join(dir_path, 'data', 'encoded', 'lexicon-dict.pkl'))
    target_code = lexicon_dictionary["#"]
    graph = tf.Graph()
    with graph.as_default():
        with tf.compat.v1.Session(graph=graph) as session:
            ncomputer = DNC(
                RecurrentController,
                input_size=len(lexicon_dictionary),
                output_size=len(lexicon_dictionary),
                max_sequence_length=100,
                memory_words_num=256,
                memory_word_size=64,
                memory_read_heads=4,
            )
            ncomputer.restore(session, ckpts_dir, 'step-100001')
            outputs, _ = ncomputer.get_outputs()
            softmaxed = tf.nn.softmax(outputs)
            print("This is an interactive shell script. Here a user may test a trained neural network by passing it "
                  "custom inputs and seeing if they elicid the desired output. \n Please note that a user may only "
                  "test inputs that consists of words in the neural network's lexicon. If the user would like to quit"
                  " the program, they can type ':q!' when prompted for an input. \n If the user would like to see the"
                  " network's lexicon, they can type ':dict' when prompted for an input. Otherwise, the user may "
                  "simply type the sequence of inputs that they would like to use and then hit the enter key. \n "
                  "They will then be asked to specify the deliminator that distinguishes one word from another word."
                  " The input will then be split using that deliminator. \n If all resulting inputs are in the "
                  "network's lexicon, the network will then be fed these inputs and its output will be printed for "
                  "the user along with its expected output.")
            my_input = input("Input:")
            while my_input != ":q!":
                if my_input == ":dict":
                    print("The neural network has been trained to recognize the following words:")
                    print(lexicon_dictionary)
                    my_input = input("Input:")
                    continue
                deliminator = input("Deliminator:")
                story = my_input.split(deliminator)
                if not set(story).issubset(lexicon_dictionary):
                    print("You may only test key in the lexicon dictionary.")
                    my_input = input("Input:")
                    continue
                desired_answers = get_solution(story)
                encoded_story = []
                encoded_answers = []
                for an_input in story:
                    encoded_story.append(lexicon_dictionary[an_input])
                for an_output in desired_answers:
                    encoded_answers.append(lexicon_dictionary[an_output])
                input_vec, _, seq_len, _ = prepare_sample([encoded_story], encoded_answers, target_code, 
                                                          len(lexicon_dictionary))
                softmax_output = session.run(softmaxed, feed_dict={
                    ncomputer.input_data: input_vec,
                    ncomputer.sequence_length: seq_len
                })
                softmax_output = np.squeeze(softmax_output, axis=0)
                given_answers = np.argmax(softmax_output[:len(desired_answers)], axis=1)
                print("Output: ", [list(lexicon_dictionary.keys())[list(lexicon_dictionary.values()).index(an_answer)] 
                                   for an_answer in given_answers])
                is_correct = True
                if len(given_answers) != len(encoded_answers):
                    is_correct = False
                else:
                    for i in range(len(given_answers)):
                        if given_answers[i] != encoded_answers[i]:
                            is_correct = False
                if is_correct:
                    print("Correct!")
                else:
                    print("Expected: ", desired_answers)
                my_input = input("Input:")
def main ( ) : dir_path = os . path . dirname ( os . path . realpath ( __file__ ) ) ckpts_dir = os . path . join ( dir_path , 'checkpoints' ) lexicon_dictionary = load ( os . path . join ( dir_path , 'data' , 'encoded' , 'lexicon-dict.pkl' ) ) target_code = lexicon_dictionary [ "#" ] graph = tf . Graph ( ) with graph . as_default ( ) : with tf . compat . v1 . Session ( graph = graph ) as session : ncomputer = DNC ( RecurrentController , input_size = len ( lexicon_dictionary ) , output_size = len ( lexicon_dictionary ) , max_sequence_length = 100 , memory_words_num = 256 , memory_word_size = 64 , memory_read_heads = 4 , ) ncomputer . restore ( session , ckpts_dir , 'step-100001' ) outputs , _ = ncomputer . get_outputs ( ) softmaxed = tf . nn . softmax ( outputs ) print ( "This is an interactive shell script. Here a user may test a trained neural network by passing it " "custom inputs and seeing if they elicid the desired output. \n Please note that a user may only " "test inputs that consists of words in the neural network's lexicon. If the user would like to quit" " the program, they can type ':q!' when prompted for an input. \n If the user would like to see the" " network's lexicon, they can type ':dict' when prompted for an input. Otherwise, the user may " "simply type the sequence of inputs that they would like to use and then hit the enter key. \n " "They will then be asked to specify the deliminator that distinguishes one word from another word." " The input will then be split using that deliminator. \n If all resulting inputs are in the " "network's lexicon, the network will then be fed these inputs and its output will be printed for " "the user along with its expected output." ) my_input = input ( "Input:" ) while my_input != ":q!" : if my_input == ":dict" : print ( "The neural network has been trained to recognize the following words:" ) print ( lexicon_dictionary ) my_input = input ( "Input:" ) continue deliminator = input ( "Deliminator:" ) story = my_input . split ( deliminator ) if not set ( story ) . issubset ( lexicon_dictionary ) : print ( "You may only test key in the lexicon dictionary." ) my_input = input ( "Input:" ) continue desired_answers = get_solution ( story ) encoded_story = [ ] encoded_answers = [ ] for an_input in story : encoded_story . append ( lexicon_dictionary [ an_input ] ) for an_output in desired_answers : encoded_answers . append ( lexicon_dictionary [ an_output ] ) input_vec , _ , seq_len , _ = prepare_sample ( [ encoded_story ] , encoded_answers , target_code , len ( lexicon_dictionary ) ) softmax_output = session . run ( softmaxed , feed_dict = { ncomputer . input_data : input_vec , ncomputer . sequence_length : seq_len } ) softmax_output = np . squeeze ( softmax_output , axis = 0 ) given_answers = np . argmax ( softmax_output [ : len ( desired_answers ) ] , axis = 1 ) print ( "Output: " , [ list ( lexicon_dictionary . keys ( ) ) [ list ( lexicon_dictionary . values ( ) ) . index ( an_answer ) ] for an_answer in given_answers ] ) is_correct = True if len ( given_answers ) != len ( encoded_answers ) : is_correct = False else : for i in range ( len ( given_answers ) ) : if given_answers [ i ] != encoded_answers [ i ] : is_correct = False if is_correct : print ( "Correct!" ) else : print ( "Expected: " , desired_answers ) my_input = input ( "Input:" )
Runs an interactive shell where the user can submit input with their chosen deliminator and see the output of the
DNC's latest checkpoint.
Runs an interactive shell where the user can submit input with their chosen deliminator and see the output of the DNC ' s latest checkpoint .
"""
    Runs an interactive shell where the user can submit input with their chosen deliminator and see the output of the
    DNC's latest checkpoint. 
    :return: None
    """
None