--- title: CTFAlign Demo emoji: ๐Ÿ”— colorFrom: indigo colorTo: green sdk: gradio sdk_version: 5.9.1 app_file: app.py pinned: false license: mit short_description: Demo of document-level word alignment algorithms. preload: - Qwen/Qwen3-Embedding-4B - jhu-clsp/mmBERT-base - sentence-transformers/LaBSE --- # CTFAlign ยท Document-level Word Alignment โ€” demo Interactive demo for [CTFAlign](https://github.com/ZurichNLP/CTFAlign): choose one of the models from the paper's experiments, paste a document pair, and see the predicted word alignments. Hover a word to highlight its aligned counterpart(s) in the other text. - **Model** โ€” experiment models with a document-level tuned layer: Qwen3-Embedding-4B (default), LaBSE, mmBERT-base. - **Method** โ€” `ctfalign` (default) or `mdpalign`. - **Mode** โ€” base SimAlign variant: `argmax` (default) or `itermax`. - **Language pair** โ€” used to pick the tuned encoder layer; leave on `(auto)` to use the modal-best layer for the model. **Layer** and **k/w** are auto-filled with the values actually used (from the model / language pair / method) and stay editable. - **Context window** โ€” small-context models (LaBSE, 512 tokens) warn when a document exceeds their limit; prefer a larger-context model for long documents. ## Exporting Alignment Labels Export alignment (accordion under the viewer) exposes the same result the `/align` endpoint returns: the Pharaoh string (`i-j โ€ฆ`,), a copyable table of aligned pairs with their surface strings, the full JSON, and `alignment.json` / `alignment.talp` downloads. Programmatically: ```python from gradio_client import Client r = Client("miwytt/ctfalign-demo").predict( "mmBERT-base", "ctfalign", "argmax", "(auto)", None, None, source_text, target_text, "auto", api_name="/align", ) r["pharaoh"] # "0-0 1-1 2-4 ..." r["alignment"] # [{"s": 0, "t": 0, "source": "...", "target": "..."}, ...] r["source"]["units"] # the units the indices refer to r["source"]["level"] # "word" or "subword" (indices are meaningless without it) r["config"] # model / method / mode / layer / k / segmentation actually used r["baseline_simalign"] # the unconstrained SimAlign baseline, same shapes r["warnings"] # e.g. the text was chunked -> degraded quality ``` Run locally with `pip install -r requirements.txt gradio && python app.py`.