def simulate(self, actions, sent): '''simulate the result of a given sequence of actions''' self.State.sent = sent n = len(sent) state = self.State.initstate() # initial state actionfeats = Vector() for i, action in enumerate(actions, 1): ## actionfeats += state.make_feats(action) ## has to be OLD STATE -- WHY? for feat in state.make_feats(action): #if action[0] != -2: actionfeats[feat] += 1 if action in state.allowed_actions(): for new in state.take(action): state = new break else: print >> logs, "Error! BAD SEQUENCE!" break return state, actionfeats
def __init__(self, decoder): self.trainfile = FLAGS.train self.trainlines = open(self.trainfile).readlines() self.devfile = FLAGS.dev self.devlines = open(self.devfile).readlines() self.outfile = FLAGS.out self.save_to = FLAGS.save_to self.decoder = decoder # a class, providing functions: load(), decode(), get_feats() self.iter = FLAGS.iter self.start_iter = FLAGS.start_iter self.avg = FLAGS.avg self.shuffle = FLAGS.shuffle self.weights = decoder.model.weights if FLAGS.resume_from is None: self.allweights = Vector() self.c = 0. # counter: how many examples have i seen so far? = it * |train| + i else: self.c = (self.start_iter - 1) * len(self.trainlines) self.allweights = Model( FLAGS.allweights).weights # read all weights from file
def __init__(self, decoder): self.trainfile = FLAGS.train self.devfile = FLAGS.dev self.outfile = FLAGS.out self.decoder = decoder # a class, providing functions: load(), decode(), get_feats() self.iter = FLAGS.iter self.avg = FLAGS.avg self.weights = decoder.model.weights self.allweights = Vector() self.c = 0. # counter: how many examples have i seen so far? = it * |train| + i
def feats(self, action=None): if self._feats is None: self._feats = self.model.make_feats( self) #if self.model is not None else [] if action is None: return self._feats else: aa = "=>" + State.names[action] fv = Vector() for f in self._feats: fv[f + aa] = 1 return fv