microsoft / kosmos-2.5

huggingface.co
Total runs: 100.0K
24-hour runs: 0
7-day runs: 6.6K
30-day runs: -425
Model's Last Updated: August 28 2025
image-text-to-text

Introduction of kosmos-2.5

Model Details of kosmos-2.5

Kosmos-2.5

Microsoft Document AI | GitHub

Model description

Kosmos-2.5 is a multimodal literate model for machine reading of text-intensive images. Pre-trained on large-scale text-intensive images, Kosmos-2.5 excels in two distinct yet cooperative transcription tasks: (1) generating spatially-aware text blocks, where each block of text is assigned its spatial coordinates within the image, and (2) producing structured text output that captures styles and structures into the markdown format. This unified multimodal literate capability is achieved through a shared decoder-only auto-regressive Transformer architecture, task-specific prompts, and flexible text representations. We evaluate Kosmos-2.5 on end-to-end document-level text recognition and image-to-markdown text generation. Furthermore, the model can be readily adapted for any text-intensive image understanding task with different prompts through supervised fine-tuning, making it a general-purpose tool for real-world applications involving text-rich images. This work also paves the way for the future scaling of multimodal large language models.

Kosmos-2.5: A Multimodal Literate Model

NOTE:

Since this is a generative model, there is a risk of hallucination during the generation process, and it CAN NOT guarantee the accuracy of all OCR/Markdown results in the images.

