Translation Sub-skill
Use this sub-skill when a future task needs to run, validate, or troubleshoot
checkpoint-based translation for this repository. It covers the translate.py
command-line flow, the load_model checkpoint contract, and programmatic beam
search with transformer.Translator.
Route here for
- Validating that a training checkpoint has the
settings and model objects
required by translation before launching a full decode job.
- Checking that a preprocessing pickle contains the
test split plus source and
target vocab fields expected by translate.py.
- Running the repository translation CLI on CPU or CUDA and interpreting its
output file.
- Calling
Translator.translate_sentence(...) directly for one already-tokenized
source sentence.
- Debugging beam-size, max-length, token-index, batch-size-one, and device
mismatches in translation.
Do not route here for
- Creating preprocessing pickles or BPE files; use the data-preparation skill.
- Producing checkpoints, choosing training flags, or optimizer settings; use the
training skill.
- Explaining encoder/decoder internals, attention masks, or parameter shapes in
depth; use the model-architecture skill.
Start with these references
- Read references/cli-reference.md for the
translate.py CLI, checkpoint/data-pickle schemas, device selection, and
output semantics.
- Read references/api-reference.md for
programmatic
Transformer construction from a checkpoint and
Translator.translate_sentence beam search usage.
- Read references/troubleshooting.md when a
checkpoint, pickle, vocabulary, CUDA, OOV, or BPE issue appears.
Bundled helpers
scripts/inspect_checkpoint.py safely gates unpickling behind an explicit
trust flag, then validates checkpoint and optional data-pickle schemas.
scripts/translation_smoke_check.py builds a tiny deterministic Transformer
and exercises Translator beam search without requiring a trained checkpoint
or dataset.
Typical preflight sequence:
python scripts/inspect_checkpoint.py \
--checkpoint trained.chkpt --data-pkl m30k_deen_shr.pkl --trust-inputs
python scripts/translation_smoke_check.py \
--repo-root /path/to/repo --device cpu
Operating reminders
translate.py loads the checkpoint with torch.load(..., map_location=device)
and then reconstructs Transformer from checkpoint['settings']; incompatible
settings are found only at load time unless you preflight them.
- The CLI sets
opt.cuda = not opt.no_cuda; on a CPU-only host include
-no_cuda or model/device transfer will fail.
Translator.translate_sentence asserts batch size one. For multiple examples,
iterate one sentence at a time or implement a separate batched decoder.
- Output lines are target-vocabulary token strings with
<s> and </s> removed
by simple string replacement. BPE post-decoding is marked TODO/not ready in the
repository flow.
1---2name: translation-23description: "Run and troubleshoot checkpoint translation with translate.py and4 transformer.Translator beam search."5disable-model-invocation: true6metadata:7 source: https://skillmd.com/skills/vectorspacelab/translation-28 disco-role: operating9license: MIT10---1112# Translation Sub-skill1314Use this sub-skill when a future task needs to run, validate, or troubleshoot15checkpoint-based translation for this repository. It covers the `translate.py`16command-line flow, the `load_model` checkpoint contract, and programmatic beam17search with `transformer.Translator`.1819## Route here for2021- Validating that a training checkpoint has the `settings` and `model` objects22 required by translation before launching a full decode job.23- Checking that a preprocessing pickle contains the `test` split plus source and24 target vocab fields expected by `translate.py`.25- Running the repository translation CLI on CPU or CUDA and interpreting its26 output file.27- Calling `Translator.translate_sentence(...)` directly for one already-tokenized28 source sentence.29- Debugging beam-size, max-length, token-index, batch-size-one, and device30 mismatches in translation.3132## Do not route here for3334- Creating preprocessing pickles or BPE files; use the data-preparation skill.35- Producing checkpoints, choosing training flags, or optimizer settings; use the36 training skill.37- Explaining encoder/decoder internals, attention masks, or parameter shapes in38 depth; use the model-architecture skill.3940## Start with these references41421. Read [references/cli-reference.md](references/cli-reference.md) for the43 `translate.py` CLI, checkpoint/data-pickle schemas, device selection, and44 output semantics.452. Read [references/api-reference.md](references/api-reference.md) for46 programmatic `Transformer` construction from a checkpoint and47 `Translator.translate_sentence` beam search usage.483. Read [references/troubleshooting.md](references/troubleshooting.md) when a49 checkpoint, pickle, vocabulary, CUDA, OOV, or BPE issue appears.5051## Bundled helpers5253- `scripts/inspect_checkpoint.py` safely gates unpickling behind an explicit54 trust flag, then validates checkpoint and optional data-pickle schemas.55- `scripts/translation_smoke_check.py` builds a tiny deterministic Transformer56 and exercises `Translator` beam search without requiring a trained checkpoint57 or dataset.5859Typical preflight sequence:6061```bash62python scripts/inspect_checkpoint.py \63 --checkpoint trained.chkpt --data-pkl m30k_deen_shr.pkl --trust-inputs64python scripts/translation_smoke_check.py \65 --repo-root /path/to/repo --device cpu66```6768## Operating reminders6970- `translate.py` loads the checkpoint with `torch.load(..., map_location=device)`71 and then reconstructs `Transformer` from `checkpoint['settings']`; incompatible72 settings are found only at load time unless you preflight them.73- The CLI sets `opt.cuda = not opt.no_cuda`; on a CPU-only host include74 `-no_cuda` or model/device transfer will fail.75- `Translator.translate_sentence` asserts batch size one. For multiple examples,76 iterate one sentence at a time or implement a separate batched decoder.77- Output lines are target-vocabulary token strings with `<s>` and `</s>` removed78 by simple string replacement. BPE post-decoding is marked TODO/not ready in the79 repository flow.