Views
No views yet
transformers as follows:1import spacy
2from transformers import AutoTokenizer
3from transformers import AutoModelForSequenceClassification
4
5nlp = spacy.load("en_core_web_lg")
6model_name = "biodatlab/score-claim-identification"
7tokenizer_name = "allenai/scibert_scivocab_uncased"
8
9tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
10model = AutoModelForSequenceClassification.from_pretrained(model_name)
11
12def inference(abstract: str):
13 """
14 Split an abstract into sentences and perform claim identification.
15 """
16 if abstract.strip() == "":
17 return "Please provide an abstract as an input."
18 claims = []
19 sents = [sent.text for sent in nlp(abstract).sents] # a list of sentences
20 inputs = tokenizer(
21 sents,
22 return_tensors="pt",
23 truncation=True,
24 padding="longest"
25 )
26 logits = model(**inputs).logits
27 preds = logits.argmax(dim=1) # convert logits to predictions
28 claims = [sent for sent, pred in zip(sents, preds) if pred == 1]
29 if len(claims) > 0:
30 return ".\n".join(claims)
31 else:
32 return "No claims found from a given abstract."
33
34claims = inference(abstract) # string of claim joining with \n| Statement | Label |
|---|---|
| We consistently found that participants selectively chose to learn that bad (good) things happened to bad (good) people (Studies 1 to 7) that is, they selectively exposed themselves to deserved outcomes. | 1 (Claim) |
| Members of higher status groups generalize characteristics of their ingroup to superordinate categories that serve as a frame of reference for comparisons with outgroups (ingroup projection). | 0 (Null) |
| Motivational Interviewing helped the goal progress of those participants who, at pre-screening, reported engaging in many individual pro-environmental behaviors, but the more directive approach worked better for those participants who were less ready to change. | 1 (Claim) |
| Training Loss | Step | Validation Loss | Accuracy | F1 | Precision | Recall |
|---|---|---|---|---|---|---|
| 0.038000 | 3996 | 0.007086 | 0.997964 | 0.993499 | 0.995656 | 0.991350 |
gradio application in biodatlab space.