

def evaluate_srl_predicates(gold_file):
    '\n    Evaluates the performance of the network on the SRL task for the\n    predicate detection subtask.\n    '
    md = Metadata.load_from_file('srl_predicates')
    nn = taggers.load_network(md)
    reader = taggers.create_reader(md, gold_file=gold_file)
    reader.codify_sentences()
    total_tokens = 0
    (tp, fp, tn, fn) = (0, 0, 0, 0)
    for (sent, tags) in izip(reader.sentences, reader.tags):
        answer = nn.tag_sentence(sent)
        for (net_tag, gold_tag) in izip(answer, tags):
            if (gold_tag == 1):
                if (net_tag == gold_tag):
                    tp += 1
                else:
                    fn += 1
            elif (net_tag == gold_tag):
                tn += 1
            else:
                fp += 1
        total_tokens += len(sent)
    precision = (float(tp) / (tp + fp))
    recall = (float(tp) / (tp + fn))
    print(('True positives: %d, false positives: %d, true negatives: %d, false negatives: %d' % (tp, fp, tn, fn)))
    print(('Accuracy: %f' % (float((tp + tn)) / total_tokens)))
    print(('Precision: %f' % precision))
    print(('Recall: %f' % recall))
    print(('F-1: %f' % (((2 * precision) * recall) / (precision + recall))))

dataset/ETHPy150Open erickrf/nlpnet/bin/nlpnet-test.py evaluate_srl_predicates/original