Skip to navigation

nemo_gym.utils.text

View as Markdown

Text helpers for user-facing messages.

Module Contents

Functions

NameDescription
_hydra_parses_toWhether Hydra’s override grammar reads text back as exactly expected, type included.
did_you_meanA Did you mean \X`?fragment for the closest candidate tovalue, or ""` if none is close enough.
hydra_literalvalue as an override value that Hydra parses back to the same value and type.
hydra_quoteSingle-quote value as a literal for Hydra’s override grammar, so it parses back to the same string.

API

nemo_gym.utils.text._hydra_parses_to(
text: str,
expected: typing.Any
) -> bool

Whether Hydra’s override grammar reads text back as exactly expected, type included.

nemo_gym.utils.text.did_you_mean(
value: str,
candidates: typing.Iterable[str]
) -> str

A Did you mean \X`?fragment for the closest candidate tovalue, or ""` if none is close enough.

nemo_gym.utils.text.hydra_literal(
value: typing.Any
) -> str

value as an override value that Hydra parses back to the same value and type.

A string is written as it is when Hydra reads it back unchanged, and as a quoted literal otherwise, so "1" stays a string and nightly(run) survives the grammar. The check is Hydra’s own parser, not a guess at its rules. Numbers, booleans, null and lists of those are written in their own syntax; anything else raises ValueError.

nemo_gym.utils.text.hydra_quote(
value: str
) -> str

Single-quote value as a literal for Hydra’s override grammar, so it parses back to the same string.

json.dumps is not that encoder: Hydra keeps \uXXXX, \t and a doubled backslash literally, so a Unicode or backslash-containing filename would reach the command under another name. Hydra un-escapes a backslash only when its run ends at a quote character, so only those runs (and the quote itself) are escaped here. Everything else, Unicode included, is passed through unchanged.