Code Monkey home page Code Monkey logo

triple_metric's Introduction

triple_metric

triple_metric

Dependecy

  • datasets
  • torch
  • fastcore

Use

import torch
from datasets import load_metric
from fastcore.foundation import L

metric = load_metric("triple_metric.py")
pred = torch.load("preds")
references = torch.load("golds")

def find_best_f1(pred,references,id2label=None,thres=0.62):
    predictions = list(L(pred).map(lambda x:L(x).filter(lambda y:y[3]>thres and y[1]<=y[2]).map(lambda z:z[:3])))
    m = metric.compute(predictions=predictions,references=references,id2label=id2label,digits=6)
    return m

max_f1 = 0.0
id2label = dict(zip(range(9),["bod", "dep", "dis", "dru", "equ", "ite", "mic", "pro", "sym"]))
for i in range(30,95):
    thres = i/100
    m = find_best_f1(pred,references,id2label=None,thres=thres)
    if m["micro_avg"].f1>=max_f1:
        max_f1 = m["micro_avg"].f1
        print("thres",thres,"\t","micro_avg",m["micro_avg"])

triple_metric's People

Contributors

junnyu avatar

Watchers

 avatar  avatar

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.