-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (29 loc) · 2.02 KB
/
Copy pathapp.py
File metadata and controls
41 lines (29 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import streamlit as st
st.set_page_config(page_title="Yeah Right! | Sarcasm Classifier", page_icon="📜")
st.sidebar.image("logo.png")
st.sidebar.info("This is a Natural Language Processing project maintained by **DecafSunrise**. Feel free to take a peek at the [**source code**](https://github.com/DecafSunrise/Yeah-Right), or check out the rest of my [**awesome projects on GitHub**](https://github.com/DecafSunrise/)")
from lime.lime_text import LimeTextExplainer
from sklearn.pipeline import make_pipeline
from joblib import load
vectorizer = load('././models/sarcasm_vectorizer.joblib')
lr_clf = load("././models/logreg_clf.pkl")
rf_clf = load("././models/rf_clf.pkl")
lr_pipe = make_pipeline(vectorizer, lr_clf)
rf_pipe = make_pipeline(vectorizer, rf_clf)
explainer = LimeTextExplainer(class_names=["sarcastic", "not-sarcastic"])
st.title('"Yeah-Right": Sarcasm Classifier')
st.markdown("**_Classifiers_** are type of machine learning model that determines which category an input should belong to: '__Hot Dog__' or '__Not Hot Dog__'.<br/><br/>"
"**Want to try it yourself?** Type some text below, and play with the provided models!", unsafe_allow_html=True)
inst_text = st.text_input(label="What text do you want to classify?", placeholder="Your super sarcastic text here")
if inst_text:
st.write("**Input:**", inst_text)
exp = explainer.explain_instance(inst_text, lr_pipe.predict_proba)
st.write(' LogisticRegression Probability(Sarcastic) =', round(lr_pipe.predict_proba([inst_text])[0, 1],3))
st.write(' RandomForest Probability(Sarcastic) =', round(lr_pipe.predict_proba([inst_text])[0, 1],3))
st.write("(Prediction probability below 0.5 would mean 'Not Sarcastic')")
st.header('Logistic Regression:')
lr_explanation = explainer.explain_instance(inst_text, lr_pipe.predict_proba)
st.pyplot(fig=lr_explanation.as_pyplot_figure())
st.header('Random Forest:')
rf_explanation = explainer.explain_instance(inst_text, rf_pipe.predict_proba)
st.pyplot(fig=rf_explanation.as_pyplot_figure())