Code Monkey home page Code Monkey logo

Comments (3)

Hironsan avatar Hironsan commented on July 30, 2024 1

You just forgot to specify mode and scheme to classification_report. If it's specified correctly, the result is the same:

def evaluate(y_true, y_pred, scheme, average):
    print(precision_score(y_true, y_pred, average=average, mode='strict', scheme=scheme), end='\t')
    print(recall_score(y_true, y_pred, average=average, mode='strict', scheme=scheme), end='\t')
    print(f1_score(y_true, y_pred, average=average, mode='strict', scheme=scheme))
    print(classification_report(y_true, y_pred, digits=3, mode='strict', scheme=scheme))

# IOBES
0.6666666666666666      0.8     0.7272727272727272
              precision    recall  f1-score   support

         LOC      0.667     0.800     0.727        10

   micro avg      0.667     0.800     0.727        10
   macro avg      0.667     0.800     0.727        10
weighted avg      0.667     0.800     0.727        10

# BILOU
0.6666666666666666      0.8     0.7272727272727272
              precision    recall  f1-score   support

         LOC      0.667     0.800     0.727        10

   micro avg      0.667     0.800     0.727        10
   macro avg      0.667     0.800     0.727        10
weighted avg      0.667     0.800     0.727        10

from seqeval.

Hironsan avatar Hironsan commented on July 30, 2024

Please show me the evaluation snippet and the data.

from seqeval.

rsuwaileh avatar rsuwaileh commented on July 30, 2024

I generated a small example from my dataset:

z_true = [['O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'E-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'I-LOC', 'E-LOC', 'O', 'S-LOC', 'O', 'S-LOC', 'O', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'O', 'O', 'O', 'O', 'S-LOC', 'S-LOC', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'B-LOC', 'I-LOC', 'E-LOC', 'O', 'S-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'B-LOC', 'E-LOC', 'O', 'O', 'B-LOC', 'E-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O']]

z_pred = [['O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'E-LOC', 'B-LOC', 'I-LOC', 'E-LOC', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'I-LOC', 'E-LOC', 'O', 'S-LOC', 'O', 'S-LOC', 'O', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'O', 'O', 'O', 'O', 'S-LOC', 'S-LOC', 'B-LOC', 'I-LOC', 'E-LOC', 'O', 'O'], 
['O', 'S-LOC', 'O', 'O', 'O', 'O', 'S-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'O', 'B-LOC', 'E-LOC', 'B-LOC', 'E-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O']]
scheme = IOBES
average = "micro"
evaluate(z_true, z_pred, scheme, average)

The results I get:

0.6666666666666666	0.8	0.7272727272727272
              precision    recall  f1-score   support

         LOC      0.667     0.800     0.727        10

   micro avg      0.667     0.800     0.727        10
   macro avg      0.667     0.800     0.727        10
weighted avg      0.667     0.800     0.727        10

When I change the scheme to BILOU using the same example and lables above:

z_true = [['O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'L-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'I-LOC', 'L-LOC', 'O', 'U-LOC', 'O', 'U-LOC', 'O', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'O', 'O', 'O', 'O', 'U-LOC', 'U-LOC', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'B-LOC', 'I-LOC', 'L-LOC', 'O', 'U-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'B-LOC', 'L-LOC', 'O', 'O', 'B-LOC', 'L-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O']]

z_pred = [['O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'L-LOC', 'B-LOC', 'I-LOC', 'L-LOC', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'I-LOC', 'L-LOC', 'O', 'U-LOC', 'O', 'U-LOC', 'O', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'O', 'O', 'O', 'O', 'U-LOC', 'U-LOC', 'B-LOC', 'I-LOC', 'L-LOC', 'O', 'O'], 
['O', 'U-LOC', 'O', 'O', 'O', 'O', 'U-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'], 
['O', 'O', 'O', 'B-LOC', 'L-LOC', 'B-LOC', 'L-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O']]
scheme = BILOU
average = "micro"
evaluate(z_true, z_pred, scheme, average)

I get the same P, R, & F1. However, the report is different. I'm using micro average with both schemes:

0.6666666666666666	0.8	0.7272727272727272
              precision    recall  f1-score   support

         LOC      0.625     0.556     0.588         9

   micro avg      0.625     0.556     0.588         9
   macro avg      0.625     0.556     0.588         9
weighted avg      0.625     0.556     0.588         9

This is the evaluate function that uses seqeval:

def evaluate(y_true, y_pred, scheme, average):
    print(precision_score(y_true, y_pred, average = average, mode='strict', scheme=scheme), end='\t')
    print(recall_score(y_true, y_pred, average = average, mode='strict', scheme=scheme), end='\t')
    print(f1_score(y_true, y_pred, average = average, mode='strict', scheme=scheme))
    print(classification_report(y_true, y_pred, digits=3))

from seqeval.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.