Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Tạo dataset chuỗi thô (raw strings) từ Illiad dataset với TensorFlow


TensorFlow (Google) framework học máy mã nguồn mở. Cài đặt: pip install tensorflow. Tensor: mảng đa chiều.

Sử dụng Illiad dataset: 3 bản dịch (Cowper, Derby, Butler). Phân loại người dịch từ 1 dòng văn bản. Đã tiền xử lý.

Chạy trên Google Colab (Python trên trình duyệt, GPU miễn phí).

Ví dụ

print("Tạo test dataset từ raw strings")
test_ds = all_labeled_data.take(VALIDATION_SIZE).batch(BATCH_SIZE)
test_ds = configure_dataset(test_ds)

loss, accuracy = export_model.evaluate(test_ds)
print("Loss:", loss)
print("Accuracy: {:2.2%}".format(accuracy))

Nguồn mã: TensorFlow Text Loading Tutorial

Đầu ra

Tạo test dataset từ raw strings
79/79 [==============================] - 7s 10ms/step - loss: 0.5230 - accuracy: 0.7909
Loss: 0.5458346605300903
Accuracy: 78.16%

Giải thích

  • Xây dựng test dataset: lấy VALIDATION_SIZE mẫu, batch size BATCH_SIZE.
  • Cấu hình dataset qua configure_dataset().
  • Đánh giá bằng evaluate() → loss và accuracy.
  • Kết quả: loss ~0.55, accuracy ~78%.