Content text [SGU] [NLP] Project (2025-2026_HK1).docx
Hidden size 512 Embedding dim 256–512 Số layer LSTM 2 Dropout 0.3–0.5 Teacher forcing ratio 0.5 6.3. Huấn luyện mô hình Thành phần Cấu hình Loss nn.CrossEntropyLoss(ignore_index=pad_idx) Optimizer Adam(lr=0.001) Epoch 10–20 Early stopping Dừng nếu val_loss không giảm sau 3 epoch Scheduler ReduceLROnPlateau (tùy chọn) Theo dõi Train/val loss, lưu best model Teacher Forcing if random.random() < 0.5: decoder_input = target[:, t] # Ground truth else: decoder_input = predicted_token # Dự đoán 6.4. Dự đoán (Inference) Greedy decoding: Chọn token có xác suất cao nhất. Dừng khi gặp <eos> hoặc đạt độ dài tối đa 50. Yêu cầu bắt buộc: Viết hàm translate(sentence: str) -> str nhận câu tiếng Anh, trả về câu tiếng Pháp. def translate(sentence): # Tokenize → tensor → encoder → decoder → detokenize # Codes return translated_french_sentence 6.5. Đánh giá Chỉ số Cách tính BLEU score nltk.translate.bleu_score.sentence_bleu (trên tập test)