TensorFlow (Google) framework học máy mã nguồn mở, tối ưu NumPy/tensor, scalable, GPU, nhiều thư viện.
Tensor: mảng đa chiều trong đồ thị luồng dữ liệu.
Sử dụng Illiad dataset: văn bản 3 bản dịch của William Cowper, Edward (Earl of Derby), Samuel Butler. Mô hình phân loại người dịch từ 1 dòng văn bản. Dữ liệu đã tiền xử lý: xóa header/footer, số dòng, tiêu đề chương.
Chạy trên Google Colab (Python trên trình duyệt, GPU miễn phí).
Ví dụ
print("Test mô hình trên dữ liệu mới")
inputs = [
"the allies, and his armour flashed about him so that he seemed to all",
"And with loud clangor of his arms he fell.",
"Join'd to th' Ionians with their flowing robes,",
]
print("Gọi predict()")
predicted_scores = export_model.predict(inputs)
predicted_labels = tf.argmax(predicted_scores, axis=1)
for input, label in zip(inputs, predicted_labels):
print("Câu hỏi:", input)
print("Nhãn dự đoán:", label.numpy())
Nguồn mã: TensorFlow Text Loading Tutorial
Đầu ra
Test mô hình trên dữ liệu mới Gọi predict() Câu hỏi: the allies, and his armour flashed about him so that he seemed to all Nhãn dự đoán: 2 Câu hỏi: And with loud clangor of his arms he fell. Nhãn dự đoán: 0 Câu hỏi: Join'd to th' Ionians with their flowing robes, Nhãn dự đoán: 1
Giải thích
- Sau compile và fit train data, test trên dữ liệu chưa thấy.
- Gọi
predict()trên test data. - Hiển thị mẫu câu hỏi và nhãn dự đoán tương ứng (0, 1, 2 cho 3 người dịch).