Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import shap
|
|
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
|
@@ -21,7 +20,7 @@ csv.field_size_limit(sys.maxsize)
|
|
21 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
22 |
|
23 |
tokenizer = AutoTokenizer.from_pretrained("vikvenk/ADR_Detection")
|
24 |
-
model = AutoModelForSequenceClassification.from_pretrained("vikvenk/ADR_Detection"
|
25 |
# build a pipeline object to do predictions
|
26 |
pred = transformers.pipeline("text-classification", model=model,
|
27 |
tokenizer=tokenizer, return_all_scores=True)
|
@@ -50,8 +49,8 @@ ner_pipe = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer, aggregation
|
|
50 |
def adr_predict(x):
|
51 |
encoded_input = tokenizer(x, return_tensors='pt')
|
52 |
output = model(**encoded_input)
|
53 |
-
scores = output[0][0].detach()
|
54 |
-
scores =
|
55 |
|
56 |
shap_values = explainer([str(x).lower()])
|
57 |
# # Find the index of the class you want as the default reference (e.g., 'label_1')
|
|
|
4 |
import numpy as np
|
5 |
import scipy as sp
|
6 |
import torch
|
|
|
7 |
import transformers
|
8 |
from transformers import pipeline
|
9 |
from transformers import RobertaTokenizer, RobertaModel
|
|
|
20 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
21 |
|
22 |
tokenizer = AutoTokenizer.from_pretrained("vikvenk/ADR_Detection")
|
23 |
+
model = AutoModelForSequenceClassification.from_pretrained("vikvenk/ADR_Detection").to(device)
|
24 |
# build a pipeline object to do predictions
|
25 |
pred = transformers.pipeline("text-classification", model=model,
|
26 |
tokenizer=tokenizer, return_all_scores=True)
|
|
|
49 |
def adr_predict(x):
|
50 |
encoded_input = tokenizer(x, return_tensors='pt')
|
51 |
output = model(**encoded_input)
|
52 |
+
scores = output[0][0].detach()
|
53 |
+
scores = torch.nn.functional.softmax(scores)
|
54 |
|
55 |
shap_values = explainer([str(x).lower()])
|
56 |
# # Find the index of the class you want as the default reference (e.g., 'label_1')
|