Hugging Face's logo Hugging Face
  • Models
  • Datasets
  • Spaces
  • Buckets new
  • Docs
  • Enterprise
  • Pricing
    • Website
      • Tasks
      • HuggingChat
      • Collections
      • Languages
      • Organizations
    • Community
      • Blog
      • Posts
      • Daily Papers
      • Hardware
      • Learn
      • Discord
      • Forum
      • GitHub
    • Solutions
      • Team & Enterprise
      • Hugging Face PRO
      • Enterprise Support
      • Inference Providers
      • Inference Endpoints
      • Storage Buckets

  • Log In
  • Sign Up

zai-org
/
GLM-OCR

Image-to-Text
Transformers
Safetensors
glm_ocr
image-text-to-text
conversational
Eval Results
Model card Files Files and versions
xet
Community
64

Instructions to use zai-org/GLM-OCR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.

  • Libraries
  • Transformers

    How to use zai-org/GLM-OCR with Transformers:

    # Use a pipeline as a high-level helper
    # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5.
    # You must load the model directly (see below) or downgrade to v4.x with:
    # 'pip install "transformers<5.0.0'
    from transformers import pipeline
    
    pipe = pipeline("image-to-text", model="zai-org/GLM-OCR")
    messages = [
        {
            "role": "user",
            "content": [
                {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
                {"type": "text", "text": "What animal is on the candy?"}
            ]
        },
    ]
    pipe(text=messages)
    # Load model directly
    from transformers import AutoTokenizer, AutoModelForMultimodalLM
    
    tokenizer = AutoTokenizer.from_pretrained("zai-org/GLM-OCR")
    model = AutoModelForMultimodalLM.from_pretrained("zai-org/GLM-OCR", device_map="auto")
    messages = [
        {
            "role": "user",
            "content": [
                {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
                {"type": "text", "text": "What animal is on the candy?"}
            ]
        },
    ]
    inputs = tokenizer.apply_chat_template(
    	messages,
    	add_generation_prompt=True,
    	tokenize=True,
    	return_dict=True,
    	return_tensors="pt",
    ).to(model.device)
    
    outputs = model.generate(**inputs, max_new_tokens=40)
    print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
  • Notebooks
  • Google Colab
  • Kaggle
  • AMD Developer Cloud
GLM-OCR
2.66 GB
Ctrl+K
Ctrl+K
  • 7 contributors
History: 13 commits
changdazhou's picture
changdazhou
Clean up Real5-OmniDocBench evaluation metadata
2737746 verified about 1 month ago
  • .eval_results
    Clean up Real5-OmniDocBench evaluation metadata about 1 month ago
  • .gitattributes
    1.52 kB
    initial commit 8 months ago
  • README.md
    8.28 kB
    Remove hardcode pipeline_tag (must be image-text-to-text) (#57) 4 months ago
  • chat_template.jinja
    4.61 kB
    Add files using upload-large-folder tool 7 months ago
  • config.json
    1.57 kB
    Add files using upload-large-folder tool 7 months ago
  • generation_config.json
    165 Bytes
    Add files using upload-large-folder tool 7 months ago
  • model.safetensors
    2.65 GB
    xet
    Add files using upload-large-folder tool 7 months ago
  • preprocessor_config.json
    367 Bytes
    Add files using upload-large-folder tool 7 months ago
  • tokenizer.json
    6.84 MB
    Add files using upload-large-folder tool 7 months ago
  • tokenizer_config.json
    1.07 kB
    Add files using upload-large-folder tool 7 months ago