def fBrownCluster(self): if self.brnclst == None: self.brnclst = utils.readMetaOptimizeBrownCluster() key = "brnclst1gram" if key not in self.featurestest: self.featurestest[key] = [] for instance in self.test: rs = features.getBrownClusNgram(instance.rawsent,1,self.brnclst) rs = ["_".join(x) for x in rs] self.featurestest[key].append(rs)
s = Space(101) s.loadFromFile(BRNCLSTSPACEFILE) return s def readScales(scalefile): scales = {} with open(scalefile) as f: for line in f: k, v = line.strip().split("\t") scales[int(k)] = float(v) f.close() return scales brnclst = utils.readMetaOptimizeBrownCluster() embeddings = utils.readMetaOptimizeEmbeddings() brnspace = initBrnSpace() scales_shallow = readScales(SHALLOWSCALEFILE) scales_neuralbrn = readScales(NEURALBRNSCALEFILE) model_shallow = ll.load_model(SHALLOWMODELFILE) model_neuralbrn = ll.load_model(NEURALBRNMODELFILE) def simpleScale(x, trainmaxes=None): maxes = trainmaxes if trainmaxes != None else {} if trainmaxes == None: for itemd in x: for k, v in itemd.items(): if k not in maxes or maxes[k] < abs(v): maxes[k] = abs(v) newx = []
def initBrnSpace(): s = Space(101) s.loadFromFile(BRNCLSTSPACEFILE) return s def readScales(scalefile): scales = {} with open(scalefile) as f: for line in f: k,v = line.strip().split("\t") scales[int(k)] = float(v) f.close() return scales brnclst = utils.readMetaOptimizeBrownCluster() embeddings = utils.readMetaOptimizeEmbeddings() brnspace = initBrnSpace() scales_shallow = readScales(SHALLOWSCALEFILE) scales_neuralbrn = readScales(NEURALBRNSCALEFILE) model_shallow = ll.load_model(SHALLOWMODELFILE) model_neuralbrn = ll.load_model(NEURALBRNMODELFILE) def simpleScale(x, trainmaxes=None): maxes = trainmaxes if trainmaxes!=None else {} if trainmaxes == None: for itemd in x: for k,v in itemd.items(): if k not in maxes or maxes[k] < abs(v): maxes[k] = abs(v) newx = [] for itemd in x: