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

วิธีใช้ TensorFlow ทดสอบประสิทธิภาพโมเดลกับชุดข้อมูล Stack Overflow Questions ด้วย Python


TensorFlow เฟรมเวิร์ก ML จาก Google Open Source ใช้กับ Python อัลกอริทึม Deep Learning งานวิจัยและ Production

ติดตั้ง tensorflow บน Windows:

pip install tensorflow

Tensor โครงสร้างข้อมูลใน TensorFlow (Data Flow Graph) เป็นอาร์เรย์หลายมิติ/ลิสต์

ใช้ Google Colab รันโค้ด (Python บนเบราว์เซอร์ ฟรี GPU บน Jupyter Notebook)

ตัวอย่างโค้ด

print("Testing the model with new data")
inputs = [
    "how do I extract keys from a dict into a list?",
    "debug public static void main(string[] args) {...}",
]
print("Predicting the scores ")
predicted_scores = export_model.predict(inputs)
print("Predicting the labels")
predicted_labels = get_string_labels(predicted_scores)
for input, label in zip(inputs, predicted_labels):
    print("Question is: ", input)
    print("The predicted label is : ", label.numpy())

Credit: TensorFlow Tutorials

ผลลัพธ์

Testing the model with new data
Predicting the scores
Predicting the labels
Question is: how do I extract keys from a dict into a list?
The predicted label is : b'python'
Question is: debug public static void main(string[] args) {...}
The predicted label is : b'java'

คำอธิบาย

  • เมื่อโค้ด Preprocessing อยู่ภายในโมเดล ช่วย Export โมเดลสำหรับ Production ได้ง่ายขึ้น

  • ลดความซับซ้อนในการ Deploy

  • ถ้า TextVectorization อยู่นอกโมเดล ช่วย Async CPU Processing และ Buffering ได้