Skip to content

Fix bug with marker location prediction - #495

Merged
pmachapman merged 1 commit into
masterfrom
fix-predict-marker-location
Sep 7, 2026
Merged

Fix bug with marker location prediction#495
pmachapman merged 1 commit into
masterfrom
fix-predict-marker-location

Conversation

@pmachapman

@pmachapman pmachapman commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes a minor bug noticed in PredictMarkerLocation() when investigating token alignment issues on the current build of Serval QA.

int bestNumCrossings = 40000;

The previous logic of 200 ^ 2 meant 200 XOR 2, i.e. 202.

targetHypothesis = alignedTargetTokens[hypothesis < 0 ? alignedTargetTokens.Count - 1 : 0];

There is no -1 element in a list - I assume the last item was intended (see the Python implementation). That said this code isn't even called, as there is no hypothesis -1.


This change is Reviewable

@pmachapman
pmachapman requested a review from Enkidu93 September 7, 2026 03:12
@pmachapman
pmachapman force-pushed the fix-predict-marker-location branch from f937fc4 to f92f870 Compare September 7, 2026 03:35
@pmachapman pmachapman changed the title Fix bugs with marker location prediction Fix bug with marker location prediction Sep 7, 2026
@codecov-commenter

codecov-commenter commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.51%. Comparing base (d734722) to head (7185d27).

Files with missing lines Patch % Lines
...hine/Corpora/PlaceMarkersUsfmUpdateBlockHandler.cs 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #495   +/-   ##
=======================================
  Coverage   73.51%   73.51%           
=======================================
  Files         451      451           
  Lines       37692    37692           
  Branches     5183     5183           
=======================================
  Hits        27708    27708           
  Misses       8845     8845           
  Partials     1139     1139           

☔ 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.

@Enkidu93

Enkidu93 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks for catching these, Peter. This is why I much prefer porting C# to python than python to C# - sorry about that! Regarding the negative hypotheses, I found Isaac's notes and he did experiment with hypotheses like [-2,-1,0,1,2] but found that [0,1,2] gave him the best results. I assume these fixes didn't improve the marker placement in your problem project, right?

@Enkidu93 Enkidu93 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@Enkidu93 reviewed all commit messages and made 2 comments.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on pmachapman).


src/SIL.Machine/Corpora/PlaceMarkersUsfmUpdateBlockHandler.cs line 368 at r1 (raw file):

            int[] hypotheses = { 0, 1, 2 };
            int bestHypothesis = -1;
            int bestNumCrossings = 40000; // A large number

Maybe 40_000 just for slightly better readability?

@pmachapman
pmachapman force-pushed the fix-predict-marker-location branch from f92f870 to ddfe7ec Compare September 7, 2026 19:35
@pmachapman
pmachapman requested a review from Enkidu93 September 7, 2026 19:44

@pmachapman pmachapman left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I assume these fixes didn't improve the marker placement in your problem project, right?

The improved for some cases, and made others far worse (particularly one of the unit tests). My original PR had a -1 case, which I removed due to one of the tests cases failing spectacularly (the markers were thrown into the preceding verse).

@pmachapman made 1 comment and resolved 1 discussion.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on Enkidu93).

@pmachapman
pmachapman force-pushed the fix-predict-marker-location branch from ddfe7ec to 12dedfb Compare September 7, 2026 19:45
@pmachapman
pmachapman force-pushed the fix-predict-marker-location branch from 12dedfb to 7185d27 Compare September 7, 2026 19:46
@pmachapman
pmachapman merged commit ae09770 into master Sep 7, 2026
3 of 4 checks passed
@pmachapman
pmachapman deleted the fix-predict-marker-location branch September 7, 2026 22:03
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.

3 participants