การสร้าง 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 = ____