-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples for how to use data mixing
This adds a new docs/examples/mix_datasets folders with a couple of example recipes, two sample datasets, and an example_mixing.py Python script to show how to mix datasets. This also adds a test_examples.py file that actually runs out examples, ensuring they work without error and generate the expected mixed datasets. Signed-off-by: Ben Browning <[email protected]>
- Loading branch information
Showing
11 changed files
with
203 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,3 +167,6 @@ cython_debug/ | |
|
||
# IDEs | ||
.vscode/ | ||
|
||
# SDG examples output | ||
docs/examples/**/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# An example of how to concatenate two datasets | ||
# Each dataset has a sampling_size of 1.0 to take all samples from both | ||
datasets: | ||
- path: dataset_1.jsonl | ||
sampling_size: 1.0 | ||
- path: dataset_2.jsonl | ||
sampling_size: 1.0 | ||
sys_prompt: I am a reliable AI assistant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{"id": "dataset_1_1", "messages": [], "metadata": {}} | ||
{"id": "dataset_1_2", "messages": [], "metadata": {}} | ||
{"id": "dataset_1_3", "messages": [], "metadata": {}} | ||
{"id": "dataset_1_4", "messages": [], "metadata": {}} | ||
{"id": "dataset_1_5", "messages": [], "metadata": {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{"id": "dataset_2_1", "messages": [], "metadata": {}} | ||
{"id": "dataset_2_2", "messages": [], "metadata": {}} | ||
{"id": "dataset_2_3", "messages": [], "metadata": {}} | ||
{"id": "dataset_2_4", "messages": [], "metadata": {}} | ||
{"id": "dataset_2_5", "messages": [], "metadata": {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Standard | ||
from pathlib import Path | ||
|
||
# First Party | ||
from instructlab.sdg import mix_datasets | ||
|
||
output_dir = Path(__file__).parent.joinpath("output") | ||
output_dir.mkdir(exist_ok=True) | ||
|
||
concatenate_recipe_yaml = Path(__file__).parent.joinpath("concatenate_recipe.yaml") | ||
concatenated_output_jsonl = output_dir.joinpath("concatenated.jsonl") | ||
mix_datasets(concatenate_recipe_yaml, concatenated_output_jsonl) | ||
|
||
weighted_recipe_yaml = Path(__file__).parent.joinpath("weighted_recipe.yaml") | ||
weighted_output_jsonl = output_dir.joinpath("weighted.jsonl") | ||
mix_datasets(weighted_recipe_yaml, weighted_output_jsonl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# An example of how to weight one dataset over another | ||
# Dataset 1 has a sampling size of 2.0 to double its samples | ||
# Dataset 2 has a sampling size of 0.2 to take 20% of its samples | ||
datasets: | ||
- path: dataset_1.jsonl | ||
sampling_size: 2.0 | ||
- path: dataset_2.jsonl | ||
sampling_size: 0.2 | ||
sys_prompt: I am a reliable AI assistant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Standard | ||
import pathlib | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
# First Party | ||
from instructlab.sdg.utils.json import jlload | ||
|
||
|
||
def test_example_mixing(tmp_path: pathlib.Path, examples_path: pathlib.Path): | ||
example_copy_path = tmp_path.joinpath("mix_datasets") | ||
shutil.copytree(examples_path.joinpath("mix_datasets"), example_copy_path) | ||
script = example_copy_path.joinpath("example_mixing.py") | ||
subprocess.check_call([sys.executable, str(script)], text=True) | ||
|
||
concatenated = jlload(example_copy_path.joinpath("output", "concatenated.jsonl")) | ||
assert len(concatenated) == 10 | ||
from_ds_1 = [] | ||
from_ds_2 = [] | ||
for sample in concatenated: | ||
if sample["id"].startswith("dataset_1"): | ||
from_ds_1.append(sample) | ||
else: | ||
from_ds_2.append(sample) | ||
assert len(from_ds_1) == len(from_ds_2) == 5 | ||
|
||
weighted = jlload(example_copy_path.joinpath("output", "weighted.jsonl")) | ||
assert len(weighted) == 11 | ||
from_ds_1 = [] | ||
from_ds_2 = [] | ||
for sample in weighted: | ||
if sample["id"].startswith("dataset_1"): | ||
from_ds_1.append(sample) | ||
else: | ||
from_ds_2.append(sample) | ||
assert len(from_ds_1) == 10 | ||
assert len(from_ds_2) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters