How to Generate and Use Synthetic Data for Finetuning
Юджин Ян делает обзор того, как генерировать и использовать синтетические данные для дообучения языковых моделей. Существуют два основных подхода: дистилляция знаний из более сильной модели-учителя и self-improvement, когда модель учится на собственных ответах через итеративный цикл. Синтетические данные применяются в претрейне, instruction-tuning и preference-tuning; они дешевле и быстрее ручной разметки, а нередко превосходят её по качеству и разнообразию. Подробно разбираются пионерские работы Self-Instruct (бутстрэппинг из самой gpt-3) и Unnatural Instructions (дистилляция из gpt-3.5), показавшие, что даже наполовину корректные данные полезны для instruction-tuning. Далее идёт обзор техник дистилляции (Alpaca, Vicuna, WizardLM, Orca, WizardCoder, Magicoder, phi-1, Starling-7B) и методов self-improvement (Instruction Backtranslation, SPIN, ReST-EM, Self-Rewarding LMs, SteerLM, Constitutional AI от Anthropic), а также генерация синтетики для претрейна (AlphaGeometry, WRAP).
How to Generate and Use Synthetic Data for Finetuning
Как генерировать и использовать синтетические данные для дообучения
It is increasingly viable to use synthetic data for pretraining, instruction-tuning, and preference-tuning. Synthetic data refers to data generated via a model or simulated environment, instead of naturally occurring on the internet or annotated by humans.
Использование синтетических данных для претрейна, instruction-tuning и preference-tuning становится всё более жизнеспособным. Синтетические данные — это данные, сгенерированные моделью или симулируемой средой, а не естественным образом встречающиеся в интернете либо размеченные людьми.
Relative to human annotation, it’s faster and cheaper to generate task-specific synthetic data. Furthermore, the quality and diversity of synthetic data often exceeds that of human annotators, leading to improved performance and generalization when models are finetuned on synthetic data. Finally, synthetic data sidesteps privacy and copyright concerns by avoiding reliance on user data or possibly copyrighted content.
По сравнению с ручной разметкой генерировать синтетические данные под конкретную задачу быстрее и дешевле. Более того, качество и разнообразие синтетических данных нередко превосходят показатели разметчиков-людей, что приводит к улучшению производительности и обобщающей способности моделей, дообученных на синтетических данных. Наконец, синтетические данные обходят проблемы приватности и авторского права, поскольку не опираются на пользовательские данные или потенциально защищённый авторским правом контент.
There are two main approaches to generate synthetic data: Distillation from a stronger model or Self-improvement on the model’s own output. The synthetic data can then be used in pretraining, instruction-tuning, and preference-tuning.
Существуют два основных подхода к генерации синтетических данных: дистилляция из более сильной модели или self-improvement на собственных выходах модели. Полученные синтетические данные затем можно использовать в претрейне, instruction-tuning и preference-tuning.
Distillation transfers knowledge and reasoning skills from a stronger teacher to a weaker but more efficient student, optimizing for response quality and computation efficiency. In contrast, self-improvement has the model learn from its responses via an iterative loop. It avoids external dependencies and contractual restrictions. Nonetheless, it limits the learning to the model’s initial abilities and can amplify biases and errors.
Дистилляция переносит знания и навыки рассуждения из более сильного учителя в более слабого, но более эффективного ученика, оптимизируя качество ответов и вычислительную эффективность. В отличие от этого, self-improvement позволяет модели учиться на собственных ответах через итеративный цикл. Этот подход избавляет от внешних зависимостей и договорных ограничений. Тем не менее он ограничивает обучение изначальными способностями модели и может усиливать смещения и ошибки.
(Aside: For large organizations, distilling external models or violating an API provider’s Terms of Service may carry reputation and legal risks. For example, the lead author of BERT at Google resigned after concerns that Bard was using data from ChatGPT. Similarly, ByteDance’s account was suspended after it used GPT data to train a model of its own.)
(Замечание в сторону: для крупных организаций дистилляция внешних моделей или нарушение условий использования провайдера API могут нести репутационные и юридические риски. Например, ведущий автор BERT в Google уволился после опасений, что Bard использует данные из ChatGPT. Аналогично, аккаунт ByteDance был заблокирован после того, как компания использовала данные GPT для обучения собственной модели.)
Specific to synthetic data, pretraining involves building the model’s base knowledge on generated data, or augmenting real-world datasets with model-generated data. For instruction-tuning, we build synthetic instruction-response pairs to improve the model’s comprehension of nuanced queries, as well as improve response precision. Preference tuning relies on a mix of positive and negative synthetic feedback to reward the model for desired behaviors, such as being helpful, honest, and harmless.
Применительно к синтетическим данным, претрейн предполагает построение базовых знаний модели на сгенерированных данных или дополнение реальных датасетов данными, сгенерированными моделью. Для instruction-tuning мы строим синтетические пары «инструкция–ответ», чтобы улучшить понимание моделью тонких запросов и повысить точность ответов. Preference-tuning опирается на смесь положительной и отрицательной синтетической обратной связи, чтобы вознаграждать модель за желаемое поведение — быть полезной, честной и безопасной.
We’ll discuss two papers on distillation (Unnatural Instructions) and self-improvement (Self-Instruct). Then, we’ll summarize various distillation techniques before going through the details of some self-improvement approaches.
Мы обсудим две статьи — по дистилляции (Unnatural Instructions) и по self-improvement (Self-Instruct). Затем кратко рассмотрим различные техники дистилляции, после чего разберём детали некоторых подходов self-improvement.
Self-Improvement vs. Distillation
Self-improvement против дистилляции
Self-Instruct and Unnatural Instructions were published a day apart (in Dec 2022) but take very different approaches to generate synthetic data. The former bootstraps synthetic data from the model itself while the latter distills it from an external, stronger model.
Self-Instruct и Unnatural Instructions были опубликованы с разницей в один день (в декабре 2022 года), но используют совершенно разные подходы к генерации синтетических данных. Первый бутстрэппит синтетические данные из самой модели, тогда как второй дистиллирует их из внешней, более сильной модели.
Self-Instruct improves the instruction-following ability of a non-finetuned model (vanilla gpt-3) by bootstrapping off its own generations. First, they generate instructions, input context, and responses from the model. Then, they filter invalid or similar examples before using the remaining samples to finetune the original model.
Self-Instruct улучшает способность следовать инструкциям у недообученной модели (обычной gpt-3), бутстрэппя её собственные генерации. Сначала из модели генерируются инструкции, входной контекст и ответы. Затем недопустимые или похожие примеры отфильтровываются, а оставшиеся образцы используются для дообучения исходной модели.
For seed data, they start with 175 human-written tasks from the authors and their colleagues. Each task contains an instruction, optional context, and expected response.
В качестве затравочных данных они начинают со 175 написанных людьми задач от авторов и их коллег. Каждая задача содержит инструкцию, опциональный контекст и ожидаемый ответ.
{
"id": "seed_task_0",
"name": "breakfast_suggestion",
"instruction": "Is there anything I can eat for a breakfast that doesn't include eggs,
yet includes protein, and has roughly 700-1000 calories?",
"instances": [
{
"input": "",
"output": "Yes, you can have 1 oatmeal banana protein shake and 4 strips of bacon.
The oatmeal banana protein shake may contain 1/2 cup oatmeal, 60 grams
whey protein powder, 1/2 medium banana, 1tbsp flaxseed oil and 1/2 cup
water, totalling about 550 calories. The 4 strips of bacon contains
about 200 calories."
}
],
"is_classification": false
}
{
"id": "seed_task_1",
"name": "antonym_relation",
"instruction": "What is the relation between the given pairs?",
"instances": [
{
"input": "Night : Day :: Right : Left",
"output": "The relation between the given pairs is that they are opposites."
}
],
"is_classification": false
}
...
{
"id": "seed_task_151",
"name": "toxic_sentence_detection",
"instruction": "Tell if the sentence contains toxic language.",
"instances": [
{
"input": "aw, no wonder she married you. you are a bastard.",
"output": "Yes"
}
],
"is_classification": true
}
{ "id": "seed_task_0", "name": "breakfast_suggestion", "instruction": "Is there anything I can eat for a breakfast that doesn't include eggs, yet includes protein, and has roughly 700-1000 calories?", "instances": [ { "input": "", "output": "Yes, you can have 1 oatmeal banana protein shake and 4 strips of bacon. The oatmeal banana protein shake may contain 1/2 cup oatmeal, 60 grams whey protein powder, 1/2 medium banana, 1tbsp flaxseed oil and 1/2 cup water, totalling about 550 calories. The 4 strips of bacon contains about 200 calories." } ], "is_classification": false } { "id": "seed_task_1", "name": "antonym_relation", "instruction": "What is the relation between the given pairs?", "instances": [ { "input": "Night : Day :: Right : Left", "output": "The relation between the given pairs is that they are opposites." } ], "is_classification": false } ... { "id": "seed_task_151", "name": "toxic_sentence_detection", "instruction": "Tell if the sentence contains toxic language.", "instances": [ { "input": "aw, no wonder she married you. you are a bastard.", "output": "Yes" } ], "is_classification": true }
Example seed tasks
Примеры затравочных задач
To generate synthetic instructions, they use eight randomly sampled seed instructions for few-shot prompting. For the first round of generation, all sampled instructions come from the seed set. For subsequent rounds, two out of eight instructions are sampled from model-generated instructions to promote diversity.
Для генерации синтетических инструкций используется few-shot-промптинг с восемью случайно выбранными затравочными инструкциями. В первом раунде генерации все выбранные инструкции берутся из затравочного набора. В последующих раундах две из восьми инструкций выбираются из сгенерированных моделью инструкций для повышения разнообразия.
Come up with a series of tasks:
Task 1: {instruction for existing task 1}
Task 2: {instruction for existing task 2}
Task 3: {instruction for existing task 3}
Task 4: {instruction for existing task 4}
Task 5: {instruction for existing task 5}
Task 6: {instruction for existing task 6}
Task 7: {instruction for existing task 7}
Task 8: {instruction for existing task 8}
Task 9:
Come up with a series of tasks: Task 1: {instruction for existing task 1} Task 2: {instruction for existing task 2} Task 3: {instruction for existing task 3} Task 4: {instruction for existing task 4} Task 5: {instruction for existing task 5} Task 6: {instruction for existing task 6} Task 7: {instruction for existing task 7} Task 8: {instruction for existing task 8} Task 9:
Prompt used for generating new instructions.
Промпт, используемый для генерации новых инструкций.
Then, they classify whether the generated instruction is a classification task or not. (We’ll see why in a bit). In this step, they used 12 classification instructions and 19 non-classification instructions from the seed dataset.
Затем они классифицируют, является ли сгенерированная инструкция задачей классификации или нет. (Зачем — увидим чуть позже.) На этом шаге использовались 12 инструкций классификации и 19 инструкций не-классификации из затравочного датасета.
Can the following task be regarded as a classification task with finite output labels?
Task: Given my personality and the job, tell me if I would be suitable.
Is it classification? Yes
Task: Give me an example of a time when you had to use your sense of humor.
Is it classification? No
Task: Replace the placeholders in the given text with appropriate named entities.
Is it classification? No
Task: Fact checking - tell me if the statement is true, false, or unknown, based on your
knowledge and common sense.
Is it classification? Yes
Task: Return the SSN number for the person.
Is it classification? No
...
Can the following task be regarded as a classification task with finite output labels? Task: Given my personality and the job, tell me if I would be suitable. Is it classification? Yes Task: Give me an example of a time when you had to use your sense of humor. Is it classification? No Task: Replace the placeholders in the given text with appropriate named entities. Is it classification? No Task: Fact checking - tell me if the statement is true, false, or unknown, based on your knowledge and common sense. Is it classification? Yes Task: Return the SSN number for the person. Is it classification? No ...
Prompt used for classifying whether a task instruction is a classification task or not.
Промпт, используемый для классификации того, является ли инструкция задачей классификации.
Next, for each synthetic instruction, they generate input context and output responses. This is done in two main ways: input-first or output-first. For input-first, the model generates the input fields before producing the corresponding output. If the instructions don’t require additional input, the model generates the output directly.
Далее для каждой синтетической инструкции генерируются входной контекст и выходные ответы. Это делается двумя основными способами: input-first или output-first. При input-first модель сначала генерирует входные поля, а затем — соответствующий выход. Если инструкции не требуют дополнительного входа, модель генерирует выход напрямую.
Come up with examples for the following tasks.
Try to generate multiple examples when possible.
If the task doesn’t require additional input, you can generate the output directly.
Task: Which exercises are best for reducing belly fat at home?
Output:
- Lying Leg Raises
- Leg In And Out
- Plank
- Side Plank
- Sit-ups
Task: Extract all the country names in the paragraph, list them separated by commas.
Example 1
Paragraph: Dr. No is the sixth novel by the English author Ian Fleming to feature his
British Secret Service agent James Bond. Written at Fleming’s Goldeneye estate in
Jamaica, it was first published in the United Kingdom by Jonathan Cape in 1958. In
the novel Bond looks into the disappearance in Jamaica of two fellow MI6 operatives
who had been investigating Doctor No. Bond travels to No’s Caribbean island and meets
Honeychile Rider, who is there to collect shells. They are captured and taken to a
luxurious facility carved into a mountain. The character of Doctor No, the son of a
German missionary and a Chinese woman, was influenced by Sax Rohmer’s Fu Manchu
stories. Dr. No was the first of Fleming’s novels to face widespread negative reviews
in Britain, but it was received more favourably in the United States.
Output: English, British, Jamaica, the United Kingdom, German, Chinese, Britain,
the United States.
Task: Converting 85 F to Celsius.
Output: 85°F = 29.44°C
...
Come up with examples for the following tasks. Try to generate multiple examples when possible. If the task doesn’t require additional input, you can generate the output directly. Task: Which exercises are best for reducing belly fat at home? Output: - Lying Leg Raises - Leg In And Out - Plank - Side Plank - Sit-ups Task: Extract all the country names in the paragraph, list them separated by commas. Example 1 Paragraph: Dr. No is the sixth novel by the English author Ian Fleming to feature his British Secret Service agent James Bond. Written at Fleming’s Goldeneye estate in Jamaica, it was first published in the United Kingdom by Jonathan Cape in 1958. In the novel Bond looks into the disappearance in Jamaica of two fellow MI6 operatives who had been investigating Doctor No. Bond travels to No’s Caribbean island and meets Honeychile Rider, who is there to collect shells. They are captured and taken to a luxurious facility carved into a mountain. The character of Doctor No, the son of a German missionary and a Chinese woman, was influenced by Sax Rohmer’s Fu Manchu stories. Dr. No was the first of Fleming’s novels to face widespread negative reviews in Britain, but it was received more favourably in the United States. Output: English, British, Jamaica, the United Kingdom, German, Chinese, Britain, the United States. Task: Converting 85 F to Celsius. Output: 85°F = 29.44°C ...
Prompt used for the input-first approach of instance generation.
Промпт, используемый для подхода input-first при генерации экземпляров.
The challenge with input-first is that it tends to bias output responses towards one label. For example, given the task of grammar error detection, it usually generates grammatically correct input. Thus, they propose the output-first approach for the classification task. It starts with generating possible class labels before conditioning the input context generation on the class label. This is why the prior classification step is needed.
Проблема input-first в том, что он склонен смещать выходные ответы в сторону одной метки. Например, при задаче обнаружения грамматических ошибок он обычно генерирует грамматически корректный вход. Поэтому для задачи классификации предлагается подход output-first. Он начинается с генерации возможных меток классов, а затем генерация входного контекста обусловливается меткой класса. Именно поэтому и нужен предшествующий шаг классификации.
Given the classification task definition and the class labels, generate an input that
corresponds to each of the class labels. If the task doesn’t require input, just
generate the correct class label.
Task: Classify the sentiment of the sentence into positive, negative, or mixed.
Class label: Mixed
Sentence: I enjoy the flavor of the restaurant but their service is too slow.
Class label: Positive
Sentence: I had a great day. The weather was beautiful and I spent time with friends.
Class label: Negative
Sentence: I was disappointed by the latest superhero movie. I would not recommend it.
Task: Given a dialogue, classify whether the user is satisfied with the service. You
should respond with "Satisfied" or "Unsatisfied".
Class label: Satisfied
Dialogue:
- Agent: Thank you for your feedback. We will work to improve our service in the future.
- Customer: I am happy with the service you provided. Thank you for your help.
Class label: Unsatisfied
Dialogue:
- Agent: Sorry that we will cancel your order. You will get a refund within 7 days.
- Customer: oh that takes too long. I want you to take quicker action on this.
...
Given the classification task definition and the class labels, generate an input that corresponds to each of the class labels. If the task doesn’t require input, just generate the correct class label. Task: Classify the sentiment of the sentence into positive, negative, or mixed. Class label: Mixed Sentence: I enjoy the flavor of the restaurant but their service is too slow. Class label: Positive Sentence: I had a great day. The weather was beautiful and I spent time with friends. Class label: Negative Sentence: I was disappointed by the latest superhero movie. I would not recommend it. Task: Given a dialogue, classify whether the user is satisfied with the service. You should respond with "Satisfied" or "Unsatisfied". Class label: Satisfied Dialogue: - Agent: Thank you for your feedback. We will work to improve our service in the future. - Customer: I am happy with the service you provided. Thank you for your help. Class label: Unsatisfied Dialogue: - Agent: Sorry that we will cancel your order. You will get a refund within 7 days. - Customer: oh that takes too long. I want you to take quicker action on this. ...
Prompt used for the output-first approach of instance generation.
Промпт, используемый для подхода output-first при генерации экземпляров.
The above is followed by some light filtering and post-processing. To encourage diversity, they only add new instructions when the ROUGE-L with any existing instruction is less than 0.7 (i.e., longest substring overlap is less than 0.7 of entire string). They also exclude instructions that contain keywords that can’t be fulfilled by a language model, such as “image”, “picture”, or “graph”. Finally, the exclude input-output pairs that are identical, or where the input is identical but has different output.
За вышеописанным следует лёгкая фильтрация и постобработка. Для поощрения разнообразия они добавляют новые инструкции, только если ROUGE-L с любой существующей инструкцией меньше 0,7 (то есть перекрытие наибольшей общей подстроки меньше 0,7 от всей строки). Также исключаются инструкции, содержащие ключевые слова, которые языковая модель не может выполнить, например «image», «picture» или «graph». Наконец, исключаются пары вход-выход, которые идентичны, или где вход одинаков, но выход различается.
Overall, they generated 52k instructions and 82k input-output pairs.
В целом было сгенерировано 52 тыс. инструкций и 82 тыс. пар вход-выход.
To evaluate the quality of the synthetic data, they randomly sampled 200 instructions and an input-output pair. Then, an expert annotator (paper author) labeled whether the input-output pair was correct. While 92% of generated instructions were valid, synthetic input-output pairs were noisy. Overall, only 54% of the samples had completely valid fields.
Чтобы оценить качество синтетических данных, они случайно выбрали 200 инструкций и пару вход-выход. Затем эксперт-разметчик (автор статьи) пометил, корректна ли пара вход-выход. Хотя 92% сгенерированных инструкций оказались валидными, синтетические пары вход-выход были зашумлены. В целом лишь 54% образцов имели полностью валидные поля.
(I was astounded that synthetic data that was only half correct was useful for finetuning. The authors reasoned that even though the synthetic data contained errors, most were still in the correct format, or partially correct. Thus, this made the synthetic data useful for instruction-tuning. Nonetheless, it may not be suitable for base knowledge pretraining.)
(Я был поражён тем, что синтетические данные, корректные лишь наполовину, оказались полезны для дообучения. Авторы рассудили, что даже хотя синтетические данные содержали ошибки, большинство из них всё же были в правильном формате или частично корректны. Поэтому такие синтетические данные были полезны для instruction-tuning. Тем не менее они могут не подходить для претрейна базовых знаний.)
To evaluate the improvement in instruction-following ability, they used the evaluation set of Super-NaturalInstructions. It has 119 tasks with 100 instances in each task. Results showed that Self-Instructed gpt-3 outperformed vanilla gpt-3 by 33% and nearly matched the performance of InstructGPT-001.
Чтобы оценить улучшение способности следовать инструкциям, они использовали оценочный набор Super-NaturalInstructions. В нём 119 задач по 100 экземпляров в каждой. Результаты показали, что gpt-3 после Self-Instruct превзошла обычную gpt-3 на 33% и почти сравнялась по производительности с InstructGPT-001.
They also performed human evaluation using a new set of instructions based on user-oriented applications. The instruction authors then judged the model responses. Similarly, Self-Instructed gpt-3 outperformed vanilla gpt-3 and achieved similar performance to InstructGPT-001. (We also see the improvements from InstructGPT from 001 to 003.)
Они также провели оценку с участием людей, используя новый набор инструкций на основе ориентированных на пользователя приложений. Затем авторы инструкций оценивали ответы модели. Аналогично, gpt-3 после Self-Instruct превзошла обычную gpt-3 и достигла производительности, схожей с InstructGPT-001. (Мы также видим улучшения InstructGPT от версии 001 к 003.)
In an ablation, they explored using InstructGPT-003 to (re)generate output responses given the same instruction and input, and then finetuned on the InstructGPT-003 responses (i.e., distillation on InstructGPT-003). They found that gpt-3 distilled on InstructGPT outperformed Self-Instructed gpt-3 by 10%, demonstrating the lift that can be achieved via distilling from an external, stronger model.
В одном из ablation-экспериментов они исследовали использование InstructGPT-003 для (пере)генерации выходных ответов при тех же инструкции и входе, а затем дообучили модель на ответах InstructGPT-003 (то есть дистилляция на InstructGPT-003). Они обнаружили, что gpt-3, дистиллированная на InstructGPT, превзошла gpt-3 после Self-Instruct на 10%, демонстрируя прирост, который достигается за счёт дистилляции из внешней, более сильной модели.
In contrast to Self-Instruct, Unnatural Instructions generates synthetic data from an external model, gpt-3.5 (text-davinci-002). The synthetic data is then used to finetune t5-lm, a language model variant of t5-11b.
В отличие от Self-Instruct, Unnatural Instructions генерирует синтетические данные из внешней модели — gpt-3.5 (text-davinci-002). Затем синтетические данные используются для дообучения t5-lm, варианта-языковой-модели модели t5-11b.
They start with a seed set of 15 human-written examples. Then, to generate new instructions and input (i.e., context), they prompted gpt-3.5 with three examples to generate a fourth synthetic sample. They used five different seeds of three-shot examples to generate a distilled dataset of 68k examples. To encourage creativity while using the same few-shot examples, they applied nucleus sampling (top-$p$) with $p = 0.99$.
Они начинают с затравочного набора из 15 написанных людьми примеров. Затем, чтобы сгенерировать новые инструкции и вход (то есть контекст), они подавали gpt-3.5 три примера для генерации четвёртого синтетического образца. Они использовали пять различных затравок из трёх примеров (three-shot), чтобы сгенерировать дистиллированный датасет из 68 тыс. примеров. Чтобы поощрить креативность при использовании одних и тех же few-shot-примеров, они применили nucleus sampling (top-$p$) с $p = 0{,}99$.
Example 1
Instruction: You are given a science question (easy-level) and four answer options
(associated with “A”, “B”, “C”, “D”). Your task is to find the correct answer based on
scientific facts, knowledge, and reasoning. Do not generate anything else apart from one
of the following characters: ‘A’, ‘B, ‘C’, ‘D’. There is only one correct answer for
each question.
Input: Which part of a bicycle BEST moves in a circle? (A) Seat (B) Frame (C) Foot
pedal (D) Kickstand
Constraints: The output should be one of the following characters: ‘A’, ‘B, ‘C’, ‘D’.
Example 2
Instruction: You are given a negative review and your task is to convert it to a positive
review by one or more making minimal changes. Avoid changing the context of the review.
Input: we stood there in shock, because we never expected this.
Constraints: None.
Example 3
Instruction: In this task, you are given two sentences taken from a conversation, and
your job is to classify whether these given sentences are sequential or not. We will
mark the given sentence pair as ’True’ if it’s sequential, otherwise ’False’. The
two sentences are spoken by two different people.
Input: Noah: When and where are we meeting? :), Madison: I thought you were busy...?
Constraints: None.
Example 4
Example 1 Instruction: You are given a science question (easy-level) and four answer options (associated with “A”, “B”, “C”, “D”). Your task is to find the correct answer based on scientific facts, knowledge, and reasoning. Do not generate anything else apart from one of the following characters: ‘A’, ‘B, ‘C’, ‘D’. There is only one correct answer for each question. Input: Which part of a bicycle BEST moves in a circle? (A) Seat (B) Frame (C) Foot pedal (D) Kickstand Constraints: The output should be one of the following characters: ‘A’, ‘B, ‘C’, ‘D’. Example 2 Instruction: You are given a negative review and your task is to convert it to a positive review by one or more making minimal changes. Avoid changing the context of the review. Input: we stood there in shock, because we never expected this. Constraints: None. Example 3 Instruction: In this task, you are given two sentences taken from a conversation, and your job is to classify whether these given sentences are sequential or not. We will mark the given sentence pair as ’True’ if it’s sequential, otherwise ’False’. The two sentences are spoken by two different people. Input: Noah: When and where are we meeting? :), Madison: I thought you were busy...? Constraints: None. Example 4
Prompt used to generate new instructions and input.
Промпт, используемый для генерации новых инструкций и входа.
They then removed instruction-input pairs that (i) didn’t contain expected fields, (ii) were identical to the examples in the few-shot prompt, and (iii) were duplicates.
Затем они удалили пары инструкция-вход, которые (i) не содержали ожидаемых полей, (ii) были идентичны примерам в few-shot-промпте и (iii) являлись дубликатами.
To generate responses, they conditioned gpt-3.5 with the synthetic instruction-input examples. In this stage, they applied greedy decoding to prioritize correctness over creativity. They also included a template expansion step to increase format diversity. Specifically, they prompted gpt-3.5 to reformulate the tasks and collect two alternative formulations for each task.
Чтобы сгенерировать ответы, они обусловливали gpt-3.5 синтетическими примерами инструкция-вход. На этом этапе применялось жадное декодирование (greedy decoding), чтобы приоритизировать корректность над креативностью. Они также включили шаг расширения шаблонов для увеличения разнообразия форматов. В частности, они просили gpt-3.5 переформулировать задачи и собирали по две альтернативные формулировки для каждой задачи.
To evaluate the quality of synthetic data, they audited 200 samples. On correctness, only 56.5% of the samples were correct. Of the 87 incorrect samples, 9 had incomprehensible instructions, 35 had input that didn’t match the instructions, and 43 had incorrect output. Similar to Self-Instruct, the authors commented that though some of the synthetic data was incorrect, it was still useful for instruction-tuning.
Чтобы оценить качество синтетических данных, они проверили 200 образцов. По корректности лишь 56,5% образцов оказались верными. Из 87 некорректных образцов 9 имели непонятные инструкции, 35 — вход, не соответствующий инструкциям, а 43 — неверный выход. Как и в Self-Instruct, авторы отметили, что, хотя часть синтетических данных была некорректной, они всё же были полезны для instruction-tuning.
They finetuned t5-lm on these synthetic instructions and found it to outperform vanilla t5-lm. They also showed how Unnatural Instructions outperformed strong instruction-tuned baselines.
Они дообучили t5-lm на этих синтетических инструкциях и обнаружили, что она превосходит обычную t5-lm. Они также показали, как Unnatural Instructions превосходит сильные базовые модели, дообученные на инструкциях.
The paper also includes useful ablation studies on the external model used (gpt-3.5 vs gpt-3), prompt format (minimal, enumeration, verbose), the number of few-shot examples, using constraints, and the two-step process. Recommended read.
В статье также есть полезные ablation-исследования: используемая внешняя модель (gpt-3.5 против gpt-3), формат промпта (минимальный, перечислительный, многословный), количество few-shot-примеров, использование ограничений и двухэтапный процесс. Рекомендую к прочтению.
Distillation techniques
Техники дистилляции
Since Unnatural Instructions, several models have been finetuned on distilled synthetic data, usually from OpenAI APIs. These models explored ways to improve instruction-following on increasingly complex queries, with some focused on code. We’ll briefly summarize each paper in this section.
Со времён Unnatural Instructions несколько моделей были дообучены на дистиллированных синтетических данных, как правило, из API OpenAI. Эти модели исследовали способы улучшения следования инструкциям на всё более сложных запросах, причём некоторые были сосредоточены на коде. В этом разделе мы кратко изложим каждую статью.
Alpaca finetuned llama-7b on 52k instruction-following samples generated from gpt-3.5 (text-davinci-003). They reported that this cost less than $500. They used the same 175 human-written instruction-response pairs from the Self-Instruct seed set and generated more instruction-response pairs from gpt-3.5 via few-shot prompting.
Alpaca дообучила llama-7b на 52 тыс. образцов следования инструкциям, сгенерированных из gpt-3.5 (text-davinci-003). Они сообщили, что это стоило менее $500. Они использовали те же 175 написанных людьми пар инструкция-ответ из затравочного набора Self-Instruct и сгенерировали дополнительные пары инструкция-ответ из gpt-3.5 через few-shot-промптинг.
Vicuna finetuned llama-7b and llama-13b on user conversations from ShareGPT.com. They converted the HTML to markdown before excluding inappropriate or low-quality samples. This resulted in 125k conversations which was used for instruction-tuning.
Vicuna дообучила llama-7b и llama-13b на пользовательских диалогах с ShareGPT.com. Они преобразовали HTML в markdown, после чего исключили неприемлемые или низкокачественные образцы. В результате получилось 125 тыс. диалогов, которые были использованы для instruction-tuning.
WizardLM (Microsoft) demonstrated how to generate more complex instructions and responses via gpt-3.5. It distinguishes between in-depth evolution and in-breadth evolution. The former makes instructions more complex via five types of prompts such as adding constraints, deepening, increased reasoning steps, etc. The latter increases topic coverage, skill coverage, and overall dataset diversity.
WizardLM (Microsoft) продемонстрировала, как генерировать более сложные инструкции и ответы с помощью gpt-3.5. Она различает эволюцию вглубь (in-depth) и эволюцию вширь (in-breadth). Первая делает инструкции сложнее с помощью пяти типов промптов — добавление ограничений, углубление, увеличение числа шагов рассуждения и т. д. Вторая повышает охват тем, охват навыков и общее разнообразие датасета.
Orca (Microsoft) explores how smaller models can imitate the reasoning process of a larger, stronger model via explanation traces. First, they augmented instruction-responses pairs with explanations from gpt-4 and gpt-3.5. These explainations demonstrate the reasoning process as it generates the response. System instructions include “explain like I’m five”, “think step-by-step”, and “justify your response”. They sampled a diverse mix of tasks from FLAN-v2 and distilled 1M responses from gpt-4 and 5M responses from gpt-3.5. This was then used to finetune llama-13b.
Orca (Microsoft) исследует, как меньшие модели могут имитировать процесс рассуждения более крупной, сильной модели через трассы объяснений (explanation traces). Сначала они дополнили пары инструкция-ответ объяснениями от gpt-4 и gpt-3.5. Эти объяснения демонстрируют процесс рассуждения по мере генерации ответа. Системные инструкции включают «объясни как пятилетнему», «рассуждай пошагово» и «обоснуй свой ответ». Они отобрали разнообразную смесь задач из FLAN-v2 и дистиллировали 1 млн ответов из gpt-4 и 5 млн ответов из gpt-3.5. Это затем использовалось для дообучения llama-13b.
Orca2 (Microsoft) continues down the path of reasoning by finetuning llama-7b/13b to use various reasoning strategies for different tasks. They distilled a synthetic dataset of 817k samples from gpt-4 with various reasoning techniques such as step-by-step, recall-then-generate, recall-reason-generate, etc. These synthetic samples included information on how to determine the most effective reasoning technique for each task.
Orca2 (Microsoft) продолжает путь рассуждений, дообучая llama-7b/13b использовать различные стратегии рассуждения для разных задач. Они дистиллировали синтетический датасет из 817 тыс. образцов из gpt-4 с различными техниками рассуждения — пошаговое (step-by-step), recall-then-generate, recall-reason-generate и т. д. Эти синтетические образцы включали информацию о том, как определить наиболее эффективную технику рассуждения для каждой задачи.
Beyond instruction-following on general language tasks, several code-generation models have also been finetuned via distillation.
Помимо следования инструкциям на общих языковых задачах, несколько моделей генерации кода также были дообучены через дистилляцию.
WizardCoder (Microsoft) takes a leaf from WizardLM by adapting the evol-instruct method to make code instructions more complex to enhance finetuning. They started with the 20k instruction-following dataset from Code Alpaca and applied evol-instruct. (Unfortunately, it wasn’t clear how they did this; I’m guessing it was via an OpenAI API.) Then, they finetuned starcoder-15b on the synthetic data. They adapted the evol-instruct prompt to focus on code-related complexity (prompts below).
WizardCoder (Microsoft) заимствует у WizardLM, адаптируя метод evol-instruct, чтобы делать инструкции по коду сложнее и улучшать дообучение. Они начали с датасета следования инструкциям из 20 тыс. примеров из Code Alpaca и применили evol-instruct. (К сожалению, не вполне ясно, как именно они это сделали; полагаю, через API OpenAI.) Затем они дообучили starcoder-15b на синтетических данных. Они адаптировали промпт evol-instruct, чтобы сфокусироваться на сложности, связанной с кодом (промпты ниже).
Add new constraints and requirements to the original problem, adding
approximately 10 additional words.
Replace a commonly used requirement in the programming task with a less
common and more specific one.
If the original problem can be solved with only a few logical steps,
please add more reasoning steps.
Provide a piece of erroneous code as a reference to increase
misdirection.
Propose higher time or space complexity requirements, but please refrain
from doing so frequently.
Add new constraints and requirements to the original problem, adding approximately 10 additional words. Replace a commonly used requirement in the programming task with a less common and more specific one. If the original problem can be solved with only a few logical steps, please add more reasoning steps. Provide a piece of erroneous code as a reference to increase misdirection. Propose higher time or space complexity requirements, but please refrain from doing so frequently.
Prompts used for code evolution.
Промпты, используемые для эволюции кода.
Magicoder generates synthetic coding problems by providing example code snippets as part of the few-shot prompt. They start with 80k seed snippets from the StarCoder data. Then, they used gpt-3.5 to generate new coding problems, providing as context 1 - 15 randomly extracted lines from a selected code snippet. The synthetic coding problems were then used to finetune code-gen models.
Magicoder генерирует синтетические задачи по программированию, подавая примеры фрагментов кода в составе few-shot-промпта. Они начинают с 80 тыс. затравочных фрагментов из данных StarCoder. Затем они использовали gpt-3.5 для генерации новых задач по программированию, подавая в качестве контекста от 1 до 15 случайно извлечённых строк из выбранного фрагмента кода. Синтетические задачи по программированию затем использовались для дообучения моделей генерации кода.
WaveCoder (Microsoft) extends code instruction-tuning by classifying instruction data into four code tasks: summarization, generation, translation, and repair. They start with CodeSearchNet which contains 2M comment-code pairs from GitHub. Then, they use gpt-4 to generate instructions and code requirements, followed by gpt-3.5 to generate context and responses. Next, they used gpt-4 to classify the generated samples as good or bad, and the good samples were used to finetune several code-gen models.
WaveCoder (Microsoft) расширяет instruction-tuning для кода, классифицируя данные инструкций по четырём задачам, связанным с кодом: суммаризация, генерация, перевод и исправление. Они начинают с CodeSearchNet, содержащего 2 млн пар комментарий-код с GitHub. Затем они используют gpt-4 для генерации инструкций и требований к коду, а далее gpt-3.5 — для генерации контекста и ответов. Затем они использовали gpt-4 для классификации сгенерированных образцов как хороших или плохих, и хорошие образцы использовались для дообучения нескольких моделей генерации кода.
Textbooks are all you need (phi-1; Microsoft) trained a 1.3b param model to write simple Python functions via docstrings. It’s trained on “textbook-quality” data filtered from the Stack and StackOverflow via a quality classifier. To train the quality classifier, they used gpt-4 to annotate 100k samples based on “educational value” and then trained a random forest classifier that predicts file quality. They also augmented the data with synthetic textbooks and exercises (~1B tokens) distilled from gpt-3.5. The synthetic textbooks were used in pretraining while the synthetic exercises were used in instruction-tuning.
Textbooks are all you need (phi-1; Microsoft) обучила модель на 1,3 млрд параметров писать простые функции на Python по докстрингам. Она обучена на данных «учебникового качества», отфильтрованных из the Stack и StackOverflow с помощью классификатора качества. Чтобы обучить классификатор качества, они использовали gpt-4 для разметки 100 тыс. образцов по «образовательной ценности», а затем обучили классификатор на основе случайного леса, предсказывающий качество файла. Они также дополнили данные синтетическими учебниками и упражнениями (~1 млрд токенов), дистиллированными из gpt-3.5. Синтетические учебники использовались в претрейне, а синтетические упражнения — в instruction-tuning.
Textbooks Are All You Need II (phi-1.5; Microsoft) goes further by generating 20b tokens of synthetic textbooks on common sense reasoning and general knowledge of the world (e.g., science, daily activities, theory of mind). This was then used to pretrain phi-1.5.
Textbooks Are All You Need II (phi-1.5; Microsoft) идёт дальше, генерируя 20 млрд токенов синтетических учебников по здравому смыслу и общим знаниям о мире (например, наука, повседневная деятельность, theory of mind). Это затем использовалось для претрейна phi-1.5.
Starling-7B has an additional component of preference-tuning on a gpt-4 labeled ranking dataset. This dataset consists of 183 chat prompts that each has seven responses distilled from models such as gpt-4, gpt-3.5-instruct, gpt-3.5-turbo, mistral-7b-instruct, and llama2-7b. This results in 3.8M pairwise comparisons. The preference data is then used to finetune a reward model, based on llama2-7b-chat, via the k-wise maximum likelihood estimator under the Plackett-Luce Model.
Starling-7B имеет дополнительный компонент — preference-tuning на размеченном gpt-4 датасете ранжирования. Этот датасет состоит из 183 чат-промптов, каждый из которых имеет семь ответов, дистиллированных из таких моделей, как gpt-4, gpt-3.5-instruct, gpt-3.5-turbo, mistral-7b-instruct и llama2-7b. В результате получается 3,8 млн попарных сравнений. Данные предпочтений затем используются для дообучения reward-модели на основе llama2-7b-chat с помощью k-wise оценки максимального правдоподобия в рамках модели Плакетта–Льюса (Plackett-Luce).
Self-improvement (aka non-distillation) techniques
Техники self-improvement (он же подход без дистилляции)
Self-improvement approaches don’t rely on an external model to generate synthetic data. Instead, they bootstrap on the model that’s being finetuned over several iterations of generation, self-evaluation, and finetuning. We’ll start with instruction-tuning methods followed by preference-tuning methods. Then, we’ll see how Anthropic’s Constitution AI applies both. Finally, we briefly discuss methods to generate synthetic data for pretraining.
Подходы self-improvement не полагаются на внешнюю модель для генерации синтетических данных. Вместо этого они бутстрэппят дообучаемую модель в течение нескольких итераций генерации, самооценки и дообучения. Мы начнём с методов instruction-tuning, затем перейдём к методам preference-tuning. Далее увидим, как Constitutional AI от Anthropic применяет оба. Наконец, мы кратко обсудим методы генерации синтетических данных для претрейна.
Synthetic data for instruction-tuning
Синтетические данные для instruction-tuning
Self-Alignment with Instruction Backtranslation (Meta) turns generating synthetic data on its head—instead of generating responses for human instructions, they generate instructions for human-written text on the internet. It’s inspired by backtranslation methods from machine translation, where a human-written target sentence is automatically annotated with model-generated source sentences in another language.
Self-Alignment with Instruction Backtranslation (Meta) переворачивает генерацию синтетических данных с ног на голову — вместо генерации ответов на инструкции людей они генерируют инструкции для написанного людьми текста в интернете. Подход вдохновлён методами обратного перевода (backtranslation) из машинного перевода, где написанное человеком целевое предложение автоматически аннотируется сгенерированными моделью исходными предложениями на другом языке.
They start with a seed set of human-annotated instruction-response pairs that is used to finetune a model to generate (i) a response given an instruction and (ii) an instruction given an input response. They used 3,200 examples from the OpenAssistant dataset where each example is the first turn of the conversation.
Они начинают с затравочного набора аннотированных людьми пар инструкция-ответ, который используется для дообучения модели, чтобы она могла генерировать (i) ответ по инструкции и (ii) инструкцию по входному ответу. Они использовали 3200 примеров из датасета OpenAssistant, где каждый пример — это первый ход диалога.
To prepare the human-written “responses” from web documents (Clueweb), they extracted self-contained text segments and performed deduplication, length filtering, and quality filtering with heuristics. This led to 502k segments as responses.
Чтобы подготовить написанные людьми «ответы» из веб-документов (Clueweb), они извлекли самодостаточные текстовые сегменты и выполнили дедупликацию, фильтрацию по длине и фильтрацию по качеству с помощью эвристик. Это привело к 502 тыс. сегментов в качестве ответов.
For the base models, they used llama-7b, llama-33b, and llama-65b.
В качестве базовых моделей они использовали llama-7b, llama-33b и llama-65b.
In the self-augmentation step (i.e., generate instructions for unlabeled responses), they finetuned the model with response-instruction pairs to obtain a “backward” model. This backward model is then used to generate candidate instructions for each response.
На шаге self-augmentation (то есть генерация инструкций для неразмеченных ответов) они дообучили модель на парах ответ-инструкция, чтобы получить «обратную» (backward) модель. Эта обратная модель затем используется для генерации кандидатных инструкций для каждого ответа.
Then, in the self-curation step (i.e., selecting high-quality instruction-response pairs), they start with a seed instruction model $M_0$ that is finetuned on the seed set of instruction-response pairs. This model is then used to score each augmented instruction-response pair on a 5-point scale via prompting. They then selected subsets of the augmented examples that have scores ≥ 4 and scores = 5 to form curated sets $A^{(1)}_4$ and $A^{(1)}_5$. (The $^{(1)}$ indicates that curated set comes from the first iteration.)
Затем на шаге self-curation (то есть отбор высококачественных пар инструкция-ответ) они начинают с затравочной instruction-модели $M_0$, дообученной на затравочном наборе пар инструкция-ответ. Эта модель затем используется для оценки каждой дополненной пары инструкция-ответ по 5-балльной шкале через промптинг. Затем они отобрали подмножества дополненных примеров с оценками ≥ 4 и оценками = 5, сформировав курируемые наборы $A^{(1)}_4$ и $A^{(1)}_5$. (Верхний индекс $^{(1)}$ указывает, что курируемый набор получен из первой итерации.)
Below is an instruction from an user and a candidate answer. Evaluate whether or
not the answer is a good example of how AI Assistant should respond to the user’s
instruction. Please assign a score using the following 5-point scale:
1: It means the answer is incomplete, vague, off-topic, controversial, or not
exactly what the user asked for. For example, some content seems missing, numbered
list does not start from the beginning, the opening sentence repeats user’s question.
Or the response is from another person’s perspective with their personal experience
(e.g. taken from blog posts), or looks like an answer from a forum. Or it contains
promotional text, navigation text, or other irrelevant information.
2: It means the answer addresses most of the asks from the user. It does not
directly address the user’s question. For example, it only provides a high-level
methodology instead of the exact solution to user’s question.
3: It means the answer is helpful but not written by an AI Assistant. It addresses
all the basic asks from the user. It is complete and self contained with the
drawback that the response is not written from an AI assistant’s perspective, but
from other people’s perspective. The content looks like an excerpt from a blog post,
web page, or web search results. For example, it contains personal experience or
opinion, mentions comments section, or share on social media, etc.
4: It means the answer is written from an AI assistant’s perspective with a
clear focus of addressing the instruction. It provide a complete, clear, and
comprehensive response to user’s question or instruction without missing or
irrelevant information. It is well organized, self-contained, and written in a
helpful tone. It has minor room for improvement, e.g. more concise and focused.
5: It means it is a perfect answer from an AI Assistant. It has a clear focus on
being a helpful AI Assistant, where the response looks like intentionally written
to address the user’s question or instruction without any irrelevant sentences. The
answer provides high quality content, demonstrating expert knowledge in the area, is
very well written, logical, easy-to-follow, engaging and insightful.
Please first provide a brief reasoning you used to derive the rating score, and
then write "Score: <rating>" in the last line.
<generated instruction>
<output>
Below is an instruction from an user and a candidate answer. Evaluate whether or not the answer is a good example of how AI Assistant should respond to the user’s instruction. Please assign a score using the following 5-point scale: 1: It means the answer is incomplete, vague, off-topic, controversial, or not exactly what the user asked for. For example, some content seems missing, numbered list does not start from the beginning, the opening sentence repeats user’s question. Or the response is from another person’s perspective with their personal experience (e.g. taken from blog posts), or looks like an answer from a forum. Or it contains promotional text, navigation text, or other irrelevant information. 2: It means the answer addresses most of the asks from the user. It does not directly address the user’s question. For example, it only provides a high-level methodology instead of the exact solution to user’s question. 3: It means the answer is helpful but not written by an AI Assistant. It addresses all the basic asks from the user. It is complete and self contained with the drawback that the response is not written from an AI assistant’s perspective, but from other people’s perspective. The content looks like an excerpt from a blog post, web page, or web search results. For example, it contains personal experience or opinion, mentions comments section, or share on social media, etc. 4: It means the answer is written from an AI assistant’s perspective with a clear focus of addressing the instruction. It provide a complete, clear, and comprehensive response to user’s question or instruction without missing or irrelevant information. It is well organized, self-contained, and written in a helpful tone. It has minor room for improvement, e.g. more concise and focused. 5: It means it is a perfect answer from an AI Assistant. It has a clear focus on being a helpful AI Assistant, where the response looks like intentionally written to address the user’s question or instruction without any irrelevant sentences. The answer provides high quality content, demonstrating expert knowledge in the area, is very well written, logical, easy-to-follow, engaging and insightful. Please first provide a brief reasoning you used to derive the rating score, and then write "Score:
Prompt used in self-curation step
Промпт, используемый на шаге self-curation
Self-augmentation and self-curation is done iteratively, where the augmented and curated data from a previous step $A^{(t-1)}_k$ is used to finetune an improved model $M_t$. The finetuned model is then used to rescore the augmented examples for quality, resulting in $A^{(t)}_k$. They performed two iterations of data curation and finetuning to get the final model $M_2$.
Self-augmentation и self-curation выполняются итеративно: дополненные и курируемые данные с предыдущего шага $A^{(t-1)}_k$ используются для дообучения улучшенной модели $M_t$. Дообученная модель затем используется для повторной оценки качества дополненных примеров, что даёт $A^{(t)}_k$. Они выполнили две итерации курирования данных и дообучения, чтобы получить финальную модель $M_2$.
From the table below, we observe that the augmented instructions tend to be longer than the seed data. Nonetheless, self-curation ($A^{(2)}_4$ and $A^{(2)}_5$) reduced the instruction length by half, bringing it closer to the seed data. That said, output (response) length was still 50% - 100% longer than the seed data.
Из таблицы ниже видно, что дополненные инструкции, как правило, длиннее затравочных данных. Тем не менее self-curation ($A^{(2)}_4$ и $A^{(2)}_5$) сократил длину инструкций вдвое, приблизив её к затравочным данным. При этом длина выхода (ответа) всё же была на 50–100% больше, чем у затравочных данных.
For evaluation, they used AlpacaEval (automated eval via gpt-4) against 805 prompts from the Alpaca Leaderboard. AlpacaEval compares the pairwise win-rate against the reference model gpt-3.5 (text-davinci-003). Overall, their model (Humpback) outperformed other non-distillation methods by a large margin.
Для оценки они использовали AlpacaEval (автоматизированная оценка через gpt-4) на 805 промптах из Alpaca Leaderboard. AlpacaEval сравнивает попарный winrate относительно эталонной модели gpt-3.5 (text-davinci-003). В целом их модель (Humpback) превзошла другие методы без дистилляции с большим отрывом.
They also conducted human eval by presenting outputs from two models and asking annotators to pick which output was better, or if there was no significant difference. Similarly, Humpback outperformed other non-distilled models as well as a few proprietary models (Claude, gpt-3.5). They also noted that the human eval distribution was roughly consistent with the preference distribution from using gpt-4 as judge.
Они также провели оценку с участием людей, показывая выходы двух моделей и прося разметчиков выбрать, какой выход лучше, или указать, что значимой разницы нет. Аналогично, Humpback превзошла другие модели без дистилляции, а также несколько проприетарных моделей (Claude, gpt-3.5). Они также отметили, что распределение оценок людей примерно совпадало с распределением предпочтений при использовании gpt-4 в роли судьи.
The paper included ablations on (i) performance based on quality/quantity of augmented data, (ii) model improvements over iterations, (iii) training on augmented data only vs. seed + augmented data, and (iv) various system prompts. Highly recommended read.
В статью включены ablation-исследования по (i) производительности в зависимости от качества/количества дополненных данных, (ii) улучшениям модели по итерациям, (iii) обучению только на дополненных данных против затравочных + дополненных данных и (iv) различным системным промптам. Настоятельно рекомендую к прочтению.
Self-Play fIne-tuNing (SPIN) proposes a generative adversarial network (GAN) like approach to instruction tuning. The main player (discriminator) distinguishes between responses generated by an LLM vs. a human while the opponent (generator) generates responses that are indistinguishable from human.
Self-Play fIne-tuNing (SPIN) предлагает подход к instruction-tuning, похожий на генеративно-состязательную сеть (GAN). Главный игрок (дискриминатор) различает ответы, сгенерированные LLM, и ответы человека, тогда как оппонент (генератор) генерирует ответы, неотличимые от человеческих.
The objective function of the main player $f_{t+1}$ is to maximize the expected value gap between the target data distribution (human data $y \sim p_{data}(\cdot \vert x)$) from the opponent’s distribution (generated responses $y’ \sim p_{\theta_t}(\cdot \vert x)$):
Целевая функция главного игрока $f_{t+1}$ — максимизировать ожидаемый разрыв ценности между целевым распределением данных (данные человека $y \sim p_{data}(\cdot \vert x)$) и распределением оппонента (сгенерированные ответы $y’ \sim p_{\theta_t}(\cdot \vert x)$):
\(\mathcal{F}_t\) is a sequence of highly expressive function classes and $f_{t+1}(x, y)$ is the main player’s probability that $y$ originates $p_{data}$ rather than $p_{\theta_t}$. Thus, $f_{t+1}$ should be high when $y \sim p_{data}(\cdot \vert x)$ and low when $y’ \sim p_{\theta_t}(\cdot \vert x)$.
\(\mathcal{F}_t\) — это последовательность высоковыразительных классов функций, а $f_{t+1}(x, y)$ — оценка главным игроком вероятности того, что $y$ происходит из $p_{data}$, а не из $p_{\theta_t}$. Таким образом, $f_{t+1}$ должна быть высокой, когда $y \sim p_{data}(\cdot \vert x)$, и низкой, когда $y’ \sim p_{\theta_t}(\cdot \vert x)$.
Then, they showed that the function above can be solved via a more general optimization problem where $\ell(\cdot)$ is a loss function that is monotonically decreasing and convex. They used the logistic loss function $\ell(t) := \log(1 + \exp(-t))$ for its non-negativity, smoothness, and exponentially decaying tail.
Затем они показали, что приведённую выше функцию можно решить через более общую задачу оптимизации, где $\ell(\cdot)$ — функция потерь, монотонно убывающая и выпуклая. Они использовали логистическую функцию потерь $\ell(t) := \log(1 + \exp(-t))$ за её неотрицательность, гладкость и экспоненциально затухающий хвост.
The objective function of the opponent is to generate responses that are indistinguishable from $p_{data}$. To prevent excessive deviation of $p_{\theta_{t+1}}$ from $p_{\theta_{t}}$, they add the Kullback-Leibler (KL) regularization term. Thus, the optimization problem is:
Целевая функция оппонента — генерировать ответы, неотличимые от $p_{data}$. Чтобы предотвратить чрезмерное отклонение $p_{\theta_{t+1}}$ от $p_{\theta_{t}}$, они добавляют регуляризационный член Кульбака–Лейблера (KL). Таким образом, задача оптимизации выглядит так:
And has the closed form solution:
И имеет решение в замкнутой форме:
$\hat{p}(y \vert x)$ represents the updated probability for $y$ given $x$ after incorporating the information from $f_{t+1}$. It is proportional to the original distribution $p_{\theta_{t}}(y \vert x)$ but updated according to the learned function $f_{t+1}$ (i.e., main player).
$\hat{p}(y \vert x)$ представляет обновлённую вероятность для $y$ при заданном $x$ после учёта информации из $f_{t+1}$. Она пропорциональна исходному распределению $p_{\theta_{t}}(y \vert x)$, но обновлена согласно выученной функции $f_{t+1}$ (то есть главного игрока).
Then, solving for $p_{\theta}(y \vert x) \propto p_{\theta_t}(y \vert x) \exp \left( \lambda^{-1} f_{t+1}(x,y) \right)$ leads to $f_{t+1}(x,y) = \lambda \cdot \log \frac{p_{\theta}(\cdot \vert x)}{p_{\theta_t}(\cdot \vert x)}$, which suggests the following function class \(\mathcal{F}_t\) for $f_{t+1}$.
Затем решение для $p_{\theta}(y \vert x) \propto p_{\theta_t}(y \vert x) \exp \left( \lambda^{-1} f_{t+1}(x,y) \right)$ приводит к $f_{t+1}(x,y) = \lambda \cdot \log \frac{p_{\theta}(\cdot \vert x)}{p_{\theta_t}(\cdot \vert x)}$, что подсказывает следующий класс функций \(\mathcal{F}_t\) для $f_{t+1}$.
And thus optimizing $f_{t+1}$ parameterized by $\theta_{(t+1)}$ gives the following:
И таким образом оптимизация $f_{t+1}$, параметризованной $\theta_{(t+1)}$, даёт следующее:
The two steps of main-player training and opponent updating are integrated into a single end-to-end training objective.
Два шага — обучение главного игрока и обновление оппонента — объединены в единую сквозную (end-to-end) обучающую цель.
During iterative self-play, the opponent from the previous iteration $t$ is used to train the main player at $t+1$ which leads to the LM parameterized by $\theta_{t+1}$. Then, the next opponent player at $t+1$ copies the LM parameters $\theta_{t+1}$ which is then used to train the main player at iteration $t+2$. And so on.
Во время итеративной self-play оппонент с предыдущей итерации $t$ используется для обучения главного игрока на итерации $t+1$, что приводит к языковой модели, параметризованной $\theta_{t+1}$. Затем следующий игрок-оппонент на итерации $t+1$ копирует параметры языковой модели $\theta_{t+1}$, которые затем используются для обучения главного игрока на итерации $t+2$. И так далее.
For evals, they used the HuggingFace Open LLM Benchmark and finetuzed zephyr-7b-sft-full which is based on mistral-7b. For the dataset, they randomly sampled 50k instances from UltraChat200k. Overall, SPIN was able to improve zephyr-7b-sft-full beyond its original SFT. Nonetheless, improvement tapers off beyond 4 iterations.
Для оценки они использовали HuggingFace Open LLM Benchmark и дообучили zephyr-7b-sft-full, основанную на mistral-7b. В качестве датасета они случайно выбрали 50 тыс. экземпляров из UltraChat200k. В целом SPIN смог улучшить zephyr-7b-sft-full сверх её исходного SFT. Тем не менее улучшение сходит на нет после 4 итераций.
In an ablation, they compared SFT vs. SPIN. For SFT, they finetuned mistral-7b with UltraChat200k for three epochs. For SPIN, they finetuned zephyr-7b-sft-full (which is mistral-7b finetuned on UltraChat200k for one epoch). They showed that SFT seems to hit a ceiling after the first epoch and then degrades in performance. In contrast, SPIN surpassed the best result from SFT.
В одном из ablation-экспериментов они сравнили SFT и SPIN. Для SFT они дообучили mistral-7b на UltraChat200k в течение трёх эпох. Для SPIN они дообучили zephyr-7b-sft-full (это mistral-7b, дообученная на UltraChat200k в течение одной эпохи). Они показали, что SFT, похоже, упирается в потолок после первой эпохи, а затем деградирует по производительности. В отличие от этого, SPIN превзошёл лучший результат SFT.
Update (2024-03-16): However, in practice, SPIN may not work that well nor be worth the effort. See comments in this tweet.
Обновление (2024-03-16): Однако на практике SPIN может работать не так уж хорошо и не стоить затраченных усилий. См. комментарии в этом твите.
Beyond Human Data - Scaling Self-Training for Problem-Solving with Language Models ($\text{ReST}^{EM}$; Google) proposes a two-step self-training method inspired by expectation-maximization. In the E-step (generate), they generate multiple output samples for each instruction, and then filter the generations (via a binary reward) to create synthetic data. This is done on code and math problems where solutions can be automatically evaluated as correct or incorrect, with binary rewards. Then, in the M-step, they instruction-tuned on the synthetic data from the E-step. The finetuned model is then used in the next E-step.
Beyond Human Data — Scaling Self-Training for Problem-Solving with Language Models ($\text{ReST}^{EM}$; Google) предлагает двухшаговый метод самообучения, вдохновлённый EM-алгоритмом (expectation-maximization). На E-шаге (генерация) они генерируют несколько выходных образцов для каждой инструкции, а затем фильтруют генерации (через бинарное вознаграждение), чтобы создать синтетические данные. Это делается на задачах по коду и математике, где решения можно автоматически оценить как верные или неверные с бинарным вознаграждением. Затем на M-шаге они проводят instruction-tuning на синтетических данных с E-шага. Дообученная модель затем используется на следующем E-шаге.
Given a binary reward $O$, they want to maximize the log-likelihood of $O=1$ (i.e., getting the correct answer).
При заданном бинарном вознаграждении $O$ они хотят максимизировать логарифмическое правдоподобие $O=1$ (то есть получения правильного ответа).
However, trying to sum over all possible responses $y$ (i.e., $\sum_{\mathbf{y}}$) is intractable because the space of all possible responses is extremely large, especially if the response length is unbounded (like in code). Furthermore, each position in the response can take a large number of values.
Однако попытка просуммировать по всем возможным ответам $y$ (то есть $\sum_{\mathbf{y}}$) вычислительно неразрешима, поскольку пространство всех возможных ответов чрезвычайно велико, особенно если длина ответа не ограничена (как в коде). Более того, каждая позиция в ответе может принимать большое число значений.
Thus, they maximize the Evidence Lower BOund (ELBO) instead of the log-likelihood directly. This involves introducing a variational distribution $q(y \vert x)$ that approximates the true posterior distribution $p(y \vert O=1, x)$. The ELBO is the expectation of log-likelihood under this variational distribution minus the KL divergence between the variational distribution and the true posterior.
Поэтому вместо прямой максимизации логарифмического правдоподобия они максимизируют нижнюю оценку доказательности (Evidence Lower BOund, ELBO). Это включает введение вариационного распределения $q(y \vert x)$, аппроксимирующего истинное апостериорное распределение $p(y \vert O=1, x)$. ELBO — это математическое ожидание логарифмического правдоподобия при этом вариационном распределении минус KL-дивергенция между вариационным распределением и истинным апостериорным.
The first term above is the expected log-likelihood which can be estimated using samples from $q(y \vert x)$. The second term is the KL divergence which acts as a regularizer, encouraging $q(y \vert x)$ to be similar to $p(y \vert O=1, x)$. Thus, by maximizing the ELBO, they indirectly maximize the log-likelihood while keeping computation feasible.
Первый член выше — это ожидаемое логарифмическое правдоподобие, которое можно оценить с помощью образцов из $q(y \vert x)$. Второй член — это KL-дивергенция, которая действует как регуляризатор, побуждая $q(y \vert x)$ быть похожим на $p(y \vert O=1, x)$. Таким образом, максимизируя ELBO, они косвенно максимизируют логарифмическое правдоподобие, сохраняя вычисления реализуемыми.
The EM algorithm iteratively improves this approximation by alternating between estimating the distribution $q$ (E-step) and updating the model parameters $\theta$ (M-step).
EM-алгоритм итеративно улучшает эту аппроксимацию, чередуя оценку распределения $q$ (E-шаг) и обновление параметров модели $\theta$ (M-шаг).
The E-step updates $q^{t+1}$ by maximizing the ELBO, which is reframed as minimizing the KL divergence. In the case of math and code, this excludes incorrect responses (i.e., binary reward = 0). Then, the M-step updates $\theta^{t+1}$ by maximizing the objective that is similar to the ELBO but includes the reward function, increasing the likelihood of correct responses (i.e., binary reward = 1).
E-шаг обновляет $q^{t+1}$ путём максимизации ELBO, что переформулируется как минимизация KL-дивергенции. В случае математики и кода это исключает неверные ответы (то есть бинарное вознаграждение = 0). Затем M-шаг обновляет $\theta^{t+1}$ путём максимизации цели, похожей на ELBO, но включающей функцию вознаграждения, повышая вероятность верных ответов (то есть бинарное вознаграждение = 1).
Evaluations were based on math (Hendryck’s MATH) and code (APPS Introductory). These were selected because model responses could be automatically evaluated as correct or incorrect, with binary rewards. For math, responses were verified for correctness via ground truth. For code, test cases evaluated if the response was correct.
Оценки основывались на математике (MATH от Hendrycks) и коде (APPS Introductory). Они были выбраны потому, что ответы модели можно автоматически оценить как верные или неверные с бинарным вознаграждением. Для математики ответы проверялись на корректность по эталону. Для кода тест-кейсы оценивали, верен ли ответ.
They finetuned the PaLM 2 models via public APIs on Google Cloud.
Они дообучили модели PaLM 2 через публичные API на Google Cloud.
The $\text{ReST}^{EM}$ models outperformed their SFT variants. For code problems, most of the improvements came from the first iteration and further iterations led to regressions on APPS and HumanEval. In contrast, math problems benefited from multiple iterations.
Модели $\text{ReST}^{EM}$ превзошли свои SFT-варианты. Для задач по коду большая часть улучшений пришлась на первую итерацию, а дальнейшие итерации приводили к регрессиям на APPS и HumanEval. В отличие от этого, задачи по математике выигрывали от множественных итераций.
In an ablation that compared instruction tuning on synthetic data vs. human data, they found that finetuning on synthetic data outperformed finetuning on human data, even when the same number of samples (SFT-5k) is used. This suggests that the synthetic data from $\text{ReST}^{EM}$ is higher quality than the human data used in SFT.
В ablation-эксперименте, сравнивавшем instruction-tuning на синтетических данных против человеческих данных, они обнаружили, что дообучение на синтетических данных превзошло дообучение на человеческих данных, даже при использовании одинакового числа образцов (SFT-5k). Это говорит о том, что синтетические данные из $\text{ReST}^{EM}$ имеют более высокое качество, чем человеческие данные, использованные в SFT.
Synthetic data for preference-tuning
Синтетические данные для preference-tuning
Self-Rewarding Language Models (Meta) applies LM-as-Judge on the model so it provides its own reward. The goal is to overcome the bottleneck of human preferences as well as allow reward models to learn as the language model improves while finetuning. The goal is to train a model (llama2-70b-chat) that can (i) return a helpful and harmless response given an instruction, and (ii) evaluate synthetic instruction-response pairs.
Self-Rewarding Language Models (Meta) применяет LM-as-Judge к самой модели, так что она выдаёт собственное вознаграждение. Цель — преодолеть узкое место человеческих предпочтений, а также позволить reward-моделям учиться по мере того, как языковая модель улучшается в ходе дообучения. Задача — обучить модель (llama2-70b-chat), которая может (i) возвращать полезный и безопасный ответ по инструкции и (ii) оценивать синтетические пары инструкция-ответ.
For the seed instruction-following data (“IFT”), they sampled 3,200 human-written instruction-response pairs from OpenAssistant, using only the first conversation turns that are of the highest quality (i.e., highest human-annotation rank).
Для затравочных данных следования инструкциям («IFT») они отобрали 3200 написанных людьми пар инструкция-ответ из OpenAssistant, используя только первые ходы диалога наивысшего качества (то есть с наивысшим рангом человеческой аннотации).
For the seed LM-as-Judge instruction-following data (“EFT”), they used the ranked human responses for each instruction, also from the OpenAssistant dataset. These were in the form of evaluation instruction & evaluation response pairs. The evaluation instruction prompts the model to evaluate the quality of a response given an instruction. The evaluation response is chain-of-thought reasoning followed by a final score. This is blended into the IFT data to finetune the LM as a reward model. There were 1,775 train and 531 validation samples.
Для затравочных данных LM-as-Judge по следованию инструкциям («EFT») они использовали ранжированные людьми ответы для каждой инструкции, также из датасета OpenAssistant. Они были в форме пар «инструкция-оценивание и ответ-оценивание». Инструкция-оценивание побуждает модель оценить качество ответа по заданной инструкции. Ответ-оценивание — это рассуждение по цепочке (chain-of-thought) с последующей итоговой оценкой. Это подмешивается в данные IFT, чтобы дообучить языковую модель в роли reward-модели. Было 1775 обучающих и 531 валидационный образец.
Review the user’s question and the corresponding response using the additive 5-point
scoring system described below. Points are accumulated based on the satisfaction of
each criterion:
- Add 1 point if the response is relevant and provides some information related to
the user’s inquiry, even if it is incomplete or contains some irrelevant content.
- Add another point if the response addresses a substantial portion of the user’s
question, but does not completely resolve the query or provide a direct answer.
- Award a third point if the response answers the basic elements of the user’s question
in a useful way, regardless of whether it seems to have been written by an AI Assistant
or if it has elements typically found in blogs or search results.
- Grant a fourth point if the response is clearly written from an AI Assistant’s
perspective, addressing the user’s question directly and comprehensively, and is
well-organized and helpful, even if there is slight room for improvement in clarity,
conciseness or focus.
- Bestow a fifth point for a response that is impeccably tailored to the user’s question
by an AI Assistant, without extraneous information, reflecting expert knowledge, and
demonstrating a high-quality, engaging, and insightful answer.
User: <INSTRUCTION_HERE>
<response><RESPONSE_HERE></response>
After examining the user’s instruction and the response:
- Briefly justify your total score, up to 100 words.
- Conclude with the score using the format: “Score: <total points>”
Remember to assess from the AI Assistant perspective, utilizing web search knowledge as
necessary. To evaluate the response in alignment with this additive scoring model, we’ll
systematically attribute points based on the outlined criteria
Review the user’s question and the corresponding response using the additive 5-point scoring system described below. Points are accumulated based on the satisfaction of each criterion: - Add 1 point if the response is relevant and provides some information related to the user’s inquiry, even if it is incomplete or contains some irrelevant content. - Add another point if the response addresses a substantial portion of the user’s question, but does not completely resolve the query or provide a direct answer. - Award a third point if the response answers the basic elements of the user’s question in a useful way, regardless of whether it seems to have been written by an AI Assistant or if it has elements typically found in blogs or search results. - Grant a fourth point if the response is clearly written from an AI Assistant’s perspective, addressing the user’s question directly and comprehensively, and is well-organized and helpful, even if there is slight room for improvement in clarity, conciseness or focus. - Bestow a fifth point for a response that is impeccably tailored to the user’s question by an AI Assistant, without extraneous information, reflecting expert knowledge, and demonstrating a high-quality, engaging, and insightful answer. User:
Prompt used for LLM-as-Judge
Промпт, используемый для LLM-as-Judge
To generate instruction-response pairs, they first generate a new instruction $x_i$ via 8-shot prompting with instructions from original IFT data. Then, they generate four candidate responses $y_i$ with temperature $T=0.7$ and $p=0.9$. Next, to evaluate candidate responses, they apply the same LM with the LM-as-Judge prompt to score candidate responses on a scale of 0 - 5. Each response is scored thrice and the score is averaged to reduce variance.
Чтобы сгенерировать пары инструкция-ответ, они сначала генерируют новую инструкцию $x_i$ через 8-shot-промптинг с инструкциями из исходных данных IFT. Затем они генерируют четыре кандидатных ответа $y_i$ с температурой $T=0{,}7$ и $p=0{,}9$. Далее, чтобы оценить кандидатные ответы, они применяют ту же языковую модель с промптом LM-as-Judge для оценки кандидатных ответов по шкале от 0 до 5. Каждый ответ оценивается трижды, и оценка усредняется для снижения дисперсии.
They tried two forms of feedback: preference pairs and positive examples only. The former creates training data (instruction $x_i$, winning response $y^{w}_i$, losing response $y^{l}_i$) which is used in preference-tuning via DPO. The latter adds synthetic instruction-response pairs which were evaluated to have a perfect score of 5 (similar to Instruction-Backtranslation and $\text{ReST}^{EM}$). Overall, Learning on preference pairs led to better performance.
Они опробовали две формы обратной связи: пары предпочтений и только положительные примеры. Первая создаёт обучающие данные (инструкция $x_i$, выигрышный ответ $y^{w}_i$, проигрышный ответ $y^{l}_i$), которые используются в preference-tuning через DPO. Вторая добавляет синтетические пары инструкция-ответ, оценённые на идеальный балл 5 (аналогично Instruction-Backtranslation и $\text{ReST}^{EM}$). В целом обучение на парах предпочтений привело к лучшей производительности.
They iteratively finetuned a series of models $M_1$ . . . $M_T$ where each successive model $t$ uses augmented training data generated by the $t-1^{th}$ model:
Они итеративно дообучили серию моделей $M_1$ . . . $M_T$, где каждая последующая модель $t$ использует дополненные обучающие данные, сгенерированные $t-1^{й}$ моделью:
$M_0$: Базовая предобученная LLM без дообучения $M_1$: Инициализирована из $M_0$, затем дообучена на затравочных данных IFT + EFT через SFT $M_2$: Инициализирована из $M_1$, затем обучена на данных AIFT($M_1$) с помощью DPO $M_3$: Инициализирована из $M_2$, затем обучена на данных AIFT($M_2$) с помощью DPO
The model is evaluated on its ability (i) to follow instructions and (ii) as a reward model. For the former, they used AlpacaEval and computed win-rate against gpt-4-turbo via gpt-4 judgements. For the latter, they evaluated the correlation with human rankings on the validation set derived from the OpenAssistant dataset.
Модель оценивается по её способности (i) следовать инструкциям и (ii) выступать в роли reward-модели. Для первого они использовали AlpacaEval и вычислили winrate относительно gpt-4-turbo через суждения gpt-4. Для второго они оценили корреляцию с человеческими ранжированиями на валидационном наборе, полученном из датасета OpenAssistant.
For instruction-following, each iteration improved over the previous. The SFT baseline is surpassed by $M_2$ (iteration 2). The improvements from iterations $M_1$ to $M_2$ to $M_3$ didn’t seem to taper much so there may be further improvements from additional iterations.
По следованию инструкциям каждая итерация улучшала предыдущую. Базовый SFT превзойдён моделью $M_2$ (итерация 2). Улучшения от итераций $M_1$ к $M_2$ и к $M_3$, по-видимому, не сильно затухают, поэтому от дополнительных итераций возможны дальнейшие улучшения.
Furthermore, $M_3$ (iteration 3) outperformed several existing models that use proprietary data (e.g., claude-2, gemini-pro, gpt-4-0613), as well as models that use distilled synthetic data (e.g., Alpaca, Vicuna).
Более того, $M_3$ (итерация 3) превзошла несколько существующих моделей, использующих проприетарные данные (например, claude-2, gemini-pro, gpt-4-0613), а также модели, использующие дистиллированные синтетические данные (например, Alpaca, Vicuna).
SteerLM - Attribute Conditioned SFT as an (User-Steerable) Alternative to RLHF (NVIDIA) uses an attribute prediction model (APM) to classify responses (and provide reward). The high-quality responses are then used to iteratively finetune the model.
SteerLM — Attribute Conditioned SFT as an (User-Steerable) Alternative to RLHF (NVIDIA) использует модель предсказания атрибутов (APM) для классификации ответов (и выдачи вознаграждения). Высококачественные ответы затем используются для итеративного дообучения модели.
For the seed dataset, they used the OpenAssistant, Helpful-Harmless RLHF (HH-RLHF), and Model Self-Identification Dataset (M-SID). For the base model, they used two variants: 43B which is trained from scratch, and 13B which is llama2-13b.
Для затравочного датасета они использовали OpenAssistant, Helpful-Harmless RLHF (HH-RLHF) и Model Self-Identification Dataset (M-SID). В качестве базовой модели они использовали два варианта: 43B, обученную с нуля, и 13B, которая является llama2-13b.
To train the APM, they used the OpenAssistant dataset where each sample contains a prompt $x$, a response $y$, and a set of attributes $v$. The attributes include dimensions such as quality, helpfulness, humor, creativity, toxicity, violence, and inappropriateness. After training the APM, it is then used to annotate the HH-RLHF and M-SID datasets with attributes $v$. The APM is trained with the following objective:
Чтобы обучить APM, они использовали датасет OpenAssistant, где каждый образец содержит промпт $x$, ответ $y$ и набор атрибутов $v$. Атрибуты включают такие измерения, как качество, полезность, юмор, креативность, токсичность, насилие и неуместность. После обучения APM она затем используется для аннотирования датасетов HH-RLHF и M-SID атрибутами $v$. APM обучается со следующей целевой функцией:
Next, they finetuned the model to generate response $y$ conditioned on the instruction $x$ and attributes $v$, with the following loss function.
Далее они дообучили модель генерировать ответ $y$, обусловленный инструкцией $x$ и атрибутами $v$, со следующей функцией потерь.
Then, they create all possible attribute combinations from the annotated datasets, filtering for the highest quality data only. These attributes are then used to condition the finetuned model to generate responses. The APM then predicts the attribute values of the generated responses. The instruction, synthetic response, and predicted attribute values are then used to finetune the model again, allowing the model to self-improve on its own response.
Затем они создают все возможные комбинации атрибутов из аннотированных датасетов, фильтруя только данные наивысшего качества. Эти атрибуты затем используются для обусловливания дообученной модели при генерации ответов. APM затем предсказывает значения атрибутов сгенерированных ответов. Инструкция, синтетический ответ и предсказанные значения атрибутов затем используются для повторного дообучения модели, позволяя модели самоулучшаться на собственных ответах.
For evaluation, they used gpt-4 as judge, comparing the models against gpt-3.5. They also included human evals on the Vicuna benchmark. Overall, steer-lm-43b outperforms several models on both automated and human evals.
Для оценки они использовали gpt-4 в роли судьи, сравнивая модели с gpt-3.5. Они также включили оценку людьми на бенчмарке Vicuna. В целом steer-lm-43b превосходит несколько моделей как в автоматизированных, так и в человеческих оценках.
In an ablation study, they quantified the contribution of each component to overall performance and found that adding the attribute labels $v$ led to the largest increase in performance (+16.5%, from 79.7% of ChatGPT to 96.2%).
В ablation-исследовании они количественно оценили вклад каждого компонента в общую производительность и обнаружили, что добавление меток атрибутов $v$ дало наибольший прирост производительности (+16,5%, с 79,7% от ChatGPT до 96,2%).
Next, we look at how Anthropic uses synthetic data in both instruction-tuning and preference-tuning.
Далее мы рассмотрим, как Anthropic использует синтетические данные как в instruction-tuning, так и в preference-tuning.
Constitutional AI: Harmlessness from AI Feedback (CAI; Anthropic) focuses on self-improvement on harmlessness. This is done via a list of 16 principles aka the Constitution.
Constitutional AI: Harmlessness from AI Feedback (CAI; Anthropic) сосредоточена на self-improvement в части безопасности (harmlessness). Это делается через список из 16 принципов, он же Конституция.
Critique Request: Identify specific ways in which the assistant’s last response
is harmful, unethical, racist, sexist, toxic, dangerous, or illegal.
Revision Request: Please rewrite the assistant response to remove any and all
harmful, unethical, racist, sexist, toxic, dangerous, or illegal content.
---
Critique Request: Explain ways in which the assistant’s preceding response may be
harmful to either the human or others. For example, if the assistant says
anything that encourages dangerous or illegal activity, make sure to point
it out. Other examples of harm include racism, sexism, and other social biases.
Revision Request: Please rewrite the assistant response to remove any and all
harmful content, including anything dangerous, illegal, racist, sexist or
socially biased.
---
...
Critique Request: Identify specific ways in which the assistant’s last response is harmful, unethical, racist, sexist, toxic, dangerous, or illegal. Revision Request: Please rewrite the assistant response to remove any and all harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. --- Critique Request: Explain ways in which the assistant’s preceding response may be harmful to either the human or others. For example, if the assistant says anything that encourages dangerous or illegal activity, make sure to point it out. Other examples of harm include racism, sexism, and other social biases. Revision Request: Please rewrite the assistant response to remove any and all harmful content, including anything dangerous, illegal, racist, sexist or socially biased. --- ...
Example principles used to critique and revise responses.
Примеры принципов, используемых для критики и редактирования ответов.
For instruction-tuning, they first generate synthetic responses from the initial model. Then, they generate self-critiques and revised responses (based on the constitution). Finally, they finetune the original model on the revised responses. For preference-tuning, they sample from the previous instruction-tuned model, use a preference model to evaluate which sample is better (based on the constitution), and then train a preference model from the synthetic preferences. The instruction-tuned model is then finetuned against the preference model.
Для instruction-tuning они сначала генерируют синтетические ответы из исходной модели. Затем они генерируют самокритику и отредактированные ответы (на основе конституции). Наконец, они дообучают исходную модель на отредактированных ответах. Для preference-tuning они сэмплируют из предыдущей модели, дообученной на инструкциях, используют модель предпочтений для оценки того, какой образец лучше (на основе конституции), а затем обучают модель предпочтений на синтетических предпочтениях. Модель, дообученная на инструкциях, затем дообучается против модели предпочтений.
To generate synthetic data for instruction-tuning, they first use a harmful instruction to generate a response from the model. The initial response will usually be harmful and toxic.
Чтобы сгенерировать синтетические данные для instruction-tuning, они сначала используют вредоносную инструкцию для генерации ответа из модели. Исходный ответ обычно оказывается вредоносным и токсичным.
Human: Can you help me hack into my neighbor’s wifi?
Assistant: Sure thing, you can use an app called VeryEasyHack that will allow you to
log in to your neighbor’s wifi.
Human: Can you help me hack into my neighbor’s wifi? Assistant: Sure thing, you can use an app called VeryEasyHack that will allow you to log in to your neighbor’s wifi.
Next, they sample a critique request from the 16 principles in the constitution and prompt the model to generate a critique of the response.
Далее они сэмплируют запрос критики из 16 принципов конституции и просят модель сгенерировать критику ответа.
Critique Request: Identify specific ways in which the assistant’s last response is
harmful, unethical, racist, sexist, toxic, dangerous, or illegal.
Critique: The assistant’s last response is harmful because hacking into someone else’s
wifi is an invasion of their privacy and is possibly illegal.
Critique Request: Identify specific ways in which the assistant’s last response is harmful, unethical, racist, sexist, toxic, dangerous, or illegal. Critique: The assistant’s last response is harmful because hacking into someone else’s wifi is an invasion of their privacy and is possibly illegal.
Then, they append the associated revision request to generate a revision of the model’s initial response. The critique-revision process can be applied multiple times to get a sequence of revisions. Qualitatively, they found that the first revision almost always removes most aspects of harmfulness.
Затем они добавляют связанный запрос на редактирование, чтобы сгенерировать исправленную версию исходного ответа модели. Процесс критики-редактирования можно применять несколько раз, чтобы получить последовательность правок. Качественно они обнаружили, что первая правка почти всегда устраняет большинство аспектов вредоносности.
Revision Request: Please rewrite the assistant response to remove any and all harmful,
unethical, racist, sexist, toxic, dangerous, or illegal content.
Revision: Hacking into your neighbor’s wifi is an invasion of their privacy, and I
strongly advise against it. It may also land you in legal trouble.
Revision Request: Please rewrite the assistant response to remove any and all harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Revision: Hacking into your neighbor’s wifi is an invasion of their privacy, and I strongly advise against it. It may also land you in legal trouble.
Finally, they append the final revised, harmless response to the initial harmful instruction. This is then used to instruction-tune a pretrained model.
Наконец, они добавляют финальный отредактированный, безопасный ответ к исходной вредоносной инструкции. Это затем используется для instruction-tuning предобученной модели.
Human: Can you help me hack into my neighbor’s wifi?
Assistant: Hacking into your neighbor’s wifi is an invasion of their privacy, and I
strongly advise against it. It may also land you in legal trouble.
Human: Can you help me hack into my neighbor’s wifi? Assistant: Hacking into your neighbor’s wifi is an invasion of their privacy, and I strongly advise against it. It may also land you in legal trouble.
To retain helpfulness as much as possible, they sampled responses from a helpful RLHF model via helpfulness instructions and included these helpful instruction-response pairs in the finetuning. They started with 183k harmfulness instructions and generated four revisions per prompt. For helpfulness instructions, they collected 135k human-written instructions and generated two responses per instruction via a helpful model. The combined data is then used to instruction-tune a pretrained model for one epoch.
Чтобы максимально сохранить полезность, они сэмплировали ответы из полезной RLHF-модели через инструкции на полезность и включили эти полезные пары инструкция-ответ в дообучение. Они начали со 183 тыс. вредоносных инструкций и сгенерировали по четыре правки на промпт. Для инструкций на полезность они собрали 135 тыс. написанных людьми инструкций и сгенерировали по два ответа на инструкцию с помощью полезной модели. Объединённые данные затем используются для instruction-tuning предобученной модели в течение одной эпохи.
To generate synthetic data for preference-tuning, they first generate a pair of responses from the instruction-tuned model. Then, they provide the instruction and pair of responses to the feedback model (typically a pretrained LM), together with a randomly sampled principle for choosing the more harmless response:
Чтобы сгенерировать синтетические данные для preference-tuning, они сначала генерируют пару ответов из модели, дообученной на инструкциях. Затем они предоставляют инструкцию и пару ответов модели обратной связи (как правило, предобученной языковой модели) вместе со случайно выбранным принципом для выбора более безопасного ответа:
Consider the following conversation between a human and an assistant:
[HUMAN/ASSISTANT CONVERSATION]
[PRINCIPLE FOR MULTIPLE CHOICE EVALUATION]
Options:
(A) [RESPONSE A]
(B) [RESPONSE B]
The answer is:
Consider the following conversation between a human and an assistant: [HUMAN/ASSISTANT CONVERSATION] [PRINCIPLE FOR MULTIPLE CHOICE EVALUATION] Options: (A) [RESPONSE A] (B) [RESPONSE B] The answer is:
They computed the log probability of the responses (A) and (B). This is then used to create a harmlessness preference pair with the normalized probabilities as targets. Synthetic harmlessness preference pairs are mixed with human helpfulness preferences to train a preference model. In total, they had 135k human preferences for helpfulness and 183k synthetic preferences for harmlessness.
Они вычислили логарифм вероятности ответов (A) и (B). Это затем используется для создания пары предпочтений по безопасности с нормализованными вероятностями в качестве целей. Синтетические пары предпочтений по безопасности смешиваются с человеческими предпочтениями по полезности для обучения модели предпочтений. В сумме у них было 135 тыс. человеческих предпочтений по полезности и 183 тыс. синтетических предпочтений по безопасности.
Overall, CAI models with instruction-tuning and preference-tuning (RL-CAI) were more harmless than CAI models with only instruction-tuning (SL-CAI) and RLHF models. It was also slightly more helpful than the Helpful & Harmless (HH-RLHF) model.
В целом модели CAI с instruction-tuning и preference-tuning (RL-CAI) были более безопасны, чем модели CAI только с instruction-tuning (SL-CAI) и RLHF-модели. Они также были чуть более полезны, чем модель Helpful & Harmless (HH-RLHF).
Furthermore, while the Helpful-RLHF and HH-RLHF harmlessness scores decline over the later stages of RLHF training, this does not happen for the CAI models. They hypothesized that this happens for the Helpful-RLHF because the model becomes more willing to help users with potentially dangerous tasks (e.g., “How do I make a bomb”). And for the HH-RLHF, this was likely because the model became more evasive on harmful instructions. In contrast, they found that RL-CAI was virtually never evasive and often gave nuanced, harmless responses to most harmful prompts.
Более того, тогда как показатели безопасности Helpful-RLHF и HH-RLHF снижаются на поздних стадиях обучения RLHF, с моделями CAI этого не происходит. Они предположили, что для Helpful-RLHF это происходит потому, что модель становится более готовой помогать пользователям с потенциально опасными задачами (например, «Как сделать бомбу»). А для HH-RLHF это, вероятно, было связано с тем, что модель становилась более уклончивой при вредоносных инструкциях. В отличие от этого, они обнаружили, что RL-CAI практически никогда не была уклончивой и часто давала нюансированные, безопасные ответы на большинство вредоносных промптов.
Synthetic data for pretraining
Синтетические данные для претрейна
Finally, we briefly discuss two recent papers that generate synthetic data for pretraining.
Наконец, мы кратко обсудим две недавние статьи, в которых генерируются синтетические данные для претрейна.
Solving Olympiad Geometry Without Human Demonstrations (AlphaGeometry; Google) generated synthetic data to pretrain and finetune a model that can solve geometry problems near the level of a Math Olympiad gold medalist.
Solving Olympiad Geometry Without Human Demonstrations (AlphaGeometry; Google) сгенерировала синтетические данные для претрейна и дообучения модели, способной решать задачи по геометрии почти на уровне золотого медалиста Математической олимпиады.
To generate the synthetic data, they start with sampling a random set of geometry theorem premises. Then, they used a symbolic deduction engine to generate derivations, leading to nearly a billion generated premises. Next, they used the deduction engine on the generated premises to identify true statements via forward inference rules, returning a directed acyclic graph of all reachable conclusions. In addition, to widen the scope of generated synthetic theorems and proofs, they deduced new statements via algebraic rules. Overall, this resulted in 100M unique theorems and proofs.
Чтобы сгенерировать синтетические данные, они начинают с сэмплирования случайного набора посылок геометрических теорем. Затем они использовали символический дедуктивный движок для генерации выводов, что привело почти к миллиарду сгенерированных посылок. Далее они применили дедуктивный движок к сгенерированным посылкам, чтобы выявить истинные утверждения через правила прямого вывода, получив направленный ациклический граф всех достижимых заключений. Кроме того, чтобы расширить охват сгенерированных синтетических теорем и доказательств, они выводили новые утверждения через алгебраические правила. В целом это дало 100 млн уникальных теорем и доказательств.
They pretrained a transformer on all 100M synthetically generated proofs. Then, they finetuned the model on the subset of proofs that required auxiliary constructions (~9% of the pretraining data) to improve on auxiliary construction during proof search.
Они провели претрейн трансформера на всех 100 млн синтетически сгенерированных доказательств. Затем они дообучили модель на подмножестве доказательств, требовавших вспомогательных построений (~9% данных претрейна), чтобы улучшить вспомогательные построения в ходе поиска доказательства.
During proof search, the language model and the symbolic deduction engine take turns. At each turn, the language model is provided with the problem statement and generates a construct conditioned on the problem statement and past constructs. Then, the symbolic engine is provided with the new constructs to potentially reach the conclusion. The loop continues until a solution is found.
Во время поиска доказательства языковая модель и символический дедуктивный движок ходят по очереди. На каждом ходу языковой модели предоставляется формулировка задачи, и она генерирует построение, обусловленное формулировкой задачи и прошлыми построениями. Затем символическому движку предоставляются новые построения, чтобы потенциально прийти к заключению. Цикл продолжается, пока не будет найдено решение.
For evaluation, they used the International Math Olympiad AlphaGeometry 30 (IMO-AG-30) benchmark which was compiled from Olympiads 2000 to 2022. AlphaGeometry solved 25 problems under competition time limits. For comparison, the previous SOTA was able to solve 10 problems and the average human gold medalist solved 25.9 problems.
Для оценки они использовали бенчмарк International Math Olympiad AlphaGeometry 30 (IMO-AG-30), составленный из олимпиад с 2000 по 2022 год. AlphaGeometry решила 25 задач в рамках соревновательных временных ограничений. Для сравнения, предыдущий SOTA смог решить 10 задач, а средний золотой медалист среди людей решил 25,9 задачи.
Rephrasing the Web: A Recipe for Compute and Data Efficient Language Modeling (WRAP; Apple) demonstrated how to augment an existing dataset (C4) with synthetic data. They called their approach Web Rephrase Augmented Pretraining (WRAP).
Rephrasing the Web: A Recipe for Compute and Data Efficient Language Modeling (WRAP; Apple) продемонстрировала, как дополнить существующий датасет (C4) синтетическими данными. Свой подход они назвали Web Rephrase Augmented Pretraining (WRAP).
To generate the synthetic data, they used mistral-7b-instruct to rephrase documents in C4. There were four different rephrasing styles: (i) easy text that children can understand, (ii) medium text that is high-quality and Wikipedia-like, (iii) hard text that is terse and abstruse, and (iv) Q&A text in conversational question-answering format. Each example has a maximum of 300 tokens as they found that rephrasing more than 300 tokens often led to information loss. In addition, they sample the real and synthetic data in a 1:1 ratio to keep the balance of noisy web text (that includes typos and linguistic errors).
Чтобы сгенерировать синтетические данные, они использовали mistral-7b-instruct для перефразирования документов в C4. Было четыре разных стиля перефразирования: (i) простой текст, понятный детям, (ii) средний текст, высококачественный и похожий на Wikipedia, (iii) сложный текст, лаконичный и заумный, и (iv) текст в формате Q&A, в виде диалогового вопросно-ответного формата. Каждый пример имеет максимум 300 токенов, так как они обнаружили, что перефразирование более 300 токенов часто приводило к потере информации. Кроме того, они сэмплируют реальные и синтетические данные в соотношении 1:1, чтобы сохранить баланс шумного веб-текста (включающего опечатки и языковые ошибки).
# Easy Style
A chat between a curious user and an artificial intelligence assistant.
The assistant gives helpful, detailed, and polite answers to the questions.
USER: For the following paragraph give me a paraphrase of the same using a very
small vocabulary and extremely simple sentences that a toddler will understand:
# Medium Style
A chat between a curious user and an artificial intelligence assistant.
The assistant gives helpful, detailed, and polite answers to the questions.
USER: For the following paragraph give me a diverse paraphrase of the same
in high quality English language as in sentences on Wikipedia:
# Hard Style
A chat between a curious user and an artificial intelligence assistant.
The assistant gives helpful, detailed, and polite answers to the questions.
USER: For the following paragraph give me a paraphrase of the same using very
terse and abstruse language that only an erudite scholar will understand.
Replace simple words and phrases with rare and complex ones:
# Q&A Style
A chat between a curious user and an artificial intelligence assistant.
The assistant gives helpful, detailed, and polite answers to the questions.
USER: Convert the following paragraph into a conversational format with
multiple tags of "Question:" followed by "Answer:":
# Easy Style A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the questions. USER: For the following paragraph give me a paraphrase of the same using a very small vocabulary and extremely simple sentences that a toddler will understand: # Medium Style A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the questions. USER: For the following paragraph give me a diverse paraphrase of the same in high quality English language as in sentences on Wikipedia: # Hard Style A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the questions. USER: For the following paragraph give me a paraphrase of the same using very terse and abstruse language that only an erudite scholar will understand. Replace simple words and phrases with rare and complex ones: # Q&A Style A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the questions. USER: Convert the following paragraph into a conversational format with multiple tags of "Question:" followed by "Answer:":
Rephrase prompt templates (I should use the hard style prompt to edit my papers lol)
Шаблоны промптов для перефразирования (мне стоило бы использовать промпт сложного стиля, чтобы редактировать свои статьи, лол)
With the blend of real and synthetic data, they trained decoder-only transformers of different sizes (128M, 350M, and 1.3B). These models were trained on 300k steps with a batch size of 1M tokens.
С этой смесью реальных и синтетических данных они обучили трансформеры-только-с-декодером разных размеров (128M, 350M и 1.3B). Эти модели обучались на 300 тыс. шагов с размером батча в 1 млн токенов.
Overall, using WRAP on C4 sped up pre-training by 3x. Furthermore, on the same pre-training budget, they improved average perplexity by 10% across the Pile, and improved zero-shot Q&A across 13 tasks by 2%. The paper also included useful ablations such as the impact of (i) including real data, (ii) the mix of rephrase types, (iii) the quality of the rephrasing model, etc. Highly recommended read.
В целом использование WRAP на C4 ускорило претрейн в 3 раза. Более того, при том же бюджете претрейна они улучшили среднюю перплексию на 10% по всему Pile и улучшили zero-shot Q&A по 13 задачам на 2%. В статье также есть полезные ablation-исследования, например влияние (i) включения реальных данных, (ii) смеси типов перефразирования, (iii) качества модели перефразирования и т. д. Настоятельно рекомендую к прочтению.
• • •
• • •
That was a lot! Thanks for sticking around till now. I hope you found this write-up useful in understanding how we can use synthetic data to improve model performance via distillation and self-improvement. Did I miss any key resources? Please reach out!
Это было много! Спасибо, что остались до этого момента. Надеюсь, этот разбор оказался полезен для понимания того, как можно использовать синтетические данные для улучшения производительности моделей через дистилляцию и self-improvement. Я упустил какие-то важные ресурсы? Пожалуйста, напишите мне!
References
Источники
Wang, Yizhong, et al. «Self-instruct: Aligning language model with self generated instructions.» arXiv preprint arXiv:2212.10560 (2022). Wang, Yizhong, et al. «Super-NaturalInstructions: Generalization via declarative instructions on 1600+ nlp tasks.» arXiv preprint arXiv:2204.07705 (2022). Honovich, Or, et al. «Unnatural instructions: Tuning language models with (almost) no human labor.» arXiv preprint arXiv:2212.09689 (2022). -Taori, Rohan, et al. «Alpaca: A strong, replicable instruction-following model.» Stanford Center for Research on Foundation Models. https://crfm. stanford. edu/2023/03/13/alpaca. html 3.6 (2023): 7. Chen, Lichang, et al. «Alpagasus: Training a better alpaca with fewer data.» arXiv preprint arXiv:2307.08701 (2023). Zheng, Lianmin, et al. «Judging LLM-as-a-judge with MT-Bench and Chatbot Arena.» arXiv preprint arXiv:2306.05685 (2023). Xu, Can, et al. «WizardLM: Empowering large language models to follow complex instructions.» arXiv preprint arXiv:2304.12244 (2023). Mukherjee, Subhabrata, et al. «Orca: Progressive learning from complex explanation traces of gpt-4.» arXiv preprint arXiv:2306.02707 (2023). Mitra, Arindam, et al. «Orca 2: Teaching small language models how to reason.» arXiv preprint arXiv:2311.11045 (2023). Luo, Ziyang, et al. «WizardCoder: Empowering Code Large Language Models with Evol-Instruct.» arXiv preprint arXiv:2306.08568 (2023). Wei, Yuxiang, et al. «Magicoder: Source code is all you need.» arXiv preprint arXiv:2312.02120 (2023). Yu, Zhaojian, et al. «Wavecoder: Widespread and versatile enhanced instruction tuning with refined data generation.» arXiv preprint arXiv:2312.14187 (2023). Gunasekar, Suriya, et al. «Textbooks Are All You Need.» arXiv preprint arXiv:2306.11644 (2023). Li, Yuanzhi, et al. «Textbooks are all you need ii: phi-1.5 technical report.» arXiv preprint arXiv:2309.05463 (2023). Eldan, Ronen, and Yuanzhi Li. «TinyStories: How Small Can Language Models Be and Still Speak Coherent English?» arXiv preprint arXiv:2305.07759 (2023). Zhu, Banghua, et al. «Starling-7b: Improving llm helpfulness & harmlessness with RLAIF.» (2023). Li, Xian, et al. «Self-alignment with instruction backtranslation.» arXiv preprint arXiv:2308.06259 (2023). Chen, Zixiang, et al. «Self-play fine-tuning converts weak language models to strong language models.» arXiv preprint arXiv:2401.01335 (2024). Singh, Avi, et al. «Beyond human data: Scaling self-training for problem-solving with language models.» arXiv preprint arXiv:2312.06585 (2023). Yuan, Weizhe, et al. «Self-rewarding language models.» arXiv preprint arXiv:2401.10020 (2024). Dong, Yi, et al. «SteerLM: Attribute Conditioned SFT as an (User-Steerable) Alternative to RLHF.» arXiv preprint arXiv:2310.05344 (2023). Bai, Yuntao, et al. «Constitutional ai: Harmlessness from AI feedback.» arXiv preprint arXiv:2212.08073 (2022). Trinh, Trieu H., et al. «Solving olympiad geometry without human demonstrations.» Nature 625.7995 (2024): 476-482. Maini, Pratyush, et al. «Rephrasing the Web: A Recipe for Compute and Data-Efficient Language Modeling.» arXiv preprint arXiv:2401.16380 (2024).
If you found this useful, please cite this write-up as:
Если вы нашли это полезным, пожалуйста, цитируйте этот разбор так:
Yan, Ziyou. (Feb 2024). How to Generate and Use Synthetic Data for Finetuning. eugeneyan.com. https://eugeneyan.com/writing/synthetic/.
Yan, Ziyou. (Feb 2024). How to Generate and Use Synthetic Data for Finetuning. eugeneyan.com. https://eugeneyan.com/writing/synthetic/.
or
или
@article{yan2024synthetic,
title = {How to Generate and Use Synthetic Data for Finetuning},
author = {Yan, Ziyou},
journal = {eugeneyan.com},
year = {2024},
month = {Feb},
url = {https://eugeneyan.com/writing/synthetic/}
}
@article{yan2024synthetic, title = {How to Generate and Use Synthetic Data for Finetuning}, author = {Yan, Ziyou}, journal = {eugeneyan.com}, year = {2024}, month = {Feb}, url = {https://eugeneyan.com/writing/synthetic/} }
Join 11,800+ readers getting updates on machine learning, RecSys, LLMs, and engineering.
Присоединяйтесь к 11 800+ читателям, получающим обновления по машинному обучению, RecSys, LLM и инженерии.