Run this model with HF Jobs

Run OpenTensorLab/OCRia-1-W4A16-LLM-Compressor on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-LLM-Compressor. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-LLM-Compressor on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-LLM-Compressor. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
File size: 3,953 Bytes
d8db4d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright (c) 2026 LlamaIndex, Inc. All rights reserved.
# Licensed under the OCRia-1 Model and Code License (LICENSE at the root of this repository).
# This is not open-source software: see the license for permitted uses.
"""Conservative reading-order paths for horizontal left-to-right prose.

Coordinates are image pixels. Word indices remain in transcript order, so a
skipped attention outlier does not delete text. Unsupported layouts fall back
to the existing spatial clustering; tables, formulas and code bypass this pass.
"""

import statistics

from .rust import get_rust

WordBox = list[float]


def paragraph_paths(boxes: list[WordBox]) -> list[list[int]] | None:
    """Return supported word paths, splitting column continuations when justified.

    Nearby words form spatial components. Within each component a longest path
    must move right on a line or wrap onto a nearby lower line. At least 60% of
    words must support the result. Separate columns need three words each and
    non-interleaving transcript spans; otherwise keep only a dominant path.
    """
    rust = get_rust()
    if rust is not None:
        return rust.paragraph_paths(boxes)
    n = len(boxes)
    if n < 3:
        return None
    height = max(1.0, statistics.median(b[3] - b[1] for b in boxes))
    parents = list(range(n))

    def root(i: int) -> int:
        while parents[i] != i:
            parents[i] = parents[parents[i]]
            i = parents[i]
        return i

    # Proximity establishes candidate columns independently of transcript order.
    # A nearby wrong word can still belong here; the ordered path rejects it.
    for i, a in enumerate(boxes):
        for j in range(i):
            b = boxes[j]
            dx = max(a[0] - b[2], b[0] - a[2], 0.0)
            dy = max(a[1] - b[3], b[1] - a[3], 0.0)
            if dx <= 4 * height and dy <= 2.5 * height:
                parents[root(i)] = root(j)
    components: dict[int, list[int]] = {}
    for i in range(n):
        components.setdefault(root(i), []).append(i)

    paths: list[list[int]] = []
    for indices in components.values():
        lengths = {i: 1 for i in indices}
        previous: dict[int, int] = {}
        for pos, i in enumerate(indices):
            b = boxes[i]
            for j in indices[:pos]:
                a = boxes[j]
                overlap = min(a[3], b[3]) - max(a[1], b[1])
                same_line = overlap >= 0.5 * min(a[3] - a[1], b[3] - b[1])
                if same_line:
                    follows = (
                        b[0] >= a[0] + 0.2 * height
                        and -0.5 * height <= b[0] - a[2] <= 4 * height
                    )
                else:
                    follows = (
                        b[1] >= a[1] + 0.5 * height
                        and b[1] - a[3] <= 2.5 * height
                        and b[0] < a[2]
                    )
                if follows and lengths[j] + 1 > lengths[i]:
                    lengths[i] = lengths[j] + 1
                    previous[i] = j
        end = max(indices, key=lengths.__getitem__)
        path = [end]
        while path[-1] in previous:
            path.append(previous[path[-1]])
        path.reverse()
        if len(path) >= 3:
            paths.append(path)
    if not paths:
        return None
    paths.sort(key=lambda p: p[0])
    if sum(map(len, paths)) < 0.6 * n:
        return None

    # A column jump is supported by whole runs, not a single distant word.
    # Interleaved components or a jump down to unrelated text are ambiguous.
    for left, right in zip(paths, paths[1:]):
        gutter = min(boxes[i][0] for i in right) - max(boxes[i][2] for i in left)
        if (
            left[-1] >= right[0]
            or gutter < height
            or boxes[right[0]][1] > boxes[left[-1]][1]
        ):
            dominant = max(paths, key=len)
            return [dominant] if len(dominant) >= 0.6 * n else None
    return paths