Дослідження попередньо навчених LLM

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Важливість донавчання

Схема, що ілюструє процес RLHF.

Reinforcement Learning from Human Feedback (RLHF)

Важливість донавчання

Схема LLM із вхідними та вихідними даними.

Reinforcement Learning from Human Feedback (RLHF)

Покроковий гід із донавчання LLM

Піктограма LLM, натренованої розпізнавати тональність твітів.

Reinforcement Learning from Human Feedback (RLHF)

Покроковий гід із донавчання LLM

Піктограма LLM для тональності твітів, що видає хибний результат.

Reinforcement Learning from Human Feedback (RLHF)

Покроковий гід із донавчання LLM

Піктограма LLM для розпізнавання тональності твітів, попередньо навченої на великому наборі даних.

Reinforcement Learning from Human Feedback (RLHF)

Крок 1: завантажте дані для роботи

from datasets import load_dataset
import pandas as pd

# `load_dataset` simplifies loading and preprocessing datasets from various sources
# It provides easy access to a wide range of datasets with minimal setup
dataset = load_dataset("mteb/tweet_sentiment_extraction")
df = pd.DataFrame(dataset['train'])
    id               text                                        label   label_text
0   cb774db0d1       I'd have responded, if I were going         1       neutral
1   549e992a42       Sooo SAD I will miss you in San Diego!!!    0       negative
2   08ac60f138       my boss is bullying me...                   0       negative
Reinforcement Learning from Human Feedback (RLHF)

Крок 2: оберіть попередньо навчenu модель

from transformers import AutoModelForCausalLM

# AutoModelForCausalLM simplifies loading and switching models
model = AutoModelForCausalLM.from_pretrained("openai-gpt")

 

  • Causal models: попередні токени «спричиняють» наступні
Reinforcement Learning from Human Feedback (RLHF)

Крок 3: токенізатор

from transformers import AutoTokenizer

# `AutoTokenizer` loads the correct tokenizer for the specified model
tokenizer = AutoTokenizer.from_pretrained("openai-gpt")
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
model.resize_token_embeddings(len(tokenizer))

 

  • Padding: для вирівнювання батчів до однакової довжини
Reinforcement Learning from Human Feedback (RLHF)

Крок 3: токенізатор

def tokenize_function(examples):
    tokenized = tokenizer(examples["content"], padding="max_length", truncation=True) 
    return tokenized

tokenized_datasets = dataset.map(tokenize_function, batched=True)

 

  • Параметр batched: для швидшої обробки
Reinforcement Learning from Human Feedback (RLHF)

Крок 4: донавчіть за допомогою методу Trainer

training_args = TrainingArguments(
   output_dir="test_trainer",
   per_device_train_batch_size=1,
   per_device_eval_batch_size=1,  
   gradient_accumulation_steps=4)
trainer = Trainer(
   model=model,
   args=training_args,
   train_dataset=tokenized_dataset["train"],
   eval_dataset=tokenized_dataset["test"])
trainer.train()
Reinforcement Learning from Human Feedback (RLHF)

Давайте потренуємось!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...