-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dolphin gpt 3.5 data mix #3606
Merged
Merged
Dolphin gpt 3.5 data mix #3606
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from pathlib import Path | ||
from typing import List, Optional, Union | ||
|
||
import numpy as np | ||
import requests | ||
from datasets import load_dataset | ||
from model_training.custom_datasets.formatting import DatasetEntrySft, Role, Utterance | ||
|
@@ -193,3 +194,61 @@ def __getitem__(self, idx): | |
] | ||
|
||
return DatasetEntrySft(conversation=conv_utt, system_message=instruction) | ||
|
||
|
||
class DolphinMix(Dataset): | ||
name = "dophin-mix" | ||
|
||
def __init__(self, cache_dir, num_samples=100000, max_char_len=8000, seed=42): | ||
self.dataset = load_dataset( | ||
"ehartford/dolphin", data_files="flan5m-alpaca-uncensored.jsonl", cache_dir=cache_dir | ||
) | ||
self.dataset = self.dataset["train"].shuffle(seed).select(range(num_samples)) | ||
self.max_char_len = max_char_len | ||
instructions = set([item["instruction"] for item in self.dataset]) | ||
|
||
self.conversations = [] | ||
for inst in instructions: | ||
data_sample = self.dataset.filter(lambda example: example["instruction"] == inst) | ||
available_indices = np.arange(0, len(data_sample)).tolist() | ||
removed_indices = [] | ||
for idx in available_indices: | ||
conversation_len = len(inst) | ||
if idx not in removed_indices and conversation_len < self.max_char_len: | ||
conversation = {"conversation": []} | ||
conversation["instruction"] = inst | ||
input, output = [data_sample[idx][key] for key in ("input", "output")] | ||
conversation["conversation"].append({"input": input, "output": output}) | ||
conversation_len += len(input) + len(output) | ||
removed_indices.append(idx) | ||
while conversation_len < self.max_char_len: | ||
indices_to_pick = np.setdiff1d(available_indices, removed_indices) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generating the indices to pick set every time seems a bit costly .. but since it is only done during startup it might be ok. |
||
if len(indices_to_pick) > 0: | ||
idx = np.random.choice(indices_to_pick, size=1)[0] | ||
input, output = [data_sample[int(idx)][key] for key in ("input", "output")] | ||
conversation["conversation"].append({"input": input, "output": output}) | ||
conversation_len += len(input) + len(output) | ||
removed_indices.append(idx) | ||
else: | ||
break | ||
|
||
self.conversations.append(conversation) | ||
|
||
def __len__(self): | ||
return len(self.conversations) | ||
|
||
def __getitem__(self, idx): | ||
conversation, instruction = [self.conversations[idx][key] for key in ("conversation", "instruction")] | ||
conversation = [(item["input"], item["output"]) for item in conversation] | ||
conversation = list(sum(conversation, ())) | ||
conv_utt: list[Utterance] = [ | ||
( | ||
Utterance( | ||
text=conv, | ||
role=Role.prompter if i % 2 == 0 else Role.assistant, | ||
) | ||
) | ||
for i, conv in enumerate(conversation) | ||
] | ||
|
||
return DatasetEntrySft(conversation=conv_utt, system_message=instruction) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have used shuffle(seed) too in my code ;-) .. will update later.