Spaces:
Build error
Build error
File size: 848 Bytes
e38d825 828b751 e38d825 828b751 4257568 828b751 4257568 828b751 4257568 828b751 4257568 f83d80f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import BartForSequenceClassification, BartTokenizer
# model = pipeline("text-generation")
# following https://joeddav.github.io/blog/2020/05/29/ZSL.html
tokenizer_bart = BartTokenizer.from_pretrained('facebook/bart-large-mnli')
model_bart_sq = BartForSequenceClassification.from_pretrained('facebook/bart-large-mnli')
# def predict(prompt):
# completion = model(prompt)[0]["generated_text"]
# return completion
def zs(premise,hypothesis):
input_ids = tokenizer_bart.encode(premise, hypothesis, return_tensors='pt')
logits = model_bart_sq(input_ids)[0]
entail_contradiction_logits = logits[:,[0,2]]
probs = entail_contradiction_logits.softmax(dim=1)
true_prob = probs[:,1].item() * 100
return true_prob
gr.Interface(fn=zs, inputs=["text", "text"], outputs="text").launch() |