isan2001 commited on
Commit
b38636e
1 Parent(s): 35a0d9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -15,8 +15,9 @@ def predict_sentiment(text):
15
  input_ids = tf.constant(bert_tokenizer.encode(text, add_special_tokens=True))[None, :] # Menambahkan token khusus [CLS] dan [SEP]
16
  logits = bert_model(input_ids)[0]
17
  probabilities = tf.nn.softmax(logits, axis=1)
18
- sentiment_score, sentiment_label = probabilities.numpy()[0]
19
- return sentiment_score, sentiment_label
 
20
 
21
  # Judul aplikasi
22
  st.title('Prediksi Sentimen menggunakan BERT')
@@ -29,8 +30,8 @@ if st.button('Prediksi'):
29
  if text.strip() == '':
30
  st.warning('Masukkan teks terlebih dahulu.')
31
  else:
32
- sentiment_score, sentiment_label = predict_sentiment(text)
33
- if sentiment_label == 0:
34
- st.error(f'Sentimen: Negatif, Skor: {sentiment_score:.2f}')
35
  else:
36
- st.success(f'Sentimen: Positif, Skor: {sentiment_score:.2f}')
 
15
  input_ids = tf.constant(bert_tokenizer.encode(text, add_special_tokens=True))[None, :] # Menambahkan token khusus [CLS] dan [SEP]
16
  logits = bert_model(input_ids)[0]
17
  probabilities = tf.nn.softmax(logits, axis=1)
18
+ sentiment = tf.argmax(probabilities, axis=1)
19
+ return sentiment.numpy()[0]
20
+
21
 
22
  # Judul aplikasi
23
  st.title('Prediksi Sentimen menggunakan BERT')
 
30
  if text.strip() == '':
31
  st.warning('Masukkan teks terlebih dahulu.')
32
  else:
33
+ sentiment = predict_sentiment(text)
34
+ if sentiment == 0:
35
+ st.error('Sentimen: Negatif')
36
  else:
37
+ st.success('Sentimen: Positif')