def main(): parser = argparse.ArgumentParser() parser.add_argument('--infile', type=str, default='../../dataset/T=2_train.json') parser.add_argument('--outfile', type=str, default="../models/sketchadapt/model.ckpt") parser.add_argument('--epochs', type=int, default=5) parser.add_argument('--val_split', type=float) parser.add_argument('-E', type=int, default=20, help='embedding dimension') parser.add_argument('--nb_inputs', type=int, default=3) args = parser.parse_args() problems = json.loads(open(args.infile).read()) max_token_length = util.get_max_token_len(args.infile) rows_type, rows_val, y = get_XY(problems, args.nb_inputs, max_token_length) model = Sketchadapt(args.nb_inputs, args.E, max_token_length / 5, batch_size=64, lr=5e-4) model.fit(rows_type, rows_val, y, epochs=args.epochs, validation_split=args.val_split) print('saving model to ', args.outfile) model.save(args.outfile)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--infile', type=str, default='../../dataset/T=2_train.json') parser.add_argument('--outfile', type=str, default="../models/rubustfill/model.ckpt") parser.add_argument('--epochs', type=int, default=30) parser.add_argument('--val_split', type=float) parser.add_argument('-E', type=int, default=8, help='embedding dimension') parser.add_argument('--nb_inputs', type=int, default=3) args = parser.parse_args() problems = json.loads(open(args.infile).read()) max_token_length = util.get_max_token_len(args.infile) rows_type, rows_val, y = get_XY(problems, args.nb_inputs, max_token_length) model = Rubustfill(args.nb_inputs, args.E, max_token_length, batch_size=64, K=128, attention=None, lr=5e-4) for i in range(args.epochs // 10): model.fit(rows_type, rows_val, y, epochs=10, validation_split=args.val_split) print('saving model to ', args.outfile) model.save(args.outfile)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--problemfile', type=str, default='../../dataset/T=2_test.json') parser.add_argument('--predictor', type=str, default='True') parser.add_argument('--outfile', type=str) parser.add_argument('--T', type=int, default=2) parser.add_argument('--mode', type=str, choices=['dfs', 'sort-and-add'], default='dfs') parser.add_argument('--gas', type=int, default=1500) parser.add_argument('-E', type=int, default=20, help='embedding dimension') parser.add_argument('--nb_inputs', type=int, default=3) args = parser.parse_args() problems = json.loads(open(args.problemfile).read()) # annotate problems with predictions max_token_length = util.get_max_token_len(args.problemfile) predictor = sketchadapt.Sketchadapt(args.nb_inputs, args.E, max_token_length/5) predictor.load() rows_type, rows_val, y = sketchadapt.get_XY(problems, args.nb_inputs, max_token_length) sketch_pred = predictor.predict_sketch(rows_type, rows_val) nb_beam = int(args.gas**0.4) nb_beam = 50 fs = search.beam_search_sketcher(sketch_pred, int(max_token_length/5), nb_beam) # [batch, nb_beam, T] print(np.array(fs).shape) arg_pred_list = [] # [nb_beam, batch, 27] for i in range(nb_beam): arg_pred_list.append(predictor.predict_args(rows_type, rows_val, np.array(fs)[:, i, :])) # print(np.array(fs).shape) print(np.array(arg_pred_list).shape) print(np.stack(arg_pred_list, axis=1).shape) predictions = list(zip(fs[i], np.stack(arg_pred_list, axis=1)[i]) for i in range(len(fs))) for problem, pred in zip(problems, predictions): problem['prediction'] = pred rows = solve_problems(problems, args.T, args.mode, args.gas, nb_beam) df = pd.DataFrame(rows) nb_solved = len(df) - sum(df.solution.isnull()) print('summary:') print('solved {}/{} ({}%)'.format(nb_solved, len(df), nb_solved * 100. / len(df))) print(df.describe()) if args.outfile: print('saving results to', args.outfile) df.to_hdf(args.outfile, 'data')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--problemfile', type=str, default='../../dataset/T=2_test.json') parser.add_argument('--predictor', type=str, default='True') parser.add_argument('--outfile', type=str) parser.add_argument('--T', type=int, default=2) parser.add_argument('--mode', type=str, choices=['dfs', 'sort-and-add', 'beam'], default='beam') parser.add_argument('--gas', type=int, default=500) parser.add_argument('-E', type=int, default=8, help='embedding dimension') parser.add_argument('--nb_inputs', type=int, default=3) args = parser.parse_args() problems = json.loads(open(args.problemfile).read()) if args.predictor: # annotate problems with predictions predictor = deepcoder_tf.Deepcoder(args.nb_inputs, args.E, K=128) predictor.load() rows_type, rows_val, y = deepcoder_tf.get_XY(problems, args.nb_inputs) predictions = predictor.predict(rows_type, rows_val) if args.mode == 'beam': max_token_length = util.get_max_token_len(args.problemfile) for problem, pred in zip(problems, predictions): # problem['prediction'] = np.array([np.concatenate([pred * 17/21, np.ones([8, ],dtype=np.float32) * 4.0 / 21], axis=-1) for _ in range(max_token_length)]) # print(problem['prediction']) rand = np.random.rand(10, 42) problem['prediction'] = np.array( [rand[_] / np.sum(rand[_]) for _ in range(10)]) else: for problem, pred in zip(problems, predictions): problem['prediction'] = pred rows = solve_problems(problems, args.T, args.mode, args.gas) df = pd.DataFrame(rows) nb_solved = len(df) - sum(df.solution.isnull()) print('summary:') print('solved {}/{} ({}%)'.format(nb_solved, len(df), nb_solved * 100. / len(df))) print(df.describe()) if args.outfile: print('saving results to', args.outfile) df.to_hdf(args.outfile, 'data')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--problemfile', type=str, default='../../dataset/T=2_test.json') parser.add_argument('--predictor', type=str, default='True') parser.add_argument('--outfile', type=str) parser.add_argument('--T', type=int, default=2) parser.add_argument('--mode', type=str, choices=['dfs', 'sort-and-add', 'beam'], default='beam') parser.add_argument('--gas', type=int, default=500) parser.add_argument('-E', type=int, default=62, help='embedding dimension') parser.add_argument('--nb_inputs', type=int, default=3) args = parser.parse_args() problems = json.loads(open(args.problemfile).read()) if args.predictor: # annotate problems with predictions max_token_length = util.get_max_token_len(args.problemfile) predictor = transformer_rf.Transfill(args.nb_inputs, args.E, max_token_length, K=64) predictor.load() rows_type, rows_val, y = transformer_rf.get_XY(problems, args.nb_inputs, max_token_length) predictions = predictor.predict( rows_type, rows_val, np.ones_like(y) * (len(impl.ACT_SPACE) - 1)) for problem, pred in zip(problems, predictions): problem['prediction'] = pred # print(pred) rows = solve_problems(problems, args.T, args.mode, args.gas) df = pd.DataFrame(rows) nb_solved = len(df) - sum(df.solution.isnull()) print('summary:') print('solved {}/{} ({}%)'.format(nb_solved, len(df), nb_solved * 100. / len(df))) print(df.describe()) if args.outfile: print('saving results to', args.outfile) df.to_hdf(args.outfile, 'data')