So sánh hiệu suất giữa hai cách vector hóa văn bản: binary (one-hot/multi-hot) và int (token index sequence) trên cùng một bài toán phân loại StackOverflow.
Mã đánh giá
print("Đánh giá mô hình")
binary_loss, binary_accuracy = binary_model.evaluate(binary_test_ds)
int_loss, int_accuracy = int_model.evaluate(int_test_ds)
print("Độ chính xác Binary model: {:2.2%}".format(binary_accuracy))
print("Độ chính xác Int model: {:2.2%}".format(int_accuracy))
Kết quả
Đánh giá mô hình 250/250 [==============================] - 3s 12ms/step - loss: 0.5265 - accuracy: 0.8110 250/250 [==============================] - 4s 14ms/step - loss: 0.5394 - accuracy: 0.8014 Độ chính xác Binary model: 81.10% Độ chính xác Int model: 80.14%
Giải thích
- Binary vectorization: Mỗi từ → 1 chiều, giá trị 0/1 (có/không). Mô hình Linear (Dense) đạt 81.10%.
- Int vectorization: Mỗi từ → index số nguyên, giữ thứ tự. Mô hình Conv1D đạt 80.14%.
- Binary + Linear model nhẹ hơn, nhanh hơn, accuracy tương đương.
- Int + Conv1D phức tạp hơn (embedding + conv), tiềm năng tốt hơn trên dữ liệu lớn/phức tạp hơn.