{ "cells": [ { "cell_type": "markdown", "id": "ad0cf718", "metadata": {}, "source": [ "# Inspect recognition confidence" ] }, { "cell_type": "code", "execution_count": 1, "id": "52bd6cd3", "metadata": { "execution": { "iopub.execute_input": "2026-11-01T08:10:32.293019Z", "iopub.status.busy": "2026-11-01T08:10:32.292937Z", "iopub.status.idle": "2026-11-01T08:10:39.898217Z", "shell.execute_reply": "2026-11-01T08:10:39.897743Z" }, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Loaded DBNet detector (CPU, threads=8)\n", "Loaded SVTR recognizer (vocab=185 chars, CPU, threads=8)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[occular] LM (pure Python): compact_lm.npz (268 MB), unigrams=2010937, alpha=0.5 beta=1.0 beam=100\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "0.996 СУПЕРМАРКЕТ «ВОЛГА-МАРКЕТ»\n", "0.996 ул. Белинского, 32\n", "0.859 00О «Волга-Ритейл»\n", "0.993 ИНН 5260998741\n", "0.996 Смена 214\n", "0.983 Чек 1073\n", "0.996 КАССОВЫЙ ЧЕК / ПРИХОД\n", "0.985 Молоко «Летний луг» 3,2% 900 мл\n" ] } ], "source": [ "from occular import ocr_detailed\n", "\n", "lines = ocr_detailed(\"receipt.jpg\")\n", "for line in lines[:8]:\n", " print(round(line[\"confidence\"], 3), line[\"text\"])" ] }, { "cell_type": "code", "execution_count": 2, "id": "e043265b", "metadata": { "execution": { "iopub.execute_input": "2026-11-01T08:10:39.899210Z", "iopub.status.busy": "2026-11-01T08:10:39.899063Z", "iopub.status.idle": "2026-11-01T08:10:49.500805Z", "shell.execute_reply": "2026-11-01T08:10:49.500232Z" }, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Loaded SVTR recognizer (vocab=185 chars, CPU, threads=8)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "WITH LANGUAGE MODEL — lines 21–22\n", "224, 16\n", "1,246 ×179,90\n", "\n", "WITHOUT LANGUAGE MODEL — lines 21–22\n", "224,16\n", "1,246 x 179,90\n" ] } ], "source": [ "from occular import ocr\n", "\n", "with_context = ocr(\"receipt.jpg\", lm=True)\n", "without_context = ocr(\"receipt.jpg\", lm=False)\n", "print(\"WITH LANGUAGE MODEL — lines 21–22\")\n", "print(\"\\n\".join(with_context.splitlines()[20:22]))\n", "print(\"\\nWITHOUT LANGUAGE MODEL — lines 21–22\")\n", "print(\"\\n\".join(without_context.splitlines()[20:22]))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }