Image-Text-to-Text
MLX
Safetensors
Chinese
ocr
rare-characters
ids
ideographic-description-sequence
glyphwiki
palaeography
Instructions to use OpenGlyph/OpenGlyph-OCR-IDS with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use OpenGlyph/OpenGlyph-OCR-IDS with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("OpenGlyph/OpenGlyph-OCR-IDS") config = load_config("OpenGlyph/OpenGlyph-OCR-IDS") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Card: crops of real lines with their sources, whole-page reading (read_page, --page), what was taken from han2ids
a9aab5c verified Download openglyph_ocr_ids/__init__.py from OpenGlyph/OpenGlyph-OCR-IDS: direct link, hf CLI and curl.
- Browser
- Download file 2.81 kB
-
https://huggingface.co/OpenGlyph/OpenGlyph-OCR-IDS/resolve/main/openglyph_ocr_ids/__init__.py
- Command line
-
hf download hf://OpenGlyph/OpenGlyph-OCR-IDS/openglyph_ocr_ids/__init__.py
-
curl -L -o __init__.py https://huggingface.co/OpenGlyph/OpenGlyph-OCR-IDS/resolve/main/openglyph_ocr_ids/__init__.py
2.81 kB
| """OpenGlyph-OCR-IDS: read one line of printed scholarly Chinese that holds rare characters, glyphs without a code point | |
| and characters no catalogue has. (MLX, Apple silicon. Run from a local copy of the repository this package lies in.) | |
| python -m openglyph_ocr_ids LINE.png [LINE2.png ...] [--options] | |
| from openglyph_ocr_ids import load, read_line, atoms | |
| ocr = load() # the folder that holds this package; or load('/path/to/the/folder') | |
| out = read_line(ocr, 'line.png') | |
| print(out['text']) # 𤪷也庾參與<gw:u2ff1-u65e5-u82f1><gw:ebag_s093-073><ids>⿰拍嵩</ids>了燒造磚瓦的工作 | |
| out = read_line(ocr, 'line.png', options=True) | |
| print(out['options']) # the second option of every place that has one | |
| What comes back (read_line): | |
| text Unicode text; a glyph without a code point that GlyphWiki has is written <gw:NAME> (its GlyphWiki name); a | |
| glyph that has neither is written <ids>IDS</ids>, an Ideographic Description Sequence the model composed | |
| ids every IDS the model wrote and what it spells: a coded character (a rare character read by its parts), a glyph | |
| with a token, or a new glyph | |
| options with options=True: beside the text, the other reading of every place that has one | |
| The picture: one horizontal line of print as cropped from a page (the lines measured are about 100 to 150 pixels high | |
| in the papers, 96 in the special test). A whole page can be read in one go with read_page(ocr, 'page.png') (or | |
| --page): it is then read as OpenGlyph-OCR-0 reads, without IDS; cutting the page into lines reads better. | |
| How a line is read. Four sets of weights work in one model built on Xiaomi-OCR-0: the reader (OpenGlyph-OCR-0, unchanged) | |
| writes the line; the opener says where a glyph needs an IDS; at such a place, and wherever the reader itself writes a rare | |
| character or a glyph token, the glyph is read two more ways -- unfolded (cut into its parts by a program, the parts read | |
| by the part reader) and spelt (by the speller, from the glyph as it stands); what stands is decided by both and by gates | |
| chosen on tuning lines (reading.json). The modules: build (the model, the interface), unfold (the reading of a line), | |
| spell (the speller), unfold_cut and unfold_search (the cuts), canon (canonical forms), decode (constrained decoding). | |
| The versions matter: this was measured with mlx 0.32.3, mlx-vlm 0.3.12, transformers 5.18.0, tokenizers 0.23.2 | |
| (requirements.txt); torch and torchvision are there for the pictures only (with torchvision, transformers prepares them | |
| as they were prepared when the model was measured).""" | |
| from .build import load,read_line,read_page,readable,atoms | |
| __all__=['load','read_line','read_page','readable','atoms'] | |