Use with transformers:
from PIL import Image
import requests
import torch
from transformers import AutoProcessor, Kosmos2_5ForConditionalGeneration
import re
repo = "microsoft/kosmos-2.5"
device = "cuda:0"
dtype = torch.bfloat16
model = Kosmos2_5ForConditionalGeneration.from_pretrained(repo, device_map=device, torch_dtype=dtype)
processor = AutoProcessor.from_pretrained(repo)
url = "https://huggingface.co/kirp/kosmos2_5/resolve/main/receipt_00008.png"
image = Image.open(requests.get(url, stream=True).raw)
prompt = "<ocr>" # <md>
inputs = processor(text=prompt, images=image, return_tensors="pt")
height, width = inputs.pop("height"), inputs.pop("width")
raw_width, raw_height = image.size
scale_height = raw_height / height
scale_width = raw_width / width
inputs = {k: v.to(device) if v is not None else None for k, v in inputs.items()}
inputs["flattened_patches"] = inputs["flattened_patches"].to(dtype)
generated_ids = model.generate(
    **inputs,
    max_new_tokens=1024,
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
def postprocess(y, scale_height, scale_width):
    y = y.replace(prompt, "")
    if "<md>" in prompt:
        return y
    pattern = r"<bbox><x_\d+><y_\d+><x_\d+><y_\d+></bbox>"
    bboxs_raw = re.findall(pattern, y)
    lines = re.split(pattern, y)[1:]
    bboxs = [re.findall(r"\d+", i) for i in bboxs_raw]
    bboxs = [[int(j) for j in i] for i in bboxs]
    info = ""
    for i in range(len(lines)):
        box = bboxs[i]
        x0, y0, x1, y1 = box
        if not (x0 >= x1 or y0 >= y1):
            x0 = int(x0 * scale_width)
            y0 = int(y0 * scale_height)
            x1 = int(x1 * scale_width)
            y1 = int(y1 * scale_height)
            info += f"{x0},{y0},{x1},{y0},{x1},{y1},{x0},{y1},{lines[i]}"
    return info
output_text = postprocess(generated_text[0], scale_height, scale_width)
print(output_text)
55,595,71,595,71,629,55,629,1
82,595,481,595,481,635,82,635,[REG] BLACK SAKURA
716,590,841,590,841,629,716,629,45,455
55,637,71,637,71,672,55,672,1
82,637,486,637,486,675,82,675,COOKIE DOH SAUCES
818,632,843,632,843,668,818,668,0
51,683,71,683,71,719,51,719,1
82,683,371,683,371,719,82,719,NATA DE COCO
820,677,845,677,845,713,820,713,0
32,770,851,770,851,811,32,811,Sub Total 45,455
28,811,853,811,853,858,28,858,PB1 (10%) 4,545
28,857,855,857,855,905,28,905,Rounding 0
24,905,858,905,858,956,24,956,Total 50,000
17,1096,868,1096,868,1150,17,1150,Card Payment 50,000
Citation

If you find Kosmos-2.5 useful in your research, please cite the following paper:

@article{lv2023kosmos,
  title={Kosmos-2.5: A multimodal literate model},
  author={Lv, Tengchao and Huang, Yupan and Chen, Jingye and Cui, Lei and Ma, Shuming and Chang, Yaoyao and Huang, Shaohan and Wang, Wenhui and Dong, Li and Luo, Weiyao and others},
  journal={arXiv preprint arXiv:2309.11419},
  year={2023}
}
License

The content of this project itself is licensed under the MIT

Microsoft Open Source Code of Conduct

Runs of microsoft kosmos-2.5 on huggingface.co

100.0K
Total runs
0
24-hour runs
0
3-day runs
6.6K
7-day runs
-425
30-day runs

More Information About kosmos-2.5 huggingface.co Model

More kosmos-2.5 license Visit here:

https://choosealicense.com/licenses/mit

kosmos-2.5 huggingface.co

kosmos-2.5 huggingface.co is an AI model on huggingface.co that provides kosmos-2.5's model effect (), which can be used instantly with this microsoft kosmos-2.5 model. huggingface.co supports a free trial of the kosmos-2.5 model, and also provides paid use of the kosmos-2.5. Support call kosmos-2.5 model through api, including Node.js, Python, http.

microsoft kosmos-2.5 online free

kosmos-2.5 huggingface.co is an online trial and call api platform, which integrates kosmos-2.5's modeling effects, including api services, and provides a free online trial of kosmos-2.5, you can try kosmos-2.5 online for free by clicking the link below.

microsoft kosmos-2.5 online free url in huggingface.co:

https://huggingface.co/microsoft/kosmos-2.5

kosmos-2.5 install

kosmos-2.5 is an open source model from GitHub that offers a free installation service, and any user can find kosmos-2.5 on GitHub to install. At the same time, huggingface.co provides the effect of kosmos-2.5 install, users can directly use kosmos-2.5 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

kosmos-2.5 install url in huggingface.co:

https://huggingface.co/microsoft/kosmos-2.5

Url of kosmos-2.5

kosmos-2.5 huggingface.co Url

Provider of kosmos-2.5 huggingface.co

microsoft
ORGANIZATIONS

Other API from microsoft

huggingface.co

Total runs: 681.1K
Run Growth: 208.0K
Growth Rate: 30.53%
Updated:February 03 2022
huggingface.co

Total runs: 595.8K
Run Growth: -131.1K
Growth Rate: -22.00%
Updated:November 25 2025
huggingface.co

Total runs: 535.6K
Run Growth: 307.0K
Growth Rate: 57.32%
Updated:April 08 2024
huggingface.co

Total runs: 511.8K
Run Growth: -531.5K
Growth Rate: -103.84%
Updated:December 08 2025
huggingface.co

Total runs: 468.5K
Run Growth: -38.4K
Growth Rate: -8.20%
Updated:September 26 2022
huggingface.co

Total runs: 289.1K
Run Growth: -22.3K
Growth Rate: -7.70%
Updated:February 14 2024
huggingface.co

Total runs: 117.8K
Run Growth: -147.4K
Growth Rate: -125.12%
Updated:November 08 2023
huggingface.co

Total runs: 117.6K
Run Growth: -1.2K
Growth Rate: -1.03%
Updated:February 29 2024
huggingface.co

Total runs: 97.7K
Run Growth: -14.6K
Growth Rate: -14.91%
Updated:February 03 2023
huggingface.co

Total runs: 69.7K
Run Growth: -13.1K
Growth Rate: -18.74%
Updated:November 25 2025
huggingface.co

Total runs: 68.7K
Run Growth: -18.2K
Growth Rate: -26.47%
Updated:December 03 2025
huggingface.co

Total runs: 52.0K
Run Growth: 26.0K
Growth Rate: 50.00%
Updated:December 23 2021
huggingface.co

Total runs: 32.5K
Run Growth: 28.2K
Growth Rate: 86.85%
Updated:April 23 2026
huggingface.co

Total runs: 31.0K
Run Growth: -89.0K
Growth Rate: -287.05%
Updated:May 12 2026
huggingface.co

Total runs: 28.0K
Run Growth: 16.8K
Growth Rate: 59.95%
Updated:April 24 2023
huggingface.co

Total runs: 26.5K
Run Growth: -52.2K
Growth Rate: -196.75%
Updated:August 04 2021