File size: 2,626 Bytes
5eea4e3
 
 
 
ec631f0
 
5eea4e3
ab84f0a
5eea4e3
 
e50255f
ec631f0
 
 
 
9cb9653
 
ec631f0
a2e8eab
ec631f0
 
 
 
 
 
e50255f
 
 
ec631f0
 
e50255f
 
ec631f0
5eea4e3
 
ec631f0
 
 
5eea4e3
 
19149e5
ec631f0
 
 
 
 
 
5eea4e3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from transformers import AutoTokenizer
from transformers import AutoModelForSequenceClassification
import gradio as gr

model_name = "biodatlab/score-claim-identification"
tokenizer_name = "allenai/scibert_scivocab_uncased"

tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)


def inference(abstract: str):
    """
    Split an abstract into sentences and perform claim identification.
    """
    if abstract.strip() == "":
        return "Please provide an abstract as an input."
    claims = []
    sents = abstract.split(". ")  # abstract to sentences
    inputs = tokenizer(
        sents,
        return_tensors="pt",
        truncation=True,
        padding="longest"
    )
    logits = model(**inputs).logits
    preds = logits.argmax(dim=1)  # convert logits to predictions
    claims = [sent for sent, pred in zip(sents, preds) if pred == 1]
    if len(claims) > 0:
        return ".\n".join(claims)
    else:
        return "No claims found from a given abstract."


with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# SCORE Claim Identification")
    gr.Markdown("This is a demo to find scientific claims made by a given abstract.")
    abstract = gr.Textbox(label="Abstract")
    greet_btn = gr.Button("Find Claims")
    output = gr.Textbox(label="Detected Claims")
    greet_btn.click(fn=inference, inputs=abstract, outputs=output, api_name="inference")
    examples = gr.Examples(
        examples=[
            "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."
        ],
        inputs=[abstract]
    )

demo.launch()