Spaces:
Stopped
Commit
•
c9498ec
1
Parent(s):
9139aa2
Delete job_coach_testing_site_zeroshot.py
Browse files
job_coach_testing_site_zeroshot.py
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""Job-coach-testing-site-zeroshot.ipynb
|
3 |
-
|
4 |
-
Automatically generated by Colaboratory.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/github/vanderbilt-data-science/job-coach-question-answering/blob/111-create-a-gradio-hf-space-to-test-whether-specific-information-is-in-a-coaching-document/job-coach-testing-zeroshot.ipynb
|
8 |
-
"""
|
9 |
-
|
10 |
-
import gradio as gr
|
11 |
-
|
12 |
-
import torch
|
13 |
-
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
|
14 |
-
from transformers import pipeline
|
15 |
-
|
16 |
-
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
17 |
-
question_answerer = pipeline("question-answering", model = "bert-large-uncased-whole-word-masking-finetuned-squad")
|
18 |
-
def zshot(context, queries):
|
19 |
-
answered=[]
|
20 |
-
res=[]
|
21 |
-
notAnswered=[]
|
22 |
-
queries=queries.split("?")
|
23 |
-
queries.pop(-1)
|
24 |
-
for query in queries:
|
25 |
-
query.strip()
|
26 |
-
result = question_answerer(question = query, context=context)
|
27 |
-
answered.append([query,result['answer']])
|
28 |
-
|
29 |
-
for item in answered:
|
30 |
-
result = ([text, classifier(text, item[0])])
|
31 |
-
if result[1]['scores'][0] > 0.01:
|
32 |
-
res.append(item[0] +"? Answer: " + item[1])
|
33 |
-
else:
|
34 |
-
notAnswered.append(item[0])
|
35 |
-
result1=''',
|
36 |
-
'''.join(res)
|
37 |
-
result1='''Information Included in the Document:
|
38 |
-
'''+ result1
|
39 |
-
result2=''',
|
40 |
-
'''.join(notAnswered)
|
41 |
-
result2='''
|
42 |
-
Information not included in the document, on no clearly stated:
|
43 |
-
'''+ result2
|
44 |
-
|
45 |
-
return result1 + result2
|
46 |
-
|
47 |
-
|
48 |
-
app = gr.Interface(
|
49 |
-
zshot,
|
50 |
-
inputs=[
|
51 |
-
gr.Textbox(label="Context", value=""),
|
52 |
-
gr.Textbox(label="Queries", value=""),
|
53 |
-
],
|
54 |
-
outputs=["text"],
|
55 |
-
)
|
56 |
-
app.launch()
|
57 |
-
|
58 |
-
"""#### Examples"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|