RLHFAlignment<T>

Models & Types · AiDotNet.AdversarialRobustness.Alignment

Implements Reinforcement Learning from Human Feedback (RLHF) for AI alignment.

Implements: IAlignmentMethod<T>

For Beginners

RLHF is like having a human teacher grade the AI’s responses and using those grades to improve the AI. The AI learns what humans prefer and adjusts its behavior accordingly. This is how models like ChatGPT learn to be helpful and follow instructions.

How It Works

RLHF trains models to align with human preferences by learning a reward model from human feedback and using it to fine-tune the model via reinforcement learning.

Original approaches: “Learning to summarize from human feedback” (OpenAI, 2020), “Training language models to follow instructions with human feedback” (InstructGPT, 2022)

Constructors

Constructor Summary
RLHFAlignment(AlignmentMethodOptions<T> options) Initializes a new instance of RLHF alignment.

Properties

Property Summary
bool IsRewardModelTrained { get; } Gets whether the reward model has been trained.
bool StrictHonestyMode { get; set; } When false (default — industry convention: honesty-on-non-comparable), IsHonest returns true for inputs the heuristic cannot evaluate (null / empty / length-mismatch input vs output) and emits a Trace warning so the unscored pair is obs…

Methods

Method Summary
AlignmentMethodOptions<T> GetOptions()
AlignmentMetrics<T> EvaluateAlignment(IPredictiveModel<T, Vector<T>, Vector<T>> model, AlignmentEvaluationData<T> evaluationData)
IPredictiveModel<T, Vector<T>, Vector<T>> AlignModel(IPredictiveModel<T, Vector<T>, Vector<T>> baseModel, AlignmentFeedbackData<T> feedbackData)
IPredictiveModel<T, Vector<T>, Vector<T>> ApplyConstitutionalPrinciples(IPredictiveModel<T, Vector<T>, Vector<T>> model, string[] principles)
RedTeamingResults PerformRedTeaming(Func<string, string> model, SafetyPipeline<T> pipeline)
byte[] Serialize()
void Deserialize(byte[] data)
void LoadModel(string filePath)
void Reset()
void SaveModel(string filePath)