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

วิธีใช้ TensorFlow ทำนาย Score สำหรับทุก Label ของชุดข้อมูล Stack Overflow Questions ด้วย Python


TensorFlow เฟรมเวิร์ก ML จาก Google Open Source ใช้กับ Python อัลกอริทึม Deep Learning งานวิจัยและ Production มีเทคนิคเพิ่มประสิทธิภาพคำนวณ ใช้ NumPy และ Multi-dimensional Arrays (Tensors) รองรับ Deep Neural Network

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

pip install tensorflow

Tensor โครงสร้างข้อมูลใน TensorFlow (Data Flow Graph) เป็นอาร์เรย์หลายมิติ/ลิสต์ มี 3 แอตทริบิวต์: Rank, Type, Shape

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

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

print("Predicting a score for every label")
def get_string_labels(predicted_scores_batch):
    predicted_int_labels = tf.argmax(predicted_scores_batch, axis=1)
    predicted_labels = tf.gather(raw_train_ds.class_names, predicted_int_labels)
    return predicted_labels

Credit: TensorFlow Tutorials

ผลลัพธ์

Predicting a score for every label

คำอธิบาย

  • เรียกเมธอด predict บนโมเดลที่สร้างขึ้น

  • รับ Raw String เป็น Input และทำนาย Score สำหรับทุก Label

  • ฟังก์ชันหา Label ที่มี Score สูงสุด

  • แสดงผลบน Console