'Train a model from sentences, and save it at ``save_loc``. ``nr_iter``
controls the number of Perceptron training iterations.
:param sentences: A list or iterator of sentences, where each sentence
is a list of (words, tags) tuples.
:param save_loc: If not ``None``, saves a pickled model in this location.
:param nr_iter: Number of training iterations.'

def train(self, sentences, save_loc=None, nr_iter=5):

    self._sentences = list()
    self._make_tagdict(sentences)
    self.model.classes = self.classes
    for iter_ in range(nr_iter):
        c = 0
        n = 0
        for sentence in self._sentences:
            (words, tags) = zip(*sentence)
            (prev, prev2) = self.START
            context = ((self.START + [self.normalize(w) for w in words]) + self.END)
            for (i, word) in enumerate(words):
                guess = self.tagdict.get(word)
                if (not guess):
                    feats = self._get_features(i, word, context, prev, prev2)
                    guess = self.model.predict(feats)
                    self.model.update(tags[i], guess, feats)
                prev2 = prev
                prev = guess
                c += (guess == tags[i])
                n += 1
        random.shuffle(self._sentences)
        logging.info('Iter    {0}:    {1}/{2}={3}'.format(iter_, c, n, _pc(c, n)))
    self._sentences = None
    self.model.average_weights()
    if (save_loc is not None):
        with open(save_loc, 'wb') as fout:
            pickle.dump((self.model.weights, self.tagdict, self.classes), fout, 2)
