fix(docx-core): add Jaccard fallback for word-level inplace changes#79
Merged
stevenobiajulu merged 1 commit intomainfrom Apr 4, 2026
Merged
fix(docx-core): add Jaccard fallback for word-level inplace changes#79stevenobiajulu merged 1 commit intomainfrom
stevenobiajulu merged 1 commit intomainfrom
Conversation
…DF degenerates TF-IDF cosine similarity fails with few paragraphs: shared words get IDF = log(N/N) = 0, making cosine similarity ≈ 0 even for paragraphs that share most of their content. This caused entire paragraphs to be marked as deleted+inserted instead of producing word-level inline tracked changes. Add gap-scoped Jaccard word-overlap fallback that runs after TF-IDF for any unmatched groups. Jaccard uses absolute word overlap, immune to corpus size. Also remove the redundant TF-IDF recheck gate on matched groups — once groups are matched, always run atom-level LCS. - TF-IDF first pass (handles 10+ paragraph documents well) - Jaccard fallback for leftovers (catches few-paragraph degenerate case) - Both gap-scoped (preserves document order, prevents #61 regression) - Both at 0.25 threshold - Add unit test for Jaccard fallback - Add integration test asserting word-level granularity on multiple-changes Closes #78
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #78 — inplace mode showed full paragraph replacement instead of word-level inline changes when documents had few paragraphs.
Root cause: TF-IDF cosine similarity degenerates with few paragraphs. Each paragraph is a "document" in the IDF corpus. With 2 paragraphs, every shared word gets
IDF = log(2/2) = 0, making cosine similarity ≈ 0 regardless of actual content overlap. The algorithm then skips atom-level LCS and marks entire paragraphs as deleted+inserted.Fix: Add gap-scoped Jaccard word-overlap fallback after TF-IDF. Jaccard uses absolute word overlap (immune to corpus size). Also remove the redundant TF-IDF similarity recheck on already-matched groups.
Design
Before / After
Before
After
Calibration data
TF-IDF with 2 paragraphs = 0.000 for everything. Jaccard correctly catches A and B.
Test plan
tsc --noEmitpasses cleancomputeGroupLcsmatches with Jaccard when TF-IDF degeneratesmultiple-changesfixture produces ≤6 insertions/deletions (word-level)