Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import torch.nn as nn
|
|
3 |
from transformers import AutoTokenizer, AutoModel
|
4 |
import gradio as gr
|
5 |
|
6 |
-
# Model multitask
|
7 |
class MultiTaskModel(nn.Module):
|
8 |
def __init__(self, base_model_name, num_topic_classes, num_sentiment_classes):
|
9 |
super(MultiTaskModel, self).__init__()
|
@@ -13,17 +13,15 @@ class MultiTaskModel(nn.Module):
|
|
13 |
self.sentiment_classifier = nn.Linear(hidden_size, num_sentiment_classes)
|
14 |
|
15 |
def forward(self, input_ids, attention_mask, token_type_ids=None):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
# Load tokenizer & model
|
29 |
tokenizer = AutoTokenizer.from_pretrained("tokenizer")
|
@@ -32,7 +30,7 @@ model.load_state_dict(torch.load("model.pt", map_location=torch.device("cpu")))
|
|
32 |
model.eval()
|
33 |
|
34 |
# Label mapping
|
35 |
-
topik_labels = ["Produk", "Layanan", "Pengiriman", "Lainnya"]
|
36 |
sentimen_labels = ["Negatif", "Netral", "Positif"]
|
37 |
|
38 |
def klasifikasi(text):
|
|
|
3 |
from transformers import AutoTokenizer, AutoModel
|
4 |
import gradio as gr
|
5 |
|
6 |
+
# Model multitask dengan token_type_ids support
|
7 |
class MultiTaskModel(nn.Module):
|
8 |
def __init__(self, base_model_name, num_topic_classes, num_sentiment_classes):
|
9 |
super(MultiTaskModel, self).__init__()
|
|
|
13 |
self.sentiment_classifier = nn.Linear(hidden_size, num_sentiment_classes)
|
14 |
|
15 |
def forward(self, input_ids, attention_mask, token_type_ids=None):
|
16 |
+
outputs = self.encoder(
|
17 |
+
input_ids=input_ids,
|
18 |
+
attention_mask=attention_mask,
|
19 |
+
token_type_ids=token_type_ids
|
20 |
+
)
|
21 |
+
pooled_output = outputs.last_hidden_state[:, 0]
|
22 |
+
topik_logits = self.topik_classifier(pooled_output)
|
23 |
+
sentimen_logits = self.sentiment_classifier(pooled_output)
|
24 |
+
return topik_logits, sentimen_logits
|
|
|
|
|
25 |
|
26 |
# Load tokenizer & model
|
27 |
tokenizer = AutoTokenizer.from_pretrained("tokenizer")
|
|
|
30 |
model.eval()
|
31 |
|
32 |
# Label mapping
|
33 |
+
topik_labels = ["Produk", "Layanan", "Pengiriman", "Pembatalan", "Lainnya"]
|
34 |
sentimen_labels = ["Negatif", "Netral", "Positif"]
|
35 |
|
36 |
def klasifikasi(text):
|