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

Fixing canary prompts for back compatibility #9836

Merged
merged 17 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nemo/collections/asr/data/audio_to_text_lhotse_prompted.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def canary(
role="assistant",
slots={
"text": ' '.join(s.text for s in cut.supervisions),
formatter.PROMPT_LANGUAGE_SLOT: cut.custom["target_lang"],
formatter.PROMPT_LANGUAGE_SLOT: cut.supervisions[0].language,
},
),
]
Expand Down
17 changes: 13 additions & 4 deletions nemo/collections/common/prompts/canary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ class CanaryPromptFormatter(PromptFormatter):
"template": f"{CANARY_BOS}|source_lang||task||target_lang||pnc|",
"slots": {
"source_lang": Modality.Text,
"task": Modality.TextLiteral("asr", "ast", "s2t_translation", "<|transcribe|>", "<|translate|>"),
"task": Modality.TextLiteral(
"asr", "ast", "translate", "transcribe", "s2t_translation", "<|transcribe|>", "<|translate|>"
),
"target_lang": Modality.Text,
"pnc": Modality.TextLiteral("yes", "no", "<|pnc|>", "<|nopnc|>"),
"pnc": Modality.TextLiteral(
"yes", "no", "true", "True", "false", "False", "1", "0", "pnc", "nopnc", "<|pnc|>", "<|nopnc|>"
),
},
},
OUTPUT_ROLE: {
Expand Down Expand Up @@ -54,13 +58,18 @@ def map_manifest_values_to_special_tokens(slot_values: dict[str, str]) -> dict[s

k = "pnc"
if k in slot_values and slot_values[k] not in (CANARY_PNC, CANARY_NOPNC):
slot_values[k] = CANARY_PNC if slot_values[k] in ("yes", "1", "True", "true") else CANARY_NOPNC
slot_values[k] = CANARY_PNC if slot_values[k] in ("yes", "1", "True", "true", "pnc") else CANARY_NOPNC
any_special_token_present = True

# Note: we re-map 'taskname' to 'task' for compatibility with earlier versions of Canary training.
for k in ("task", "taskname"):
if k in slot_values and slot_values[k] not in ("<|transcribe|>", "<|translate|>"):
slot_values["task"] = "<|transcribe|>" if slot_values[k] == "asr" else "<|translate|>"
if slot_values[k] in {"translate", "ast", "s2t_translation"}:
slot_values["task"] = "<|translate|>"
elif slot_values[k] in {"transcribe", "asr"}:
slot_values["task"] = "<|transcribe|>"
else:
assert False, f"Task {slot_values[k]} invalid task for slot {k}"
any_special_token_present = True

# Auto-inject which tokenizer to look up in CanaryTokenizer if not provided,
Expand Down
Loading