Spaces:
Sleeping
Sleeping
Update helper.py
Browse files
helper.py
CHANGED
@@ -6,6 +6,7 @@ import keras
|
|
6 |
import os
|
7 |
import warnings
|
8 |
import tempfile
|
|
|
9 |
import tensorflow as tf
|
10 |
from transformers import BertTokenizer, TFBertModel
|
11 |
from string import punctuation
|
@@ -31,7 +32,13 @@ stop_words = set(stopwords_df['stopword'].astype(str).tolist())
|
|
31 |
|
32 |
# Load tokenizer & model
|
33 |
tokenizer = BertTokenizer.from_pretrained("data")
|
34 |
-
bert_model =
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
lstm_model = keras.models.load_model(os.path.join(model_path, 'indobert_lstm_model.keras'))
|
36 |
|
37 |
# --- Preprocessing Functions ---
|
|
|
6 |
import os
|
7 |
import warnings
|
8 |
import tempfile
|
9 |
+
import torch
|
10 |
import tensorflow as tf
|
11 |
from transformers import BertTokenizer, TFBertModel
|
12 |
from string import punctuation
|
|
|
32 |
|
33 |
# Load tokenizer & model
|
34 |
tokenizer = BertTokenizer.from_pretrained("data")
|
35 |
+
bert_model = BertModel.from_pretrained("data")
|
36 |
+
|
37 |
+
# Di fungsi predict_emotion:
|
38 |
+
with torch.no_grad():
|
39 |
+
tokens = tokenizer(cleaned, return_tensors="pt", padding='max_length', truncation=True, max_length=MAX_LENGTH)
|
40 |
+
outputs = bert_model(**tokens)
|
41 |
+
embeddings = outputs.last_hidden_state.numpy().astype(np.float32)
|
42 |
lstm_model = keras.models.load_model(os.path.join(model_path, 'indobert_lstm_model.keras'))
|
43 |
|
44 |
# --- Preprocessing Functions ---
|