Spaces:
Runtime error
Runtime error
Minor code sanitization
Browse files
app.py
CHANGED
@@ -2,32 +2,46 @@ from transformers import AutoTokenizer
|
|
2 |
from transformers import AutoModelForSequenceClassification
|
3 |
import gradio as gr
|
4 |
|
5 |
-
model_name =
|
6 |
-
tokenizer_name =
|
7 |
|
8 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
9 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
|
11 |
-
def inference(abstract):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
25 |
-
gr.Markdown("# Claim Identification")
|
26 |
-
gr.Markdown("This demo
|
27 |
-
|
28 |
greet_btn = gr.Button("Find Claims")
|
29 |
output = gr.Textbox(label="Detected Claims")
|
30 |
greet_btn.click(fn=inference, inputs=abst, outputs=output, api_name="inference")
|
31 |
-
examples = gr.Examples(
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
demo.launch()
|
|
|
2 |
from transformers import AutoModelForSequenceClassification
|
3 |
import gradio as gr
|
4 |
|
5 |
+
model_name = "biodatlab/score-claim-identification"
|
6 |
+
tokenizer_name = "allenai/scibert_scivocab_uncased"
|
7 |
|
8 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
9 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
|
11 |
+
def inference(abstract: str):
|
12 |
+
"""
|
13 |
+
Split an abstract into sentences and perform claim identification.
|
14 |
+
"""
|
15 |
+
claims = []
|
16 |
+
sents = abstract.split('. ')
|
17 |
+
inputs = tokenizer(
|
18 |
+
sents,
|
19 |
+
return_tensors="pt",
|
20 |
+
truncation=True,
|
21 |
+
padding="longest"
|
22 |
+
)
|
23 |
+
output = model(**inputs).logits
|
24 |
+
for (idx, out) in enumerate(output):
|
25 |
+
pred = out.argmax().item()
|
26 |
+
if pred:
|
27 |
+
claims.append(lines[idx])
|
28 |
+
if len(claims) > 0:
|
29 |
+
return ".\n".join(claims)
|
30 |
+
return "No claims were made here"
|
31 |
+
|
32 |
|
33 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
34 |
+
gr.Markdown("# SCORE Claim Identification")
|
35 |
+
gr.Markdown("This is a demo to find scientific claims made by a given abstract.")
|
36 |
+
abstract = gr.Textbox(label="Abstract")
|
37 |
greet_btn = gr.Button("Find Claims")
|
38 |
output = gr.Textbox(label="Detected Claims")
|
39 |
greet_btn.click(fn=inference, inputs=abst, outputs=output, api_name="inference")
|
40 |
+
examples = gr.Examples(
|
41 |
+
examples=[
|
42 |
+
"This study adopted a person (actor) by partner perspective to examine how actor personality traits, partner personality traits, and specific actor by partner personality trait interactions predict actor's depressive symptoms across the first 2years of the transition to parenthood. Data were collected from a large sample of new parents (both partners in each couple) 6weeks before the birth of their first child, and then at 6, 12, 18, and 24months postpartum. The results revealed that higher actor neuroticism and lower partner agreeableness predicted higher levels of depressive symptoms in actors. Moreover, the specific combination of high actor neuroticism and low partner agreeableness was a particularly problematic combination, which was intensified when prepartum dysfunctional problem-solving communication and aggression existed in the relationship. These results demonstrate the importance of considering certain actor by partner disposition pairings to better understand actors' emotional well-being during major life transitions."
|
43 |
+
],
|
44 |
+
inputs=[abstract]
|
45 |
+
)
|
46 |
|
47 |
demo.launch()
|