Skip to content

Port additional changes made to the transductive alignment model - #426

Open
pmachapman wants to merge 1 commit into
mainfrom
port-additional-transductive
Open

pmachapman wants to merge 1 commit into
mainfrom
port-additional-transductive

Conversation

@pmachapman

@pmachapman pmachapman commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #372.

The Python binding for num_training_alignments is currently broken (see sillsdev/thot#20), so I get the property using introspection.


This change is Reviewable

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.79%. Comparing base (e063f28) to head (5dfb75b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #426      +/-   ##
==========================================
+ Coverage   92.64%   92.79%   +0.14%     
==========================================
  Files         424      424              
  Lines       27014    27074      +60     
==========================================
+ Hits        25028    25123      +95     
+ Misses       1986     1951      -35     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


@pytest.mark.parametrize("symmetrized", [False, True])
@pytest.mark.parametrize("index", [-1, 8])
def test_get_training_alignment_out_of_range(symmetrized: bool, index: int) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: F1. This test never closes its model. The native thot models are left for the garbage collector to clean up, against the AGENTS.md rule to close models according to their contracts. test_word_align_corpus_falls_back_to_inference_when_alignments_not_retained (tests/translation/test_corpus_ops.py:86) has the same gap. Wrapping the body in with model: fixes it, the way test_emit_training_alignments_symmetrized_with_empty_segments already does. The older tests in this file have the same gap, so this is optional.

@claude

claude Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor
  1. Approve. The port matches Port transductive alignment model machine#466: the training_alignment_count > 0 fallback, the min count, the range check, the shape guard for symmetrizing, and the whitespace tokenization before training.
  2. Nothing blocks merging. The only finding is Low: F1, test models that are never closed, at tests/translation/thot/test_thot_word_alignment_model_trainer.py:151.
  3. Counts: 0 Critical, 0 Important, 1 Low.
  4. What I ran with sil-thot 3.5.3:
    • I saved models trained with and without emit_training_alignments, then reloaded them. With emission on, the reloaded model reports training_alignment_count == 4 and returns alignment 0. With it off, the count is 0 and the call raises IndexError. So NmtEngineBuildJob still uses the transductive path, because its factory always emits.
    • num_training_alignments exists on thot.alignment.AlignmentModel.
    • CI (gh pr checks 426): 16 builds pass; macOS 3.11, macOS 3.13 and claude-review are pending.
  5. Not verified: the jobs on the pending macOS builds. I also did not check what the thot binding bug behind the getattr TODO actually is (Add the Python bindings for num_training_alignments thot#20).

Public API changes, all matching C#:

  • TransductiveWordAlignmentModel.get_training_alignment on the thot models now raises IndexError out of range. It used to return a degenerate matrix.
  • training_alignment_count now counts retained alignments, not sentence pairs.
  • The sil-machine[thot] extra moves from sil-thot~=3.5.2 to ==3.5.3.

Upstream in sillsdev/machine, not this PR:

  • IParallelTextCorpusExtensions.cs WordAlign takes the transductive path whenever the count is above 0. A model trained on fewer rows than the corpus therefore raises partway through iteration. I reproduced this: a model trained on 2 rows, aligning 3 rows, raised IndexError at index 2.
  • WordAlignParallelTextCorpusBase.cs passes through the input corpus's tokenized flags, but the trained corpus yields whitespace-tokenized rows. Calling .tokenize(LatinWordTokenizer()) on the result re-splits test., so the word pairs index the wrong tokens.

Findings: F1 new.

Reviewed at 5dfb75b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port additional changes made to 'Port transductive alignment model'

2 participants