File size: 725 Bytes
284ba3b
 
e5833e5
284ba3b
 
 
 
 
 
 
 
 
 
 
 
e5833e5
284ba3b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import torch
from transformers import AutoTokenizer, AutoModel
from model.bilstm_model import BiLSTMSentiment
from config import DEVICE, MODEL_PATH, HIDDEN_SIZE, NUM_CLASSES

# โหลด tokenizer และ BERT
tokenizer = AutoTokenizer.from_pretrained(
    "airesearch/wangchanberta-base-att-spm-uncased",
    use_fast=False,
    trust_remote_code=True
)
bert_model = AutoModel.from_pretrained("airesearch/wangchanberta-base-att-spm-uncased").to(DEVICE)

# สร้าง model
INPUT_SIZE = bert_model.config.hidden_size + 1  # BERT + sentiment score
model_lstm = BiLSTMSentiment(INPUT_SIZE, HIDDEN_SIZE, NUM_CLASSES).to(DEVICE)
model_lstm.load_state_dict(torch.load(MODEL_PATH, map_location=DEVICE))
model_lstm.eval()