File size: 1,097 Bytes
c8070aa
 
2fc8ad9
 
c8070aa
2fc8ad9
 
 
83eec8f
3ad0ab9
 
 
 
d7676a5
b7a1a0d
0ed8f63
 
b7a1a0d
ae17a67
0c87eb4
0ed8f63
 
 
 
58b2e8b
 
0ed8f63
 
3ad0ab9
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
27
28
29
30
31
32
33
34
35
36
37
import subprocess
import sys

def install(package):
    subprocess.check_call([sys.executable, "-m", "pip", "install", package])

install("tensorflow")
install("numpy")
install("transformers")

import transformers
from transformers import DistilBertTokenizer
from transformers import TFDistilBertForSequenceClassification

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), np.ones(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)