Skip to content

Commit

Permalink
SlimOrca aligner
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Mueller committed Feb 8, 2024
1 parent d0daaa0 commit 36d7a75
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/llmtuner/data/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,32 @@ def convert_sharegpt(examples: Dict[str, List[Any]], dataset_attr: "DatasetAttr"
if len(messages) == 0:
continue

n_sys = 0
prompt = []
response = []
for turn_idx, message in enumerate(messages):
if turn_idx % 2 == 0:
accept_tags = [dataset_attr.user_tag, dataset_attr.observation_tag]
else:
accept_tags = [dataset_attr.assistant_tag, dataset_attr.function_tag]

if message[dataset_attr.role_tag] not in accept_tags:
accept_tags = [dataset_attr.user_tag, dataset_attr.observation_tag, dataset_attr.assistant_tag, dataset_attr.function_tag]

if message[dataset_attr.role_tag] == "system":
outputs["system"].append(message[dataset_attr.content_tag])
n_sys += 1
elif message[dataset_attr.role_tag] not in accept_tags:
print("sytem attr", dataset_attr.system)
print("accepted tags", accept_tags)
raise ValueError("Invalid role tag in {}.".format(messages))

prompt.append(
{"role": tag_mapping[message[dataset_attr.role_tag]], "content": message[dataset_attr.content_tag]}
)
else:
prompt.append(
{"role": tag_mapping[message[dataset_attr.role_tag]], "content": message[dataset_attr.content_tag]}
)

last_message = prompt.pop(-1)
response.append(last_message)
outputs["prompt"].append(prompt)
outputs["response"].append(response)
outputs["system"].append(examples[dataset_attr.system][i] if dataset_attr.system else "")
if n_sys == 0:
outputs["system"].append(examples[dataset_attr.system][i] if dataset_attr.system else "")
outputs["tools"].append(examples[dataset_attr.tools][i] if dataset_attr.tools else "")

assert n_sys <= 1
return outputs


Expand Down

0 comments on commit 36d7a75

Please sign in to comment.