MiyunKim commited on
Commit
fb318bc
·
verified ·
1 Parent(s): 1302ee1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -4,9 +4,10 @@ import shap
4
  import numpy as np
5
  import scipy as sp
6
  import torch
7
-
8
  import transformers
9
  from transformers import pipeline
 
10
  from transformers import AutoModelForSequenceClassification
11
  from transformers import TFAutoModelForSequenceClassification
12
  from transformers import AutoTokenizer, AutoModelForTokenClassification
@@ -19,8 +20,8 @@ csv.field_size_limit(sys.maxsize)
19
 
20
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
21
 
22
- tokenizer = AutoTokenizer.from_pretrained("bert-based-case/ADR_Detector")
23
- model = AutoModelForSequenceClassification.from_pretrained("bert-based-case/ADR_Detector").to(device)
24
 
25
  # build a pipeline object to do predictions
26
  pred = transformers.pipeline("text-classification", model=model,
@@ -41,11 +42,17 @@ explainer = shap.Explainer(pred)
41
  # score_1sym = x['score']
42
  # return round(score_1sym,3)
43
 
 
 
 
 
 
 
44
  def adr_predict(x):
45
  encoded_input = tokenizer(x, return_tensors='pt')
46
  output = model(**encoded_input)
47
- scores = output[0][0].detach()
48
- scores = torch.nn.functional.softmax(scores)
49
 
50
  shap_values = explainer([str(x).lower()])
51
  # # Find the index of the class you want as the default reference (e.g., 'label_1')
@@ -83,10 +90,9 @@ def adr_predict(x):
83
  prev_end = end
84
 
85
  htext += x[prev_end:]
86
-
87
- return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}, local_plot,htext
88
- # ,{"Contains Medication": float(med), "No Medications": float(1-med)} , {"Contains Symptoms": float(sym), "No Symptoms": float(1-sym)}
89
 
 
 
90
 
91
  def main(prob1):
92
  text = str(prob1).lower()
 
4
  import numpy as np
5
  import scipy as sp
6
  import torch
7
+ import tensorflow as tf
8
  import transformers
9
  from transformers import pipeline
10
+ from transformers import RobertaTokenizer, RobertaModel
11
  from transformers import AutoModelForSequenceClassification
12
  from transformers import TFAutoModelForSequenceClassification
13
  from transformers import AutoTokenizer, AutoModelForTokenClassification
 
20
 
21
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
22
 
23
+ tokenizer = AutoTokenizer.from_pretrained("paragon-analytics/ADRv1")
24
+ model = AutoModelForSequenceClassification.from_pretrained("paragon-analytics/ADRv1").to(device)
25
 
26
  # build a pipeline object to do predictions
27
  pred = transformers.pipeline("text-classification", model=model,
 
42
  # score_1sym = x['score']
43
  # return round(score_1sym,3)
44
 
45
+ ner_tokenizer = AutoTokenizer.from_pretrained("d4data/biomedical-ner-all")
46
+ ner_model = AutoModelForTokenClassification.from_pretrained("d4data/biomedical-ner-all")
47
+
48
+ ner_pipe = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer, aggregation_strategy="simple") # pass device=0 if using gpu
49
+ #
50
+
51
  def adr_predict(x):
52
  encoded_input = tokenizer(x, return_tensors='pt')
53
  output = model(**encoded_input)
54
+ scores = output[0][0].detach().numpy()
55
+ scores = tf.nn.softmax(scores)
56
 
57
  shap_values = explainer([str(x).lower()])
58
  # # Find the index of the class you want as the default reference (e.g., 'label_1')
 
90
  prev_end = end
91
 
92
  htext += x[prev_end:]
 
 
 
93
 
94
+ return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}, local_plot,htext
95
+ # ,{"Contains Medication": float(med), "No Medications": float(1-med)} , {"Contains Symptoms": float(sym), "No Symptoms": float(1-sym)}
96
 
97
  def main(prob1):
98
  text = str(prob1).lower()