Skip to content
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

update alpaca gpt4 to use dataset entry #2869

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions model/model_training/custom_datasets/qa_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def __init__(self, cache_dir: str | Path, mode: str = "sft", input_max_length: i
if (conv := self._process_instruction(line, input_max_length)) is not None:
self.rows.append(conv)

def _process_instruction(self, row: dict[str, str], input_max_length: int) -> list[str] | None:
def _process_instruction(self, row: dict[str, str], input_max_length: int) -> DatasetEntry | None:
# discard items that are too long: when checked on 2023-04-17 this was just one item in the whole dataset with length above 2048.
# And 12 above 1024.
if len(row["input"]) + len(row["instruction"]) > input_max_length:
Expand All @@ -615,18 +615,17 @@ def _process_instruction(self, row: dict[str, str], input_max_length: int) -> li
or (not row["input"])
or (row["input"].lower() in row["instruction"].lower())
):
return [row["instruction"], row["output"]]
return DatasetEntry(questions=[row["instruction"]], answers=[row["output"]])
# Concatenate the instruction and input.
else:
linking_char = random.choice(LINKING_CHARS)
return [f"{row['instruction']}{linking_char}{row['input']}", row["output"]]
return DatasetEntry(
questions=[f"{row['instruction']}{linking_char}{row['input']}"], answers=[row["output"]]
)

def __len__(self) -> int:
return len(self.rows)

def __getitem__(self, index: int) -> list[str] | tuple[str]:
dialogue: list[str] = self.rows[index]
if self.mode == "sft":
return dialogue
elif self.mode == "rl":
return tuple(dialogue[:-1])
dialogue = self.rows[index]
return dialogue