default='1', choices=xrange(1, 21), help='the task ID to train/test on from bAbI dataset (1-20)') parser.add_argument('--rlayer_type', default='gru', choices=['gru', 'lstm'], help='type of recurrent layer to use (gru or lstm)') parser.add_argument('--model_weights', help='pickle file of trained weights') args = parser.parse_args(gen_be=False) # setup backend be = gen_backend(**extract_valid_args(args, gen_backend)) be.bsz = 1 # load the bAbI dataset babi = babi_handler(args.data_dir, args.task) valid_set = QA(*babi.test) # create model model_inference = create_model(babi.vocab_size, args.rlayer_type) model_inference.load_params(args.model_weights) model_inference.initialize(dataset=valid_set) ex_story, ex_question, ex_answer = babi.test_parsed[0] stitch_sentence = lambda words: \ " ".join(words).replace(" ?", "?").replace(" .", ".\n").replace("\n ", "\n") print "\nThe vocabulary set from this task has {} words:".format( babi.vocab_size) print stitch_sentence(babi.vocab) print "\nExample from test set:" print "\nStory"
# parse the command line arguments parser = NeonArgparser(__doc__) parser.add_argument('-t', '--task', type=int, default='1', choices=xrange(1, 21), help='the task ID to train/test on from bAbI dataset (1-20)') parser.add_argument('--rlayer_type', default='gru', choices=['gru', 'lstm'], help='type of recurrent layer to use (gru or lstm)') parser.add_argument('--model_weights', help='pickle file of trained weights') args = parser.parse_args(gen_be=False) # setup backend be = gen_backend(**extract_valid_args(args, gen_backend)) be.bsz = 1 # load the bAbI dataset babi = babi_handler(args.data_dir, args.task) valid_set = QA(*babi.test) # create model model_inference = create_model(babi.vocab_size, args.rlayer_type) model_inference.load_params(args.model_weights) model_inference.initialize(dataset=valid_set) ex_story, ex_question, ex_answer = babi.test_parsed[0] stitch_sentence = lambda words: \ " ".join(words).replace(" ?", "?").replace(" .", ".\n").replace("\n ", "\n") print "\nThe vocabulary set from this task has {} words:".format(babi.vocab_size) print stitch_sentence(babi.vocab) print "\nExample from test set:" print "\nStory" print stitch_sentence(ex_story)