피드백의 품질과 관련성 측정

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

이상 피드백 탐지의 적용

예시:

  • 긍정 리뷰:
    • "이 제품이 정말 마음에 들었어요!"
  • 부정 리뷰:
    • "서비스가 형편없어요."
  • 중립 리뷰:
    • "기능은 하는 대로 합니다."
  • 이상 리뷰:
    • "하늘은 파랗다."

네 개의 별 평가에 손이 다섯 번째 별을 추가하는 이미지

Reinforcement Learning from Human Feedback (RLHF)

이상 피드백 탐지

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)

이상 피드백 탐지

prob_distribution_array = np.array([
    [0.1, 0.1, 0.2],   # 낮은 신뢰도(0.2)
    [0.6, 0.2, 0.1],   # 높은 신뢰도(0.6)
    [0.3, 0.3, 0.4]   # 중간 신뢰도(0.4)
])

# 임계값 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-평균

  • 이상치 탐지에 유용하며 구현이 빠름
  • 클러스터 수는 도메인 지식 또는 분석으로 결정

k-평균 알고리즘을 나타내는 다이어그램.

Reinforcement Learning from Human Feedback (RLHF)

k-평균으로 이상치 탐지

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)

k-평균으로 이상치 탐지

feedback_data = np.array([
    [4.0],  # 클러스터 중심에 가까움
    [4.5],  # 클러스터 중심에 가까움
    [1.0],  # 이상치 - 주된 그룹에서 멀리 있음
    [4.1],  # 클러스터 중심에 가까움
    [3.9]  # 클러스터 중심에 가까움
])

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

연습해 봅시다!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...