答案擷取

Snowflake 生成式 AI 入門

James Cha-Earley

Senior Developer Advocate, Snowflake

為什麼要用答案擷取?

$$

  • 辨識抱怨
  • 擷取設施相關回饋
  • 從長文件回答問題

一份文件配上問號,周圍有開心與難過表情符號,表示我們不知道每則評論在說什麼

Snowflake 生成式 AI 入門

常見商務問題

review = """
The property needs updating and management needs to hire more staff. 
The staff does everything they can but it is not enough for the number of guests. 
The rooms look old as well as everything in the bathrooms. 
Definitely better options in the hotel zone.
"""
  • Snowflake Cortex 前來支援!
Snowflake 生成式 AI 入門

擷取答案

from snowflake.cortex import extract_answer

response = extract_answer( from_text=review, question="What did the guest complain about?" )
Snowflake 生成式 AI 入門

輸出

print(response)
[
    {
    "answer": "Management needs to hire more staff.",
    "score": 0.8013839254
    }
]
  • 分數介於 0 到 1
Snowflake 生成式 AI 入門

建立工作流程

SELECT DESCRIPTION
FROM HOTELS.REVIEWS
WHERE RATING < 6
    AND DATE = '2023-08-23';
Snowflake 生成式 AI 入門

SQL 輸出

I will never book a vacation through Expedia not only did I pay over 5;000 dollars
but they false advertise the resort; in my reservation It clearly stated that
breakfast and dinner was included. When I got to the resort they informed me that 
these issues have happed before with Expedia because the resort does not offer an
all exclusive. After flighting practically all day I called Expedia and they had me
on hold for 45min and nothing got resolved. I ended up spending over 1000.00 more
just on food. I am beyond me they are not only false advertising but refused to
take any responsibility on their part for the issues they caused me and my family.  Again I will never chose Expedia to plan a vacation!!!
Snowflake 生成式 AI 入門

提出問題

negative_review = dataframe_1.to_pandas()['DESCRIPTION'].iloc[0]

response = extract_answer( from_text=negative_review, question="What was the primary issue that the guest mentioned?" ) print(response)
Snowflake 生成式 AI 入門

檢視回應

[
    {
    "answer" : "Expedia falsely advertised that meals were included, but the
                resort did not offer an all-inclusive package.",
    "score": 0.75829312442
    }
]
Snowflake 生成式 AI 入門

限制

$$

  • 可能回傳片段或含糊的語句
  • 適合段落,不適合多主題文件
  • 重要輸出務必審查

警示標誌

Snowflake 生成式 AI 入門

一起來練習吧!

Snowflake 生成式 AI 入門

Preparing Video For Download...