def train_crf_sgd(self, n_epochs, sigma, eta0 = 0.001):
        '''Trains the parser by running the online MaxEnt algorithm for n_epochs, regularization coefficient sigma, 
        and initial stepsize eta0 (which anneals as O(1/(sigma*t))).''' 
        self.weights = np.zeros(self.features.n_feats)
        t = 0
        t0 = 1.0 / (sigma * eta0)
        for epoch in range(n_epochs):
            print "Epoch {0}".format(epoch+1)
            n_mistakes = 0
            n_tokens = 0
            n_instances = 0
            objective = 0.0
            for instance in self.reader.train_instances:
                eta = 1.0 / (sigma * (t + t0))
                feats = self.features.create_features(instance)
                scores = self.features.compute_scores(feats, self.weights)

                # Compute marginals and log-partition function, and move away from that direction
                marginals, logZ = self.decoder.parse_marginals_nonproj(scores)
                self.weights -= eta * sigma * self.weights # Scale the weight vector
                for h in range(np.size(marginals,0)):
                    for m in range(1, np.size(marginals,1)):
                        if feats[h][m] == None:
                            continue
                        for f in feats[h][m]: 
                            if 0 < f:
                                continue
                            self.weights[f] -= eta * marginals[h,m]

                # Compute score of the correct parse, and move the weight vector towards that direction. 
                score_corr = 0.0                
                for m in range(1, np.size(instance.heads)):
                    h = instance.heads[m]
                    score_corr += scores[h,m]
                    for f in feats[h][m]: 
                        if f < 0:
                            continue
                        self.weights[f] += eta

                # Compute objective (w.r.t. this instance only)
                objective += 0.5 * sigma * np.dot(self.weights,self.weights) - score_corr + logZ

                n_instances += 1
                t += 1

            print "Training objective: {0}".format(objective / n_instances)
dataset/ETHPy150Open LxMLS/lxmls-toolkit/lxmls/parsing/dependency_parser.py/DependencyParser.train_crf_sgd/swapped operands of `<`