เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การสร้าง Embedding สำหรับรีวิวร้านอาหาร

งานจำแนกประเภทที่ embedding ทำได้ดีอย่างหนึ่งคือการวิเคราะห์ความรู้สึก (sentiment analysis) ในแบบฝึกหัดนี้และแบบฝึกหัดถัดไป จะได้เรียนรู้ขั้นตอนการทำ sentiment analysis โดยใช้ embedding

มีชุดข้อมูลรีวิวร้านอาหารขนาดเล็กให้แล้ว เก็บอยู่ใน reviews และป้ายกำกับความรู้สึกเก็บอยู่ใน sentiments:

sentiments = [{'label': 'Positive'},
              {'label': 'Neutral'},
              {'label': 'Negative'}]

reviews = ["The food was delicious!",
           "The service was a bit slow but the food was good",
           "The food was cold, really disappointing!"]

จะใช้ zero-shot classification เพื่อจำแนกความรู้สึกของรีวิวเหล่านี้ โดยการสร้าง embedding จากรีวิวและป้ายกำกับของแต่ละคลาส

ฟังก์ชัน create_embeddings() ที่สร้างไว้ก่อนหน้านี้พร้อมใช้งานแล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การสร้าง Embeddings ด้วย OpenAI API

ดูคอร์ส

คำแนะนำการฝึกหัด

  • สร้าง list ของ class descriptions จากป้ายกำกับใน dictionary sentiments โดยใช้ list comprehension
  • สร้าง embedding จาก class_descriptions และ reviews โดยใช้ฟังก์ชัน create_embeddings()

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Create a list of class descriptions from the sentiment labels
class_descriptions = ____

# Embed the class_descriptions and reviews
class_embeddings = ____
review_embeddings = ____
แก้ไขและรันโค้ด