Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การใช้ TensorFlow กับ Iliad Dataset: ทดสอบโมเดลกับข้อมูลใหม่


บทนำ

TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python ใช้ในงานวิจัยและการผลิต มีเทคนิคเพิ่มประสิทธิภาพ ใช้ NumPy และเทนเซอร์ รองรับ Deep Neural Networks สเกลได้ดี ใช้ GPU computation จัดการทรัพยากรอัตโนมัติ มีไลบรารี ML มากมาย เอกสารดี

Tensor

เทนเซอร์ = อาร์เรย์หลายมิติ สำหรับ Data flow graph

ชุดข้อมูล Iliad

ข้อความจาก 3 งานแปลของ William Cowper, Edward (Earl of Derby), Samuel Butler โมเดลฝึกระบุผู้แปลจากบรรทัดเดียว ข้อความผ่าน preprocessing: ลบ header/footer, หมายเลขบรรทัด, ชื่อบท

ตัวอย่าง: ทดสอบโมเดลกับข้อความใหม่

print("ทดสอบโมเดลกับข้อมูลใหม่")
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("เรียกใช้เมธอด predict")
predicted_scores = export_model.predict(inputs)
predicted_labels = tf.argmax(predicted_scores, axis=1)

for input, label in zip(inputs, predicted_labels):
    print("คำถาม:", input)
    print("ป้ายกำกับที่ทำนาย:", label.numpy())

ที่มา: TensorFlow Text Loading Tutorial

ผลลัพธ์

ทดสอบโมเดลกับข้อมูลใหม่
เรียกใช้เมธอด predict
คำถาม: the allies, and his armour flashed about him so that he seemed to all
ป้ายกำกับที่ทำนาย: 2
คำถาม: And with loud clangor of his arms he fell.
ป้ายกำกับที่ทำนาย: 0
คำถาม: Join'd to th' Ionians with their flowing robes,
ป้ายกำกับที่ทำนาย: 1

คำอธิบาย

  • หลังคอมไพล์และฝึกข้อมูลแล้ว ทดสอบกับข้อมูลที่ไม่เคยเห็น
  • เรียกเมธอด predict บนข้อมูลทดสอบ
  • แสดงตัวอย่างคำถามและป้ายกำกับที่ทำนายได้