titipata commited on
Commit
ec631f0
1 Parent(s): ab84f0a

Minor code sanitization

Browse files
Files changed (1) hide show
  1. app.py +32 -18
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 = '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):
12
- claims = []
13
- lines = abstract.split('. ')
14
- inputs = tokenizer(lines,return_tensors='pt',truncation=True,padding="longest")
15
- output = model(**inputs).logits
16
- for (i,out) in enumerate(output):
17
- pred = out.argmax().item()
18
- if pred:
19
- claims.append(lines[i])
20
- if claims:
21
- return '.\n'.join(claims)
22
- return 'No claims were made here'
 
 
 
 
 
 
 
 
 
23
 
24
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
25
- gr.Markdown("# Claim Identification")
26
- gr.Markdown("This demo finds claims made by an abstract.")
27
- abst = gr.Textbox(label="Abstract")
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(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=[abst])
 
 
 
 
 
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()