File size: 809 Bytes
d7676a5
 
 
b7a1a0d
0ed8f63
 
b7a1a0d
ae17a67
0c87eb4
0ed8f63
 
 
 
58b2e8b
 
0ed8f63
 
94e8426
0ed8f63
 
 
 
 
 
 
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
!pip install tensorflow
!pip install numpy

import streamlit as st
import numpy as np
import tensorflow as tf

x = st.header("Welcome to the STEM NLP application!")

model = TFDistilBertForSequenceClassification.from_pretrained("kaixinwang/NLP")

MODEL_NAME_1 = 'distilbert-base-uncased'
tokenizer = DistilBertTokenizer.from_pretrained(MODEL_NAME_1)

x = st.text_input("Type in your review here:")
st.write("Your review is:", x)
encoding = tokenizer(x, truncation=True, padding=True)
encoded = tf.data.Dataset.from_tensor_slices((dict(encoding), 1))
preds = model.predict(encoded.batch(1)).logits  
prob = tf.nn.softmax(preds, axis=1).numpy()  
prob_max = np.argmax(prob, axis=1)
st.write("Sentiment:", prob_max, "Score:", prob[prob_max])

# x = st.slider('Select a value')
# st.write(x, 'squared is', x * x)