Spaces:
Runtime error
Runtime error
Commit
·
6886461
1
Parent(s):
8f5000f
bug fix
Browse files- .gitignore +3 -3
- app.py +7 -3
- sentiment_onnx_classify.py +10 -7
- zeroshot_clf.py +4 -4
.gitignore
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
venv
|
| 2 |
-
sent_clf_onnx
|
| 3 |
-
sentiment_model_dir
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
sent_clf_onnx/
|
| 3 |
+
sentiment_model_dir/
|
app.py
CHANGED
|
@@ -74,7 +74,10 @@ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
|
| 74 |
@st.cache(allow_output_mutation=True, suppress_st_warning=True, max_entries=None, ttl=None)
|
| 75 |
def create_model_dir(chkpt, model_dir):
|
| 76 |
if not os.path.exists(chkpt):
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
| 78 |
_model = AutoModelForSequenceClassification.from_pretrained(chkpt)
|
| 79 |
_tokenizer = AutoTokenizer.from_pretrained(chkpt)
|
| 80 |
_model.save_pretrained(model_dir)
|
|
@@ -95,8 +98,9 @@ if select_task=='README':
|
|
| 95 |
st.header("NLP Summary")
|
| 96 |
|
| 97 |
############### Pre-Download & instantiate objects for sentiment analysis *********************** START **********************
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
#create model/token dir
|
| 101 |
create_model_dir(chkpt=sent_chkpt, model_dir=sent_model_dir)
|
| 102 |
|
|
|
|
| 74 |
@st.cache(allow_output_mutation=True, suppress_st_warning=True, max_entries=None, ttl=None)
|
| 75 |
def create_model_dir(chkpt, model_dir):
|
| 76 |
if not os.path.exists(chkpt):
|
| 77 |
+
try:
|
| 78 |
+
os.mkdir(path=model_dir)
|
| 79 |
+
except:
|
| 80 |
+
pass
|
| 81 |
_model = AutoModelForSequenceClassification.from_pretrained(chkpt)
|
| 82 |
_tokenizer = AutoTokenizer.from_pretrained(chkpt)
|
| 83 |
_model.save_pretrained(model_dir)
|
|
|
|
| 98 |
st.header("NLP Summary")
|
| 99 |
|
| 100 |
############### Pre-Download & instantiate objects for sentiment analysis *********************** START **********************
|
| 101 |
+
|
| 102 |
+
sent_chkpt = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 103 |
+
sent_model_dir="sentiment_model_dir"
|
| 104 |
#create model/token dir
|
| 105 |
create_model_dir(chkpt=sent_chkpt, model_dir=sent_model_dir)
|
| 106 |
|
sentiment_onnx_classify.py
CHANGED
|
@@ -8,9 +8,9 @@ import transformers.convert_graph_to_onnx as onnx_convert
|
|
| 8 |
from pathlib import Path
|
| 9 |
import os
|
| 10 |
|
| 11 |
-
chkpt='distilbert-base-uncased-finetuned-sst-2-english'
|
| 12 |
-
model= AutoModelForSequenceClassification.from_pretrained(chkpt)
|
| 13 |
-
tokenizer= AutoTokenizer.from_pretrained(chkpt)
|
| 14 |
|
| 15 |
def create_onnx_model(_model, _tokenizer):
|
| 16 |
"""
|
|
@@ -24,7 +24,10 @@ def create_onnx_model(_model, _tokenizer):
|
|
| 24 |
|
| 25 |
"""
|
| 26 |
if not os.path.exists('sent_clf_onnx'):
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
"""
|
| 29 |
Making ONNX model object
|
| 30 |
"""
|
|
@@ -50,9 +53,9 @@ def create_onnx_model(_model, _tokenizer):
|
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
-
#create onnx & onnx_int_8 sessions
|
| 54 |
-
session = ort.InferenceSession("sent_clf_onnx/sentiment_classifier_onnx.onnx")
|
| 55 |
-
session_int8 = ort.InferenceSession("sent_clf_onnx/sentiment_classifier_onnx_int8.onnx")
|
| 56 |
|
| 57 |
# options=ort.SessionOptions()
|
| 58 |
# options.inter_op_num_threads=1
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
import os
|
| 10 |
|
| 11 |
+
# chkpt='distilbert-base-uncased-finetuned-sst-2-english'
|
| 12 |
+
# model= AutoModelForSequenceClassification.from_pretrained(chkpt)
|
| 13 |
+
# tokenizer= AutoTokenizer.from_pretrained(chkpt)
|
| 14 |
|
| 15 |
def create_onnx_model(_model, _tokenizer):
|
| 16 |
"""
|
|
|
|
| 24 |
|
| 25 |
"""
|
| 26 |
if not os.path.exists('sent_clf_onnx'):
|
| 27 |
+
try:
|
| 28 |
+
os.mkdir('sent_clf_onnx')
|
| 29 |
+
except:
|
| 30 |
+
pass
|
| 31 |
"""
|
| 32 |
Making ONNX model object
|
| 33 |
"""
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
+
# #create onnx & onnx_int_8 sessions
|
| 57 |
+
# session = ort.InferenceSession("sent_clf_onnx/sentiment_classifier_onnx.onnx")
|
| 58 |
+
# session_int8 = ort.InferenceSession("sent_clf_onnx/sentiment_classifier_onnx_int8.onnx")
|
| 59 |
|
| 60 |
# options=ort.SessionOptions()
|
| 61 |
# options.inter_op_num_threads=1
|
zeroshot_clf.py
CHANGED
|
@@ -5,11 +5,11 @@ from transformers import AutoModelForSequenceClassification,AutoTokenizer
|
|
| 5 |
import numpy as np
|
| 6 |
import plotly.express as px
|
| 7 |
|
| 8 |
-
chkpt='valhalla/distilbart-mnli-12-1'
|
| 9 |
-
model=AutoModelForSequenceClassification.from_pretrained(chkpt)
|
| 10 |
-
tokenizer=AutoTokenizer.from_pretrained('zero_shot_clf/')
|
| 11 |
|
| 12 |
-
def zero_shot_classification(premise: str, labels: str, model
|
| 13 |
try:
|
| 14 |
labels=labels.split(',')
|
| 15 |
labels=[l.lower() for l in labels]
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import plotly.express as px
|
| 7 |
|
| 8 |
+
# chkpt='valhalla/distilbart-mnli-12-1'
|
| 9 |
+
# model=AutoModelForSequenceClassification.from_pretrained(chkpt)
|
| 10 |
+
# tokenizer=AutoTokenizer.from_pretrained('zero_shot_clf/')
|
| 11 |
|
| 12 |
+
def zero_shot_classification(premise: str, labels: str, model, tokenizer):
|
| 13 |
try:
|
| 14 |
labels=labels.split(',')
|
| 15 |
labels=[l.lower() for l in labels]
|