การวิเคราะห์ข้อความ

Prompt Engineering กับ OpenAI API

Fouad Trad

Machine Learning Engineer

การวิเคราะห์ข้อความ

  • การตรวจสอบข้อความเพื่อดึงข้อมูล
    • การจำแนกประเภทข้อความ
    • การดึงข้อมูลเอนทิตี
  • บริษัทควรขอคำปรึกษาด้านกฎหมายเมื่อใช้ข้อมูลลูกค้า

ภาพแสดงการวิเคราะห์ข้อความที่ดึงข้อมูล เช่น ความรู้สึก อารมณ์ น้ำเสียง เอนทิตี ฯลฯ จากข้อความที่กำหนด

Prompt Engineering กับ OpenAI API

การจำแนกประเภทข้อความ

  • กำหนดหมวดหมู่ให้กับข้อความ
  • ตัวอย่าง: การวิเคราะห์ความรู้สึก

ภาพแสดงประเภทของการวิเคราะห์ความรู้สึก ได้แก่ บวก ลบ หรือเป็นกลาง

Prompt Engineering กับ OpenAI API

หมวดหมู่ที่กำหนดไว้

  • ระบุหมวดหมู่การจำแนกเมื่อทราบแล้ว
  • ระบุข้อกำหนดของผลลัพธ์
text = "I bought your XYZ Smart Watch and wanted to share my positive experience. 
Impressed with its sleek design, comfort, and touchscreen usability."

prompt = f"""Classify the sentiment of the text delimited by triple backticks as positive, negative, or neutral. Give your answer as a single word: ```{text}```""" print(get_response(prompt))
positive
Prompt Engineering กับ OpenAI API

หมวดหมู่ที่ไม่ได้ระบุ

  • โมเดลใช้ความรู้ของตัวเองเมื่อไม่ได้ระบุหมวดหมู่
text = "I bought your XYZ Smart Watch and wanted to share my positive experience. 
Impressed with its sleek design, comfort, and touchscreen usability."

prompt = f"""Classify the sentiment of the text delimited by triple backticks. 
             Give your answer as a single word.
           ```{text}```"""
print(get_response(response))
positive.
  • สำหรับปัญหาที่เปิดกว้าง วิธีนี้อาจไม่ได้ผลดีเสมอไป
Prompt Engineering กับ OpenAI API

หลายหมวดหมู่

  • ข้อความสามารถอยู่ในหลายหมวดหมู่ได้
  • กำหนดจำนวนสูงสุดของหมวดหมู่หากยังไม่ทราบ
text = "I bought your XYZ Smart Watch and wanted to share my positive experience. 
Impressed with its sleek design, comfort, and touchscreen usability."

prompt = f"""Identify emotions used in this text. Don't use more than 3 emotions. Format your answer as a list of words separated by commas: ```{text}```""" print(get_response(prompt))
impressed, positive, comfortable
Prompt Engineering กับ OpenAI API

การดึงข้อมูลเอนทิตี

  • การดึงเอนทิตีเฉพาะจากข้อความ
  • ตัวอย่าง: ชื่อบุคคล สถานที่ องค์กร วันที่

ไอคอนแสดงการดึงเอนทิตีเฉพาะออกจากข้อความที่กำหนด

Prompt Engineering กับ OpenAI API

การดึงเอนทิตี: ระบุเอนทิตี

  • ระบุเอนทิตีที่ต้องการดึง
  • ระบุรูปแบบผลลัพธ์
text = "The XYZ Mobile X200: a sleek 6.5-inch Super AMOLED smartphone with a 48MP 
triple-camera, octa-core processor, 5000mAh battery, 5G connectivity, and Android 
11 OS. Secure with fingerprint and facial recognition. 128GB storage, expandable up 
to 512GB."

prompt = f"""Identify the following entities from the text delimited by triple backticks: - Product Name ```{text}```""" print(get_response(prompt))
Prompt Engineering กับ OpenAI API

การดึงเอนทิตี: ระบุเอนทิตี

  • ระบุเอนทิตีที่ต้องการดึง
  • ระบุรูปแบบผลลัพธ์
text = "The XYZ Mobile X200: a sleek 6.5-inch Super AMOLED smartphone with a 48MP 
triple-camera, octa-core processor, 5000mAh battery, 5G connectivity, and Android 
11 OS. Secure with fingerprint and facial recognition. 128GB storage, expandable up 
to 512GB."

prompt = f"""Identify the following entities from the text delimited by triple backticks: - Product Name - Display Size ```{text}```""" print(get_response(prompt))
Prompt Engineering กับ OpenAI API

การดึงเอนทิตี: ระบุเอนทิตี

  • ระบุเอนทิตีที่ต้องการดึง
  • ระบุรูปแบบผลลัพธ์
text = "The XYZ Mobile X200: a sleek 6.5-inch Super AMOLED smartphone with a 48MP 
triple-camera, octa-core processor, 5000mAh battery, 5G connectivity, and Android 
11 OS. Secure with fingerprint and facial recognition. 128GB storage, expandable up 
to 512GB."

prompt = f"""Identify the following entities from the text delimited by triple backticks: - Product Name - Display Size - Camera Resolution ```{text}```""" print(get_response(prompt))
Prompt Engineering กับ OpenAI API

การดึงเอนทิตี: ระบุเอนทิตี

  • ระบุเอนทิตีที่ต้องการดึง
  • ระบุรูปแบบผลลัพธ์
text = "The XYZ Mobile X200: a sleek 6.5-inch Super AMOLED smartphone with a 48MP 
triple-camera, octa-core processor, 5000mAh battery, 5G connectivity, and Android 
11 OS. Secure with fingerprint and facial recognition. 128GB storage, expandable up 
to 512GB."

prompt = f"""Identify the following entities from the text delimited by triple backticks: - Product Name - Display Size - Camera Resolution Format the answer as an unordered list. ```{text}```""" print(get_response(prompt))
Prompt Engineering กับ OpenAI API

การดึงเอนทิตี: ระบุเอนทิตี

Product Name: XYZ Mobile X200
Display Size: 6.5-inch
Camera Resolution: 48MP triple-camera
Prompt Engineering กับ OpenAI API

การดึงเอนทิตีด้วย few-shot prompts

  • สำหรับโครงสร้างที่ซับซ้อน
ticket_1 = "Hello, I'm Emma Adams. I'd 
like to ask about my reservation with 
the code CAR123. 
You can reach me at +123456 if needed."

ticket_2 = "This is Sarah Williams. 
I would like to request some information
regarding my upcoming flight with 
reservation code FLIGHT987. Thank you."
entities_1 = """
* Customer Details:
  - Name: Emma Adams
  - Phone: +123456
* Reservation Details:
  - Reservation Code: CAR123"""
entities_2 = """
* Customer Details:
  - Name: Sarah Williams
* Reservation Details:
  - Reservation Code: FLIGHT987"""
Prompt Engineering กับ OpenAI API

การดึงเอนทิตีด้วย few-shot prompts

ticket_3 = "Hello, I'm David Brown (CUST123). I need assistance with my reservation under 
the code HOTEL456. There are some questions and issues related to my upcoming stay that 
require your attention."

prompt = f"""Text: {ticket_1} -> Entities: {entities_1} Text: {ticket_2} -> Entities: {entities_2} Text: {ticket_3} -> Entities: """ print(get_response(prompt))
* Customer Details:
  - Name: David Brown
  - Customer ID: CUST123
* Reservation Details:
  - Reservation Code: HOTEL456
Prompt Engineering กับ OpenAI API

มาฝึกกันเถอะ!

Prompt Engineering กับ OpenAI API

Preparing Video For Download...