def CFG2CNF(modelPath): K, V, Productions = helper.loadModel(modelPath) Productions = START(Productions, V) Productions = removeTERM(Productions, V) Productions = nonunitaryremoval(Productions, V) Productions = DELmakeNewRules(Productions) Productions = UNITremoval(Productions, V) return K, Productions
def UNIT(productions, variables): i = 0 result = unit_routine(productions, variables) tmp = unit_routine(result, variables) while result != tmp and i < 1000: result = unit_routine(tmp, variables) tmp = unit_routine(result, variables) i += 1 return result if __name__ == '__main__': if len(sys.argv) > 1: modelPath = str(sys.argv[1]) else: modelPath = 'model.txt' K, V, Productions = helper.loadModel(modelPath) Productions = START(Productions, variables=V) Productions = TERM(Productions, variables=V) Productions = BIN(Productions, variables=V) Productions = DEL(Productions) Productions = UNIT(Productions, variables=V) print(helper.prettyForm(Productions)) print(len(Productions)) open('out.txt', 'w').write(helper.prettyForm(Productions))
"""Define parameters of the run""" DUMP_WEIGHTS = True #will we dump the weights of conv layers for visualization batch_size = 4 #how many training examples per batch """Define the folder where the model will be stored based on the input arguments""" folder = helper.defineFolder(True,outType,size,run) print folder trainNP = folder+"tempTrain/" print trainNP model = helper.loadModel(folder+"wholeModel") """ TRAINING """ superEpochs = 10000 RMSE = 1000000 oldRMSE = 1000000 for sup in range(0,superEpochs): oldRMSE = min(oldRMSE,RMSE) print "*"*80 print "TRUE EPOCH ", sup print "*"*80 count = 0 added = 0