多個資料來源的多數決
你的團隊正在開發一個用於自動產生智慧型手機品質管制(QC)報告的 AI 模型。為此,你從三個不同的品管來源蒐集了偏好資料——「Automated Vision System」、「Human Inspector」和「Customer Feedback」。他們各自將成對的文字樣本標示為『chosen』與『rejected』。每個配對都有唯一的 id,且每筆資料都呈現了偏好的 QC 評語。
quality_df 是使用 pandas 載入並合併後的 DataFrame,其中包含這三個不同資料來源的資料。此外,collections 模組中的 Counter 類別已經預先匯入。
本練習屬於課程
Reinforcement Learning from Human Feedback(RLHF)
練習說明
- 在 vote 函式中計算每個(chosen, rejected)配對的出現次數。
- 找出票數最高的(chosen, rejected)配對。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def majority_vote(df):
# Count occurrences of each (chosen, rejected) pair
votes = ____
# Find the (chosen, rejected) pair with the highest vote count
winner = ____
return winner
final_preferences = quality_df.groupby(['id']).apply(majority_vote)
print(final_preferences)