Đo lường chất lượng và mức độ liên quan của phản hồi

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Ứng dụng phát hiện phản hồi bất thường

Ví dụ:

  • Đánh giá tích cực:
    • "Tôi rất thích sản phẩm này!"
  • Đánh giá tiêu cực:
    • "Dịch vụ tệ."
  • Đánh giá trung lập:
    • "Làm đúng như mong đợi."
  • Đánh giá ngoại lệ:
    • "Bầu trời có màu xanh."

Xếp hạng bốn trên năm sao với một bàn tay thêm ngôi sao thứ năm

Reinforcement Learning from Human Feedback (RLHF)

Phát hiện phản hồi bất thường

import numpy as np
def least_confidence(prob_dist):
    simple_least_conf = np.nanmax(prob_dist) 
    num_labels = float(prob_dist.size)  # number of labels
    least_conf = (1 - simple_least_conf) * (num_labels / (num_labels - 1))
    return least_conf
def filter_low_confidence_predictions(prob_dists, threshold=0.5):
    filtered_indices = [i for i, prob_dist in enumerate(prob_dists) 
                        if least_confidence(prob_dist) > threshold]
    return filtered_indices
Reinforcement Learning from Human Feedback (RLHF)

Phát hiện phản hồi bất thường

prob_distribution_array = np.array([
    [0.1, 0.1, 0.2],   # Độ tin cậy thấp (0.2)
    [0.6, 0.2, 0.1],   # Độ tin cậy cao (0.6)
    [0.3, 0.3, 0.4]   # Độ tin cậy trung bình (0.4)
])

# Hàm lọc với ngưỡng 0.5 filtered_feedback_indices, filtered_confidences = filter_low_confidence_predictions(prob_distribution_array, threshold=0.5)
print(f"Filtered Confidence Scores: {filtered_confidences}")
Filtered Confidence Scores: [0.6]
Reinforcement Learning from Human Feedback (RLHF)

K-means

  • Tốt để phát hiện bất thường, triển khai nhanh
  • Dùng hiểu biết miền hoặc phương pháp phân tích để chọn số cụm

Sơ đồ mô tả thuật toán k-means.

Reinforcement Learning from Human Feedback (RLHF)

Phát hiện bất thường với k-means

import numpy as np
import pandas as pd
from sklearn.cluster import KMeans


def detect_anomalies(data, n_clusters=3): kmeans = KMeans(n_clusters=n_clusters, random_state=42) clusters = kmeans.fit_predict(data) centers = kmeans.cluster_centers_
# Calculate distances from cluster centers distances = np.linalg.norm(data - centers[clusters], axis=1) return distances
Reinforcement Learning from Human Feedback (RLHF)

Phát hiện bất thường với k-means

feedback_data = np.array([
    [4.0],  # Gần tâm cụm
    [4.5],  # Gần tâm cụm
    [1.0],  # Bất thường - xa nhóm chính
    [4.1],  # Gần tâm cụm
    [3.9]  # Gần tâm cụm
])

anomalies = detect_anomalies(confidences, n_clusters=1)
print(anomalies)
[0.5 1.  2.5   0.6 0.4]
Reinforcement Learning from Human Feedback (RLHF)

Ayo berlatih!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...