Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"LaTeX OCR Environment","local":"latex-ocr-environment","sections":[{"title":"Episode","local":"episode","sections":[],"depth":2},{"title":"Task API","local":"task-api","sections":[],"depth":2},{"title":"Run locally","local":"run-locally","sections":[],"depth":2},{"title":"Configuration (env vars)","local":"configuration-env-vars","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/entry/start.B5gQcl3H.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/DHLZrqMK.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/DfHjNWj2.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/entry/app.CsPaKcGJ.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/Ba1drWuH.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/Bx1vlXKe.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/PGLvW8OU.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/nodes/0.DtJt93Mx.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/CFswWuIO.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/nodes/2.Bf6GWt5G.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/chunks/Bln0COW0.js" rel="modulepreload"> | |
| <!--r51zn7--><meta name="hf:doc:metadata" content="{"title":"LaTeX OCR Environment","local":"latex-ocr-environment","sections":[{"title":"Episode","local":"episode","sections":[],"depth":2},{"title":"Task API","local":"task-api","sections":[],"depth":2},{"title":"Run locally","local":"run-locally","sections":[],"depth":2},{"title":"Configuration (env vars)","local":"configuration-env-vars","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/openenv/pr_1003/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="latex-ocr-environment" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#latex-ocr-environment"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>LaTeX OCR Environment</span></h1><!--]--><!----> <p>A dataset-backed, single-step (bandit) RL environment for <strong>image → LaTeX</strong> transcription, served through OpenEnv.</p> <ul><li><strong>Task</strong>: the agent is shown an image of a math/text expression and must | |
| return its LaTeX source.</li> <li><strong>Dataset</strong>: tasks are served from a Hugging Face dataset (default <a href="https://huggingface.co/datasets/unsloth/LaTeX_OCR" rel="nofollow"><code>unsloth/LaTeX_OCR</code></a>: <code>image</code> + <code>text</code> columns, <code>train</code>/<code>test</code> splits) via the OpenEnv <strong>Task API</strong>.</li> <li><strong>Reward</strong>: <code>[(1 - exact_weight) * (1 - CER) + exact_weight * exact_match] * length_factor</code>, | |
| where <code>CER</code> is the normalized character edit distance over whitespace-stripped | |
| LaTeX. With the default <code>exact_weight=0.4</code> (tunable via <code>LATEX_OCR_EXACT_WEIGHT</code>), | |
| partial answers score in <code>[0, 0.6]</code>; only an exact match reaches <code>1.0</code>. | |
| Computed <strong>server-side</strong> against the hidden ground truth — the agent never | |
| sees the target on <code>reset</code>. Dense and smooth, for stable RL training.</li> <li><strong>Length guard</strong>: because the score is whitespace-insensitive, a policy could | |
| otherwise emit the correct answer followed by unlimited whitespace and still | |
| score <code>1.0</code> — a reward hack that, in RL, shows up as completions drifting to | |
| the generation-length cap. <code>length_factor</code> decays the reward once the <em>raw</em> prediction grows past <code>LATEX_OCR_OVERLONG_RATIO</code>× the target length (default <code>4.0</code>, floor <code>LATEX_OCR_OVERLONG_FLOOR=80</code> chars); normal LaTeX spacing is well | |
| within the allowance. Set <code>LATEX_OCR_OVERLONG_RATIO=0</code> to disable. The rubric | |
| also strips code fences / <code>$</code>-delimiters from raw completions itself.</li></ul> <!--[1--><h2 class="relative group"><a id="episode" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#episode"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Episode</span></h2><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class=" "><!---->reset(<span class="hljs-attribute">split</span>=<span class="hljs-string">"test"</span>, <span class="hljs-attribute">index</span>=0) -> observation { image_base64, prompt, <span class="hljs-built_in">..</span>. } # target hidden | |
| <span class="hljs-keyword">step</span>(LatexOCRAction(<span class="hljs-attribute">latex</span>=…)) -> reward, <span class="hljs-attribute">done</span>=<span class="hljs-literal">True</span> { target_latex, exact_match, char_error_rate }<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="task-api" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#task-api"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Task API</span></h2><!--]--><!----> <table><thead><tr><th>Endpoint</th><th>Purpose</th></tr></thead><tbody><tr><td><code>GET /latex_ocr_env/splits</code></td><td>list splits (<code>train</code>, <code>test</code>)</td></tr><tr><td><code>POST /latex_ocr_env/num_tasks</code></td><td>row count for a split</td></tr><tr><td><code>POST /latex_ocr_env/tasks</code></td><td>all task specs for a split (materialize mode)</td></tr><tr><td><code>POST /latex_ocr_env/task</code></td><td>one task by <code>{split, index}</code></td></tr><tr><td><code>POST /latex_ocr_env/task_range</code></td><td>slice <code>{split, start, stop}</code></td></tr></tbody></table> <p>Client helpers: <code>env.list_splits()</code>, <code>env.num_tasks(split)</code>, <code>env.get_task(split, index)</code>, <code>env.get_task_range(split, start, stop)</code>. | |
| In stream mode, full task enumeration returns <code>501</code>; use <code>num_tasks</code> and | |
| bounded <code>get_task_range</code> calls instead.</p> <!--[1--><h2 class="relative group"><a id="run-locally" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#run-locally"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Run locally</span></h2><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-comment"># From the repo root. LATEX_OCR_SPLITS=test avoids the 380MB train download.</span> | |
| PYTHONPATH=src:envs/latex_ocr_env LATEX_OCR_SPLITS=<span class="hljs-built_in">test</span> \ | |
| uv run --with datasets --with pillow --with fastapi --with uvicorn --with websockets \ | |
| uvicorn server.app:app --host 0.0.0.0 --port 8000<!----></pre></div><!----> <p>Then drive it (needs <code>HF_TOKEN</code> for the real VLM policy):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!---->HF_TOKEN=hf_xxx PYTHONPATH=src \ | |
| uv run --with datasets --with pillow --with requests --with websockets --with openai \ | |
| python envs/latex_ocr_env/validate.py --<span class="hljs-built_in">split</span> <span class="hljs-built_in">test</span> --num 3 \ | |
| --model Qwen/Qwen2.5-VL-7B-Instruct<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="configuration-env-vars" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#configuration-env-vars"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Configuration (env vars)</span></h2><!--]--><!----> <table><thead><tr><th>Var</th><th>Default</th><th>Meaning</th></tr></thead><tbody><tr><td><code>LATEX_OCR_DATASET</code></td><td><code>unsloth/LaTeX_OCR</code></td><td>source dataset</td></tr><tr><td><code>LATEX_OCR_IMAGE_COLUMN</code></td><td><code>image</code></td><td>image column</td></tr><tr><td><code>LATEX_OCR_TEXT_COLUMN</code></td><td><code>text</code></td><td>ground-truth LaTeX column</td></tr><tr><td><code>LATEX_OCR_SPLITS</code></td><td><code>train,test</code></td><td>splits to expose</td></tr><tr><td><code>LATEX_OCR_MAX_ROWS</code></td><td>—</td><td>cap rows per split (dev)</td></tr><tr><td><code>LATEX_OCR_EXACT_WEIGHT</code></td><td><code>0.4</code></td><td>exact-match share of the reward</td></tr><tr><td><code>LATEX_OCR_OVERLONG_RATIO</code></td><td><code>4.0</code></td><td>raw length allowed as a multiple of the target before the reward decays (<code>0</code> disables the length guard)</td></tr><tr><td><code>LATEX_OCR_OVERLONG_FLOOR</code></td><td><code>80</code></td><td>minimum allowed raw length (chars) for short targets</td></tr></tbody></table> <p>Swap in any <code>(image, latex)</code> dataset by pointing <code>LATEX_OCR_DATASET</code> at it (and | |
| the column vars if they differ).</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/openenv/blob/main/docs/source/environments/latex_ocr.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_vrn1ay = { | |
| base: "/docs/openenv/pr_1003/en", | |
| assets: "/docs/openenv/pr_1003/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/openenv/pr_1003/en/_app/immutable/entry/start.B5gQcl3H.js"), | |
| import("/docs/openenv/pr_1003/en/_app/immutable/entry/app.CsPaKcGJ.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 2], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 20.4 kB
- Xet hash:
- 7aa7ab65cf413e7519aab2f5a259305854692eefe85c9efca7240db636b402c9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.