duwing commited on
Commit
879bc79
ยท
verified ยท
1 Parent(s): 2ec5280

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -10,7 +10,22 @@ from tqdm import tqdm
10
  import os
11
  from tensorflow.python.client import device_lib
12
 
13
- model = TFBertModel.from_pretrained('bert-base-multilingual-cased')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("๋ณด๋˜๊ฑฐ๋ผ ๊ณ„์†๋ณด๊ณ ์žˆ๋Š”๋ฐ ์ „๊ฐœ๋„ ๋А๋ฆฌ๊ณ  ์ฃผ์ธ๊ณต์ธ ์€ํฌ๋Š” ํ•œ๋‘์ปท ๋‚˜์˜ค๋ฉด์„œ ์†Œ๊ทน์ ์ธ๋ชจ์Šต์— ")