Repository navigation
Replies: 3 comments
|
Follow-up: score whole candidate words, not only seams Section 1 above describes a seam classifier with approximately 8 characters of context on each side. That description does not state the main idea clearly. A reader does not judge each gap alone. A reader recognizes the words, and a confident word makes the reader tolerant of irregular spacing inside it. I propose to make this part of the design, not something that the model must learn by chance. Formulation. Score each candidate segmentation of a line with two independent terms, and find the best one with a Viterbi search over a lattice of candidate chunks (up to approximately 30 characters):
Example: @morten-lagabote's tight line (letter gap 0.69 of the line's space):
Consequences:
Implementation. For version 1, I recommend two separate models: a multilingual character LM of a few MB, and the small geometric model. One weight balances the two terms. Each decision then shows its lexical and geometric scores, so a maintainer can see why a line was split. The LM trains on plain text, and the geometric model and the weight train on synthetic PDFs. A neural semi-CRF that scores spans and seams together can come later, if it measures better. Sections 2 and 3 and the four questions do not change. The convention questions now concern only the geometric term, because the lexical term is flat in math. |
|
And for full disclosure I'll note that we'll be experimenting with models having deeper context, as I think that's needed to deal with real-world variability even just within lines. |
|
Thank you, @wittjeff, for the kind mention, and for taking the time to turn what we found on docling-parse#385 into a proposal. I can't judge the model design, but a written convention for dot leaders, inline math and CJK would help anyone reading these tables later, so I'm glad that is part of it. This is my first attempt to contribute to an open source project. I'm a clinical pharmacist, and I came to Docling because I rely on it to read drug monographs. Finding that a table cell was wrong, tracing why, and having it taken seriously by people who know the code has been rewarding. It is a different way of contributing from what I'm used to, and I'm grateful for how welcoming this community has been. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Context: docling-parse#385, #358, #377, #383
Summary
7.22.1 introduced a 0.35 cap on word gaps. Since then, several issues and PRs have tried to fix how docling-parse divides glyphs into words: #358, #377, #383 and #385. Each fix adds or tunes a threshold on the gap size. Each fix repairs one class of lines and moves part of the error to a different class.
I propose a different method:
This proposal does not replace #385. #385 is a clear improvement over 7.22.2 and must continue. This is a longer-term direction. I ask for feedback from the maintainers before I build it.
The problem: gap size alone cannot decide
@morten-lagabote posted a good example on #385: Innst. 240 S (2013–2014). This is justified Norwegian text with letter-spaced emphasis. The tracking is 1.65 pt per letter, and the tracked word contains no space characters. Results on the 70 tracked runs in the document:
The first line of page 1 has three populations of gaps:
PresidentskapetThe letter gap is 0.69 of the space. If a threshold on gap ÷ space keeps this word whole, it also joins real words on other lines. The gate sweep on #385 showed the same result from the other direction: a gate at 0.6 of a space joins a dot leader, and a gate at 1.0 joins
:,in maths.The unit is also important. On #383 I showed that a gap in em separates seams that the current unit (the advances of the two neighbouring glyphs) cannot separate. But some lines have no geometric clue in any unit. In
elsevier-00.pdf,a r t i c l e i n f ohas a uniform tracking of 0.44 em and no space glyph. The geometry cannot show wherearticleends.A reader settles these cases with vocabulary:
Pr e s i den tis not Norwegian, andarticle infois two English words. A model can use the same evidence.Proposal
1. Tag each seam
For each pair of adjacent glyphs on a text line, predict
joinorboundary. This is the same formulation as character-tagging word segmentation for Chinese, Japanese and Thai, with geometric features added.The model only makes a decision at each seam. It cannot add, remove or change a character, so the text stays exact. A VLM or an OCR engine cannot give this guarantee.
Inputs for each seam:
Geometry:
nominal_text_height)Producer intent:
TJadjustmentTcandTwvalues in effectget_space_width()used its flat 500 fallbackThe parser already reads
TcandTwinto the text state (char_spacingandword_spacinginpdf_states/text.h) and uses them to place glyphs. The cells do not keep them today. Tracking set withTcis close to a direct label.Context: the font and size on each side, any font change, the Unicode script and category.
Characters: approximately 8 characters on each side.
The model is a small character encoder (approximately 0.2 to 1 M parameters). A linear-chain CRF on top decodes one line at a time. Thus a tracked run gets one decision and does not get partial joins (
rada,oriz,ー病in the #385 sweep). The #383 measurement made approximately 2,000 seam decisions per page. At a few microseconds per seam on a CPU, this cost is small compared with layout analysis or TableFormer.2. Keep a few fixed rules around the model
Use rules where the answer is clear and structural:
Mn/Me), for example the Arabic sukun.3. Write a convention for text that is not words
Much of the discussion on #377, #385 and #358 is about convention, not recognition. Are
Θ=,α∈and:,regressions? At present, the published groundtruth decides this implicitly, and nobody wrote down its rules. I propose that we agree these points in this thread:Ref.,hoeveelheden),).The written convention can be reviewed. It also becomes the training labels. With thresholds, the convention exists only as a side effect of the tuning.
4. Fall back to geometry when the characters give no signal
For math fonts,
GLYPH<n>text, mis-encoded text and scripts outside the training data, the model must not use the character features and must use geometry only. The target for these classes is "no worse than the current rules".Expected effect by case
These are predictions, not measurements.
Presidentskapet(0.69 of a space)Tcacross linesa r t i c l e i n f o(0.44 em)TJcorrectionsInf lammation(#377)TJvalue and vocabularyRelated Work(#383)rada,oriz,ー病. . . . .Θ=,:,, TeX thin spaces文 責 : 事 務 室Training and evaluation data
Space restoration on plain text. Remove the spaces from multilingual text, and train the character part of the model to restore them. The supply of this data has no practical limit.
Synthetic PDFs. Render known text with Chromium, LuaLaTeX and a word processor. Use random letter-spacing, justification, kerning, per-glyph
TJcorrections, fonts without a space glyph, suppressed spaces, CJK, Arabic and maths. The labels are exact, and they follow the convention.Real PDFs, for evaluation only:
ActualTextThe pdfium text layer is a weak reference. It is not reliable for justified CJK text or for TeX thin spaces (see #383).
The model must not train on the issue PDFs. They are the test of whether it generalizes.
Where the model can be
I recommend option A first. We can consider option B after a measured result.
Plan for a first measurement
Tc,Tw,TJ, the space-glyph state, the space-width fallback flag, a leader flag and a math-font flag.Success criterion: better than all current builds on the recognition classes (tracking,
TJcorrections, wide glyphs), and no worse on leaders, math and text with no character signal.Limits
ID A 12). The CRF and the explicit-space features help, but this needs a specific test.Questions for the maintainers
Thanks to @seanphopkins for the sweeps and traces on #385, @morten-lagabote for the Norwegian data, and @rasokiwayami for the verification on #377.
All reactions