-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathpredict_HS-B.py
More file actions
executable file
·721 lines (651 loc) · 22.6 KB
/
predict_HS-B.py
File metadata and controls
executable file
·721 lines (651 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
#-*-coding:utf-8-*-
import sys
from code_generate_model import *
from resolve_data import *
import os
import tensorflow as tf
import numpy as np
import os
import math
import queue as Q
from copy import deepcopy
from tqdm import tqdm
#os.envireni
os.environ["CUDA_VISIBLE_DEVICES"]="5"
vocabu = {}
tree_vocabu = {}
vocabu_func = {}
tree_vocabu_func = {}
vocabu_var = {}
tree_vocabu_var = {}
J_HasSon = []
J_VarList = []
J_readrulenum = -1
J_NeedsEnd = []
J_NlList = []
#classnum = 320
global_step = 0
embedding_size = 256
conv_layernum = 128
conv_layersize = 3
rnn_layernum = 50
batch_size = 64
NL_vocabu_size = len(vocabulary)
Tree_vocabu_size = len(tree_vocabulary)
NL_len = nl_len
Tree_len = tree_len
learning_rate = 1e-5
keep_prob = 0.5
pretrain_times = 0
pretrain_dis_times = 2
train_times = 1000
parent_len = 20
rulelist_len = 200
step_list_p = []
numberstack = []
list2wordlist = []
copy_node = []
cardnum = []
def J_readrule():
f = open(project + "Rule.txt", "r")
lines = f.readlines()
f.close()
for line in lines:
J_HasSon.append(line.strip().split()[0])
f = open(project + "copy_node.txt", "r")
lines = f.readlines()
f.close()
for line in lines:
J_HasSon.append(line.strip().split()[0])
f = open(project + "WithListEnd.txt", "r")
lines = f.readlines()
f.close()
for line in lines:
J_HasSon.append(line.strip().split()[0])
J_NeedsEnd.append(line.strip().split()[0])
J_readrule()
def J_readlist(in_file):
lines = in_file.readlines()
global J_readrulenum
J_readrulenum = int(lines[1])
return lines[0].replace(" node_gen ^", "").strip().split()
def J_findtheson_name(l, site):
ans = []
count = 0
nowsite = site
while (nowsite < len(l)):
if l[nowsite] == "^":
count -= 1
else:
if count == 1:
ans.append(l[nowsite])
count += 1
if count <= 0:
break
nowsite += 1
return ans
def J_isend(l, site):
if l[site] not in J_HasSon:
return True
if l[site] == "End" or l[site] == "^":
return True
sonlist = J_findtheson_name(l, site)
if len(sonlist) == 0:
return False
elif l[site] not in J_NeedsEnd:
return True
elif l[site] in J_NeedsEnd and sonlist[-1] == "End":
return True
return False
def J_findthecontrol(liststr, site):
ans = [site + 1]
count = 0
nowsite = site
while (nowsite < len(liststr)):
if liststr[nowsite] == "^":
count -= 1
else:
count += 1
if count <= 0:
ans.append(nowsite)
break
nowsite += 1
return ans
def J_AddOneSon(l, rule, site):
node = l[site]
if node != rule[0]:
assert False
se = J_findthecontrol(l, site)
e = se[1]
s = se[0]
newlist = deepcopy(l)
newlist.insert(e, "^")
step_list_p.insert(e, global_step)
newlist.insert(e, rule[1][0])
step_list_p.insert(e, global_step)
return newlist
def J_AddSon(l, rulenum, site):
if rulenum >= len(Rule): # for copy
newlist = deepcopy(l)
newlist.insert(site + 1, "^")
step_list_p.insert(site + 1, global_step)
copy_nl = J_NlList[rulenum - len(Rule)]
#if "_END" not in copy_nl:
# for i in range(len(copy_nl))[::-1]:
# if i == "_":
# copy_nl = copy_nl[:i]
# break
if copy_nl == "NAME_END":
#lz = []
#for node = J_NlList[0:rulenum - len(Rule)]:
#copy_nl = "_".join(J_NlList[0:rulenum - len(Rule)]).replace("_NAME", "").replace("_'", "'").replace("_!", "!")
if newlist[site] == "s":
copy_nl = "_".join(J_NlList[0:rulenum - len(Rule)]).replace("_NAME", "").replace("_'", "'").replace("_!", "!")
copy_nl = copy_nl.replace("_-", "-").replace("-_", "-").replace("'_", "'")
#copy_nl = copy_nl.replace("'", "").replace("_", "").replace("!", "")
else:
lz = []
import string
for node in J_NlList[0:rulenum - len(Rule)]:
if len(node) > 1:
lz.append(string.capwords(node))
else:
lz.append(node)
copy_nl = "_".join(lz[0:rulenum - len(Rule)]).replace("_NAME", "").replace("_'", "'").replace("_!", "!")
copy_nl = copy_nl.replace("'", "").replace("_", "").replace("!", "").replace("-", "")
if J_NlList[min(len(J_NlList) - 1, rulenum - len(Rule) + 1)] == "TYPE_END":
copy_nl += "Card"
copy_nl += "_fu_nc_na_me"
newlist.insert(site + 1, copy_nl)
step_list_p.insert(site + 1, global_step)
return newlist
newlist = deepcopy(l)
rule = Rule[rulenum]
for son in rule[1][::-1]:
newlist.insert(site + 1, "^")
step_list_p.insert(site + 1, global_step)
if rule[0] in copy_node:
son += "_fu_nc_na_me"
newlist.insert(site + 1, son)
step_list_p.insert(site + 1, global_step)
return newlist
def J_AddSon_nodegen(l, site):
newlist = deepcopy(l)
se = J_findthecontrol(l, site)
newlist.insert(se[1], "^")
#step_list_p.insert(se[1], global_step)
newlist.insert(se[1], "node_gen")
#step_list_p.insert(se[1], global_step)
return newlist
father_index_now = -1
def J_scan(l, rulenum):
for i in range(len(l)):
now = l[i]
if now == "^":
continue
if not J_isend(l, i):
global father_index_now
father_index_now = step_list_p[i]
if l[i] in J_NeedsEnd:
return J_AddOneSon(l, Rule[J_readrulenum], i)
return J_AddSon(l, J_readrulenum, i)
return None
def J_findthefather_site(l, site):
index = site - 1
count = 0
if index < 0:
return -1
while index >= 0:
#print ("fa", words[i])
if "^" in l[index]:
count -= 1
else:
count += 1
if count == 1:
# exit()
# print (words[index])
#return words[index]
return index
index -= 1
return -1
def J_scan_for_node(l, rulenum):
for i in range(len(l)):
now = l[i]
if now == "^":
continue
if not J_isend(l, i):
newl = J_AddSon_nodegen(l, i)
return newl, i#J_findthefather_site(newl, i + 1)
return None, -1
def J_getfeaturenode(l, nextsite):
i = nextsite
node_par = []
node_par.append(l[i])
par = J_findthefather_site(l, i)
pars = ""
if par == -1:
pars = "Unknown"
else:
pars = l[par]
node_par.append(pars)
l_f = []
par = i
while (par != -1):
l_f.append(l[par])
par = J_findthefather_site(l, par)
node_par.append(" ".join(l_f))
return node_par
def J_run():
global global_step
in_file = open(project + "Tree_Rule.in")
#in_file.close()
fw = open(project + "Tree_Feature.out", "w")
l = J_readlist(in_file)
in_file.close()
global_step += 1
newl = J_scan(l, J_readrulenum)
if newl == None:
fw.write(" ".join(l) + "\n")
fw.write("END\n")
else:
newl1, nextsite = J_scan_for_node(newl, J_readrulenum)
if newl1 == None:
fw.write(" ".join(newl) + "\n")
fw.write("END\n")
else:
newl = newl1
node_par = J_getfeaturenode(newl, nextsite)
out = " ".join(newl)
fw.write(out.replace(" node_gen ^", "") + "\n")
fw.write(node_par[0] + "\n")
fw.write(node_par[1] + "\n")
fw.write(node_par[2] + "\n")
fw.write(out.replace(" End ^", "") + "\n")
fw.write(out.replace(" End ^", "") + "\n")
fw.write("1\n")
fw.write("1\n")
fw.write(out.replace(" End ^", "") + "\n")
fw.write("1\n")
fw.write(str(father_index_now) + "\n")
fw.close()
def data_random():
limit = math.sqrt(6 / (classnum + 10 + embedding_size * 2))
vec = np.random.uniform(-limit, limit, size=[classnum + 10, embedding_size * 2])
for i in range(len(vec[0])):
vec[0, i] = 0
return vec
def create_model(session, g, placeholder=""):
if(os.path.exists(project + "save1")):
saver = tf.train.Saver()
saver.restore(session, tf.train.latest_checkpoint(project + "save1"))
print("load the model")
else:
classvec = data_random()
session.run(tf.global_variables_initializer(), feed_dict={d.variable:classvec})
print("create a new model")
def save_model(session, number):
saver = tf.train.Saver()
saver.save(session, "save" + str(number) + "/model.cpkt")
class Javaoutput:
def __init__(self, Tree, Nl, Node, PNode , Root, TreeWithEnd,FatherTree, GrandFatherTree, state):
self.Tree = Tree
self.Nl = Nl
self.Node = Node
self.PNode = PNode
self.Root = [Root]
self.Probility = 1
self.is_end = False
self.state = state
self.FuncDict = {}
self.FuncList = []
self.VarList = []
self.father_index = []
self.rule = []
self.RuleList = []
self.DeepthList = []
self.FatherTree = FatherTree
self.TreeWithEnd = TreeWithEnd
self.GrandFatherTree = GrandFatherTree
self.list2wordlistjava = []
self.numberstack = []
self.step_list = [-1] * 30
self.gs = -1
def prin(self):
print(self.Tree)
def __lt__(self, other):
return self.Probility > other.Probility
def getJavaOut(Nl):
f = open(project + "Tree_Feature.out", "r")
lines = f.readlines()
f.close()
# print(lines)
if len(lines) == 2:
return Javaoutput(lines[0][:-1], Nl, "", "", "", "", "", "", "end")
if len(lines) == 12:
return Javaoutput(lines[4][:-1], Nl, lines[1][:-1], lines[2][:-1], lines[3][:-1], lines[0][:-1],lines[6][:-1], lines[7][:-1], "end")
if len(lines) == 1:
return Javaoutput("", Nl, "", "", "", "", "", "", "error")
return Javaoutput(lines[4][:-1], Nl, lines[1][:-1], lines[2][:-1], lines[3][:-1], lines[0][:-1],lines[6][:-1], lines[7][:-1], "grow")
def getlistDeep_all(inputlist):
ne = []
count = 0
for p in inputlist:
if p == "^":
count -= 1
ne.append(count)
else:
ne.append(count)
count += 1
return ne
def cov(tree):
ans = " "
li = tree.split()
#for s in str:
deeplist = getlistDeep_all(li)
mp = {}
for i in range(len(li)):
if li[i] == "^":
now = deeplist[i]
li[i] = mp[now] + "^"
else:
mp[deeplist[i]] = li[i]
ans += " " + li[i]
return ans.replace(" ", "")
def pre_mask():
mask = np.zeros([rulelist_len, rulelist_len])
for i in range(rulelist_len):
for t in range(i + 1):
mask[i][t] = 1
return mask
def g_predict_beam(sess, model, batch_data):
batch = batch_data
rewards = np.zeros([len(batch[1])])
for i in range(len(rewards)):
rewards[i] = 1
y = sess.run(model.y_result, feed_dict={model.input_NL: batch[0],
model.input_NLChar:batch[1],
model.inputrulelist:batch[6],
model.inputrulelistnode:batch[7],
model.inputrulelistson:batch[8],
model.tree_path_vec: batch[9],
model.treemask: batch[10],
model.father_mat: batch[11],
model.labels:batch[12],
model.antimask:pre_mask(),
#model.state:state,
model.keep_prob: 1,
model.rewards: rewards,
model.is_train: False
})
#print (batch[6])
#print (len(y))
#print (len(y[0]))
#print (len(y[0][0]))
for i in range(len(batch[6][0])):
if batch[6][0][i] == 0:
return y[0][i - 1]
return y[ -1 ]
#print (pre_rules)
#return acc, pre, pre_rules
def get_tree_path_vec_for_pre (tree_path):
fathers = []
tree_path_len = 10
tree_path_vec = np.zeros([length[5], tree_path_len])
#return tree_path_vec
for i in range(len(tree_path)):
words = tree_path[i].strip().split()
for t in range(min(len(words), tree_path_len)):
tree_path_vec[i][t] = word2vec(words[t], "tree")
fathers.append(word2vec(words[0], "tree"))
return tree_path_vec, fathers
step = 1
# length = [nl_len, tree_len, tree_len, tree_len, parent_len, rulelist_len, 1, function_len]
def getAction(sess, Code_gen_model, JavaOut):
valid_batch, _ = batch_data(1, "test") # read data
input_NL = line2vec(JavaOut.Nl, "nl", length[0])
#print (input_NL)
input_NLChar = line2charvec(JavaOut.Nl, length[0], char_len)
#print (input_NLChar)
input_Tree = line2vec(cov(JavaOut.Tree), "tree", length[1])
input_Father = line2vec(cov(JavaOut.FatherTree), "tree", length[2])
input_Grand = line2vec(cov(JavaOut.GrandFatherTree), "tree", length[3])
tree_path_vec, father_vec = get_tree_path_vec_for_pre(JavaOut.Root)
print (JavaOut.Root)
deepthlist = []
tree_path = JavaOut.Root
for i in range(len(tree_path)):
words = tree_path[i].strip().split()
deepthlist.append(str(len(words)))
root = ""
#for r in JavaOut.Root:
# print (str(r))
#for n in JavaOut.Root.split():
# root += str(n) + "_root "
#input_Root = line2vec(root, "tree", length[4])
rules_str = ""
print (JavaOut.RuleList)
rules_destart = ""
flag = True
for n in JavaOut.RuleList:
rules_str += str(n) + " "
#rules_str += "23"
input_Rules = line2rulevec(rules_str, length[5])
print (JavaOut.Nl)
#print (input_Rules)
#print (input_Rules)
input_func = np.zeros([1])
list_input = []
list_input.append(input_NL)
list_input.append(input_NLChar)
list_input.append(input_Tree)
list_input.append(input_Father)
list_input.append(input_Grand)
list_input.append("")
list_input.append(input_Rules)
v1, v2 = line2rules(rules_str, length[5], father_vec, JavaOut.Nl)
list_input.append(v1)
#print (v1)
list_input.append(v2)
#print (v2)
global step
#list_input.append(valid_batch[0][12][0])
#for i in range(len(list_input[-1])):
# for t in range(len(list_input[-1][i])):
# if i > step:
# list_input[-1][i][t] = 0
step += 1
list_input.append(tree_path_vec)
#print (listu_input)
#exit()
deepth = " ".join(deepthlist)
print ("------")
print (JavaOut.father_index)
#print (deepth)
line = ""
for f in JavaOut.father_index:
line += str(f) + " "
print (line)
ret, father_vec, labels = line2mask(line, length[5])
#if len(JavaOut.RuleList) > 0 and (JavaOut.RuleList[-1] - 1 >= len(Rule) or (len(Rule[JavaOut.RuleList[-1] - 1][1]) == 1 and Rule[JavaOut.RuleList[-1] - 1][1][0] not in Nonterminal)):
# labels[len(JavaOut.RuleList) + 1] = 2 # for terminals
list_input.append(ret)
list_input.append(father_vec)
list_input.append(labels)
for i in range(len(list_input)):
list_input[i] = np.expand_dims(list_input[i], axis=0)
return g_predict_beam(sess, Code_gen_model, list_input)
def WriteJavaIn(JavaOut, action):
f = open(project + "Tree_Rule.in", "w")
f.write(JavaOut.TreeWithEnd)
f.write("\n")
f.write(str(action))
f.write("\n")
f.write(str(JavaOut.Nl))
f.write("\n")
f.close()
def BeamSearch(sess, Code_gen_model, Nl, N, NL_number):
Javaout = getJavaOut(Nl)
global J_NlList
J_NlList = Nl.strip().split()
#Javaout.RuleList.append(classnum + 2)
close_table = {}
close_table[Javaout.Tree] = 1
#get_deepth(Javaout, Javaout.Tree, len(Javaout.RuleList))
Beam = [Javaout]
Set_ = Q.PriorityQueue()
level = 0
words = Nl.split()
while True:
#print("search level is " + str(level))
level += 1
Set_ = Q.PriorityQueue()
if level > 10000:
N -= 1
for JavaOut in Beam:
if JavaOut.is_end :
Set_.put(JavaOut)
continue
print ("-----------")
res = getAction(sess, Code_gen_model, JavaOut)
list_res = [[res[i], i] for i in range(len(res))]
#exit()
try:
list_res = sorted(list_res, reverse=True)
except:
JavaOut.is_end = True
Set_.put(JavaOut)
continue
count_n = N
#print ("-----------")
#print (list_res[0])
print (list_res[0])
for t in range(len(list_res)):
if t >= count_n:
break
i = int(list_res[t][1])
if i < len(Rule) and Rule[i][0] != JavaOut.Node:
count_n += 1
continue
if i >= len(Rule) + len(words):
count_n += 1
continue
if i >= len(Rule) and JavaOut.Node.strip() not in copy_node:
count_n += 1
continue
WriteJavaIn(JavaOut, i )
global global_step
global_step = JavaOut.gs
global step_list_p
step_list_p = deepcopy(JavaOut.step_list)
J_run()
JavaOutNext = getJavaOut(Nl)
JavaOutNext.step_list = step_list_p
print (step_list_p)
JavaOutNext.gs = global_step
if JavaOutNext.state == "error":
count_n += 1
#thres = v[0, max(0, - N - count_n)]
continue
JavaOutNext.RuleList = deepcopy(JavaOut.RuleList)
JavaOutNext.Root = deepcopy(JavaOut.Root) + JavaOutNext.Root
JavaOutNext.rule = deepcopy(JavaOut.rule)
JavaOutNext.father_index = deepcopy(JavaOut.father_index)#.append(father_index_now)
JavaOutNext.father_index.append(father_index_now)
print (JavaOutNext.father_index)
nowtree = JavaOutNext.Tree
print (i)
#print (res[0, i])
print (JavaOutNext.Tree)
apa = 0.6
if JavaOutNext.state == "grow":
print("grow")
print ("{Rule: %s}" % str(i))
#if len(JavaOutNext.Tree.split()) > 1000:
# continue
JavaOutNext.Probility = (JavaOut.Probility * math.pow(len(JavaOut.RuleList), apa) + math.log(max(1e-10, res[i]))) / math.pow(len(JavaOut.RuleList) + 1, apa)
JavaOutNext.RuleList.append(i + 1)
#get_deepth(JavaOutNext, JavaOutNext.Tree, len(JavaOutNext.RuleList))
Set_.put(JavaOutNext)
elif JavaOutNext.state == "end": # BUG!!!!?????
if JavaOutNext.Tree != JavaOut.Tree:
JavaOutNext.Probility = (JavaOut.Probility * math.pow(len(JavaOut.RuleList), apa) + math.log(max(1e-10, res[i]))) / math.pow(len(JavaOut.RuleList) + 1, apa)
else:
JavaOutNext.Probility = JavaOut.Probility
JavaOutNext.is_end = True
Set_.put(JavaOutNext)
Beam = []
endnum = 0
while((not Set_.empty()) and N > len(Beam)):
JavaOut = Set_.get()
print(JavaOut.Probility)
# if JavaOut.Tree not in close_table:
close_table[JavaOut.Tree] = 1
Beam.append(JavaOut)
if JavaOut.is_end:
endnum += 1
if endnum >= N:
# print("end")
f = open(project + "out/"+str(NL_number)+".txt","w")
for JavaOut in Beam:
f.write(JavaOut.Tree)
f.write("\n")
f.write(str(JavaOut.Probility))
f.write("\n")
f.close()
break
def predict():
#readvoc()
global Tree_vocabu_size
global NL_vocabu_size
NL_vocabu_size = len(vocabulary)
Tree_vocabu_size = len(tree_vocabulary)
Code_gen_model = code_gen_model(classnum, embedding_size, conv_layernum, conv_layersize, rnn_layernum,
batch_size, NL_vocabu_size, Tree_vocabu_size, NL_len, Tree_len, parent_len, learning_rate, keep_prob, len(char_vocabulary), rules_len)
#gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.6)
#config = tf.ConfigProto(device_count={"GPU": 0})
#config = tf.ConfigProto(allow_soft_placement=True, gpu_options=gpu_options)
config = tf.ConfigProto(allow_soft_placement=True)
config.gpu_options.allow_growth = True
#gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0)
#config = tf.ConfigProto(allow_soft_placement=True, gpu_options=gpu_options)
#config = tf.ConfigProto(allow_soft_placement=True, gpu_options=config)
with tf.Session(config=config) as sess:
create_model(sess, "", "")
f = open(project + "input.txt", "r")
lines = f.readlines()
f.close()
for i in range(len(lines)):
Nl = lines[i].strip()
print(Nl)
f = open(project + "Tree_Feature.out", "w")
f.write("root ^")
f.write("\n")
f.write("root")
f.write("\n")
f.write("Unknown")
f.write("\n")
f.write("root\n")
f.write("root node_gen ^ ^\n")
f.write("root node_gen ^ ^\n")
f.write("Unknown root ^ ^\n")
f.write("Unknown Unknown ^ ^\n")
f.write("root node_gen ^\n")
f.write("Unknown root ^ ^\n")
f.write("Unknown Unknown ^ ^\n")
f.close()
BeamSearch(sess, Code_gen_model, Nl, int(sys.argv[2]), i)
print(str(i) + "th card is finished")
# exit()
def read_copy_node():
f = open(project + "copy_node.txt", "r")
lines = f.readlines()
f.close()
for line in lines:
copy_node.append(line.strip())
def main():
#np.set_printoptions(threshold=np.nan)
# ReadRule()
read_copy_node()
print ("predict start")
predict()
main()