Beispiel #1
0
 def f1(data, name):
     print
     print 'Phrase-based F1:', name
     f1 = F1()
     for i, x in enumerate(iterview(data)):
         predict = extract_contiguous(model(x))
         truth = extract_contiguous(x.truth)
         # (i,begin,end) uniquely identifies the span
         for (label, begins, ends) in truth:
             f1.add_relevant(label, (i, begins, ends))
         for (label, begins, ends) in predict:
             f1.add_retrieved(label, (i, begins, ends))
     print
     return f1.scores(verbose=True)
Beispiel #2
0
 def evaluate(self, predict, data, name, verbosity=1):
     if not data:
         return
     if verbosity:
         print()
         print('Phrase-based F1:', name)
     f1 = F1()
     for i, x in enumerate(iterview(data, msg='Eval %s' % name)):
         pred = extract_contiguous(predict(x))
         gold = extract_contiguous(self.Y.lookup_many(x.tags))
         # (i,begin,end) uniquely identifies the span
         for (label, begins, ends) in gold:
             f1.add_relevant(label, (i, begins, ends))
         for (label, begins, ends) in pred:
             f1.add_retrieved(label, (i, begins, ends))
     if verbosity:
         print()
     return f1.scores(verbose=verbosity >= 1)
Beispiel #3
0
    def predict(self,tokenlist):
        """ Takes a list of Tokens and returns the prediction on the data. """

        for i, x in enumerate(iterview([tokenlist])):
            if x:
                predict = extract_contiguous(self.model(x))
            else:
                return None
        return predict