Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,22 @@ from tqdm import tqdm
|
|
| 10 |
import os
|
| 11 |
from tensorflow.python.client import device_lib
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def sentence_convert_data(data):
|
| 16 |
global tokenizer
|
|
@@ -42,3 +57,6 @@ def movie_evaluation_predict(sentence):
|
|
| 42 |
st.write("(๋ถ์ ํ๋ฅ : %.2f) ๋ถ์ ์ ์ธ ์ํ ํ๊ฐ์
๋๋ค." % (1.0-predict_value))
|
| 43 |
elif predict_answer == 1:
|
| 44 |
st.write("(๊ธ์ ํ๋ฅ : %.2f) ๊ธ์ ์ ์ธ ์ํ ํ๊ฐ์
๋๋ค." % predict_value)
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
import os
|
| 11 |
from tensorflow.python.client import device_lib
|
| 12 |
|
| 13 |
+
def create_sentiment_bert():
|
| 14 |
+
# ๋ฒํธ pretrained ๋ชจ๋ธ ๋ก๋
|
| 15 |
+
model = TFBertModel.from_pretrained('bert-base-multilingual-cased')
|
| 16 |
+
# ํ ํฐ ์ธํ, ๋ง์คํฌ ์ธํ, ์ธ๊ทธ๋จผํธ ์ธํ ์ ์
|
| 17 |
+
token_inputs = tf.keras.layers.Input((SEQ_LEN,), dtype=tf.int32, name='input_word_ids')
|
| 18 |
+
mask_inputs = tf.keras.layers.Input((SEQ_LEN,), dtype=tf.int32, name='input_masks')
|
| 19 |
+
segment_inputs = tf.keras.layers.Input((SEQ_LEN,), dtype=tf.int32, name='input_segment')
|
| 20 |
+
# ์ธํ์ด [ํ ํฐ, ๋ง์คํฌ, ์ธ๊ทธ๋จผํธ]์ธ ๋ชจ๋ธ ์ ์
|
| 21 |
+
bert_outputs = model([token_inputs, mask_inputs, segment_inputs])
|
| 22 |
+
|
| 23 |
+
bert_outputs = bert_outputs[1]
|
| 24 |
+
sentiment_first = tf.keras.layers.Dense(1, activation='sigmoid', kernel_initializer=tf.keras.initializers.TruncatedNormal(stddev=0.02))(bert_outputs)
|
| 25 |
+
sentiment_model = tf.keras.Model([token_inputs, mask_inputs, segment_inputs], sentiment_first)
|
| 26 |
+
|
| 27 |
+
sentiment_model.compile(loss=tf.keras.losses.BinaryCrossentropy(), metrics = ['accuracy'])
|
| 28 |
+
return sentiment_model
|
| 29 |
|
| 30 |
def sentence_convert_data(data):
|
| 31 |
global tokenizer
|
|
|
|
| 57 |
st.write("(๋ถ์ ํ๋ฅ : %.2f) ๋ถ์ ์ ์ธ ์ํ ํ๊ฐ์
๋๋ค." % (1.0-predict_value))
|
| 58 |
elif predict_answer == 1:
|
| 59 |
st.write("(๊ธ์ ํ๋ฅ : %.2f) ๊ธ์ ์ ์ธ ์ํ ํ๊ฐ์
๋๋ค." % predict_value)
|
| 60 |
+
|
| 61 |
+
sentiment_model = create_sentiment_bert()
|
| 62 |
+
movie_evaluation_predict("๋ณด๋๊ฑฐ๋ผ ๊ณ์๋ณด๊ณ ์๋๋ฐ ์ ๊ฐ๋ ๋๋ฆฌ๊ณ ์ฃผ์ธ๊ณต์ธ ์ํฌ๋ ํ๋์ปท ๋์ค๋ฉด์ ์๊ทน์ ์ธ๋ชจ์ต์ ")
|