<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yoojin Shin on Medium]]></title>
        <description><![CDATA[Stories by Yoojin Shin on Medium]]></description>
        <link>https://medium.com/@yoojinshin9918?source=rss-5b918dd23d33------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DEdIjNCMcIvXCzlD</url>
            <title>Stories by Yoojin Shin on Medium</title>
            <link>https://medium.com/@yoojinshin9918?source=rss-5b918dd23d33------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:59:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yoojinshin9918/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring OCR-like Tasks with IDEFICS2: A Structured VLM Breakdown Based on Experiments]]></title>
            <link>https://medium.com/@yoojinshin9918/exploring-ocr-like-tasks-with-idefics2-a-structured-vlm-breakdown-based-on-experiments-23949d40e6cd?source=rss-5b918dd23d33------2</link>
            <guid isPermaLink="false">https://medium.com/p/23949d40e6cd</guid>
            <category><![CDATA[vlm]]></category>
            <category><![CDATA[multimodal-ai]]></category>
            <category><![CDATA[hugging-face]]></category>
            <dc:creator><![CDATA[Yoojin Shin]]></dc:creator>
            <pubDate>Mon, 09 Jun 2025 23:57:18 GMT</pubDate>
            <atom:updated>2025-06-10T11:38:22.850Z</atom:updated>
            <content:encoded><![CDATA[<h3>📌 Goal</h3><p><strong>T</strong>o explore whether IDEFICS2 — a vision-language model (VLM) developed by Hugging Face — could handle structured multimodal tasks such as OCR and TTS, I conducted three different experimental approaches.</p><p>I used the <a href="https://huggingface.co/HuggingFaceM4/idefics2-8b">IDEFICS2–8B</a> version, as it was pretrained not only on image-text pairs but also on a variety of instruction-following multimodal datasets.</p><p>The goal was to test whether a single VLM could:<br>1. Extract coherent, readable text from image prompts (OCR)<br>2. Produce text clean enough for downstream text-to-speech synthesis (TTS)</p><p>While many VLMs are optimized for tasks like captioning or open-ended visual reasoning, OCR and TTS require fine-grained sequence alignment, layout preservation, and low tolerance for hallucination – making them a useful benchmark for structured performance.</p><p>This post documents each attempt chronologically, highlighting architectural constraints, hallucination patterns, and the impact of prompt formatting on model behavior. a vision-language model (VLM) by Hugging Face, I conducted three different experimental approaches. This post documents each attempt chronologically, highlighting architectural choices, hallucination patterns, and the impact of prompt formatting.</p><h3>🧪 Phase 1: Prompt-only Attempt (with AutoModelForCausalLM, processor-based Inference, Using Processor Inputs)</h3><h4>🧱 Setup</h4><p>In my initial attempt, I loaded the model and processor using Hugging Face’s AutoProcessor and AutoModelForCausalLM, manually injected a prompt instructing the model to extract text from the image.</p><pre>prompt = &quot;Extract all visible text from the image. Only respond with the text.&quot;</pre><h4>❌ Result</h4><ul><li>Model failed to load: Idefics2Config was not supported by AutoModelForCausalLM</li><li>No inference was performed</li></ul><h4>🧠 Insight</h4><ul><li>IDEFICS2 must be explicitly loaded using Idefics2ForConditionalGeneration</li></ul><h3>⚙️ 2. Phase 2: Prompt only + Direct Model Call</h3><h4>🧱 Setup</h4><ul><li>Model: Idefics2ForConditionalGeneration</li><li>Prompt string passed manually</li><li>Tokenizer used independently without structured formatting</li></ul><h4>❌ Result</h4><p>Despite clearly specifying the task, the model frequently returned irrelevant full descriptions or hallucinated responses like:</p><pre>🧠 IDEFICS Output:<br>In this image we can see a person holding a book. There is some text on the book.</pre><p>This happened even when no such objects were present in the image.</p><h4>🤔 Root Cause: Default Generation &amp; Prompt Template</h4><ul><li>The model used a <strong>default generation config</strong> and <strong>chat template</strong> embedded inside the processor’s config.</li><li>This template implicitly added system-like prefixes (e.g., &quot;Please transcribe the visible text...&quot;) regardless of what I typed.</li><li>Result: My custom prompt was <strong>ignored or overwritten</strong>, and the model reverted to its default “image captioning” behavior.</li></ul><h4>🧠 Insight</h4><ul><li>Prompt-only structure fails to guide the model toward OCR tasks</li><li>IDEFICS2 tends to default into image captioning-style outputs</li></ul><h3>🧪 Phase 3: Processor-based Inference (Structured Input)</h3><h4>✅ Setup</h4><pre>import torch<br>from PIL import Image<br>from transformers import AutoProcessor, AutoModelForCausalLM, Idefics2ForConditionalGeneration<br><br># Model loading<br>model_id = &quot;HuggingFaceM4/idefics2-8b&quot;<br>token = &quot;TOP SECRET&quot;<br><br># device<br>device = torch.device(&quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;)<br><br># Processor &amp; Model Load<br>processor = AutoProcessor.from_pretrained(model_id, token=token)<br>model = Idefics2ForConditionalGeneration.from_pretrained(<br>    model_id,<br>    torch_dtype = torch.float16,<br>    device_map = &quot;auto&quot;,<br>    token = token<br>).eval()</pre><h4>🧪 Prompt:</h4><pre>image_path = &quot;/content/drive/MyDrive/Apziva/4th_MonReader/monreader_images/images/testing/notflip/0001_000000002.jpg&quot;<br>image = Image.open(image_path).convert(&quot;RGB&quot;)<br><br># prompt <br>prompt = &quot;&lt;image&gt;\nReturn only the exact visible text in the image.&quot;<br><br># input using processor<br>inputs = processor(text=prompt, images=image, return_tensors=&quot;pt&quot;).to(device)</pre><h4>⚠️ Result</h4><ul><li>Slight improvement in following instructions</li><li>Still hallucinated content: repeated &quot;Networking.&quot; in images with no such text</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*359pkiGIm9rg2raLh_RaCQ.png" /></figure><h4>🧠 Insights</h4><ul><li>Using processor() correctly formats input_ids, attention_mask, and pixel_values</li><li>However, IDEFICS2 still lacks OCR-specific capabilities</li></ul><h3>🧪 Phase 4: Final Attempt with Processor + Token Security</h3><h4>✅ Setup</h4><p>Here’s a small tip for you to cover your token on you colab environment. Use the function on the left column and get access for the token key.</p><pre>from google.colab import userdata<br>from huggingface_hub import login<br><br>hf_token = userdata.get(&#39;huggingface_pw&#39;)<br>login(token=hf_token)</pre><pre>import torch<br>from PIL import Image<br>from transformers import AutoProcessor, AutoModelForCausalLM<br>from transformers.models.idefics2 import Idefics2ForConditionalGeneration<br><br>model_id = &quot;HuggingFaceM4/idefics2-8b&quot;<br>device = torch.device(&quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;)<br><br># Model and Process Load<br>processor = AutoProcessor.from_pretrained(model_id, token=True)<br>model = Idefics2ForConditionalGeneration.from_pretrained(<br>      model_id,<br>      device_map = &quot;auto&quot;,<br>      torch_dtype = torch.float16,<br>      token=True<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SooYowDntvcNANUjEGhI0Q.png" /></figure><ul><li>Prompt: &lt;image&gt;\nExtract all visible text from the image. Only respond with the text.</li><li>Full structured inference using Hugging Face secure token</li></ul><h4>⚠️ Result</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*9tcL8u7bR2nn2PxYrXbTBg.png" /><figcaption>Can you see that what it’s returning?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8ioVKIaY7umVQs-gwKsew.jpeg" /><figcaption>It’s the original picture.</figcaption></figure><ul><li>Still returned hallucinated result: NETWORK ASIA.</li><li>Even with structured formatting and proper model loading, hallucination persisted</li></ul><h4>🧠 Insight</h4><ul><li>Despite ideal input formatting, IDEFICS2 is not fine-tuned for OCR</li><li>Outputs still leaned toward language modeling over visual grounding</li></ul><h4>📊 Final Takeaways</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*ET55xjxN_3hkdNZuKrJLZg.png" /></figure><h4>🔍 Hallucination Patterns Observed</h4><ul><li>Repeated use of generic words like Networking, Map, Asia</li><li>Echoed full prompt strings instead of task-specific answers</li><li>Output often sounded like image captioning, not OCR</li></ul><h4>✍️ Summary</h4><p>Across four iterations with IDEFICS2, I confirmed:</p><ul><li>Prompt formatting <strong>alone is insufficient</strong> to steer the model reliably</li><li>Processor-based input formatting is <strong>crucial for VLM usability</strong></li><li>However, IDEFICS2 remains <strong>unreliable for OCR tasks</strong> due to hallucination and a lack of fine-tuning for text extraction</li></ul><h3>🧭 What’s Next?</h3><p>Next, I’ll explore <strong>BLIP-2</strong>, a more controllable vision-language model with Q-former architecture.<br>I plan to test OCR-style prompts using both pre-training and instruction-tuned versions of BLIP-2 and compare results with IDEFICS2 in structure, quality, and task alignment.</p><p>Stay tuned!</p><blockquote><strong><em>T</em></strong><em>his work was carried out as part of a project I contributed to during my time with </em><a href="https://www.apziva.com/"><em>Apziva</em></a><em>. If you’re interested in collaboration opportunities or have any questions, I’d be delighted to connect — feel free to reach out via </em><a href="https://www.linkedin.com/in/yoojinshinew99/"><em>LinkedIn</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23949d40e6cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Multimodal Inference: My Switch from Shikra to VLLM — Trials and Errors]]></title>
            <link>https://medium.com/@yoojinshin9918/getting-started-with-multimodal-inference-my-switch-from-shikra-to-vllm-trials-and-errors-d429091ddd44?source=rss-5b918dd23d33------2</link>
            <guid isPermaLink="false">https://medium.com/p/d429091ddd44</guid>
            <category><![CDATA[multimodal-ai]]></category>
            <category><![CDATA[hugging-face]]></category>
            <category><![CDATA[vllm]]></category>
            <dc:creator><![CDATA[Yoojin Shin]]></dc:creator>
            <pubDate>Wed, 28 May 2025 15:19:27 GMT</pubDate>
            <atom:updated>2025-05-29T12:23:23.161Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started with Multimodal Inference: My Switch from Shikra to VLLM — Trials and Errors</h3><h3>Avoid These Mistakes When Customizing Shikra with Delta Weights: How I Switched to VLLM Instead</h3><p>When I first explored building a <strong>multimodal inference pipeline</strong>, I was drawn to <a href="https://huggingface.co/shikras">Shikras</a> — a powerful vision-language model framework built on top of LLaVa with delta-based fine-tuning support. It seemed like a natural choice for testing image-text reasoning. However, as I dove deeper into customization, I encountered several roadblocks that slowed down my experimentation.<br>In this post, I’ll walk you through:<br>- What didn’t work for me with <a href="https://huggingface.co/shikras/shikra-7b-delta-v1">Shikra</a> (particularly when trying to run it with non-default image inputs and model variants)<br>- Why switching to <a href="https://github.com/vllm-project/vllm">VLLM</a> simplified my workflow, and<br>- How to get started quickly with VLLM for your own multimodal experiments.</p><h3>🔍 My Initial Setup with Shikra</h3><p>At first, I tried following the official instructions from the Shikra GitHub repo. The goal was to use Shikra to process a custom <strong>image and caption input.</strong></p><p>I first cloned the Shikras repository on Colab, hoping to install it using. The installation itself wasn’t too bad:</p><h4>Step 1: Installing Shikra — No Setup File?</h4><pre>!git clone https://github.com/Shikra-LLM/Shikra.git<br>cd Shikra<br>!pip install -r requirements.txt</pre><pre>pip install -e .</pre><p>But right away, I hit the first wall:</p><blockquote>Error: file:///content/shikra does not appear to be a Python project: neither ‘setup.py’ nor ‘pyproject.toml’ found.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAlaFmIXmxzNSVDd1ez9mA.png" /><figcaption>Wrong way to implement Shikra</figcaption></figure><h4>Step 2: Version Mismatch — peft vs transformer</h4><p>After force-installing some requirements from <em>requirements.txt, </em>my environment broke again. There were import errors due to outdated versions of peft, while newer versions of transformer attempted to access modules like <em>Cache</em> or <em>DynamiCache</em> that didn’t exist yet.<br>This led to another fix:</p><pre>!pip uninstall transformers<br>!pip install git+https://github.com/huggingface/transformers<br>!pip install --upgrade peft</pre><p>Even after all this, the Shikra environment was still unstable.</p><h4>Step 3: Model Download Failure — Gated Repository Error</h4><p>While attempting to merge the delta weights using PEFT with the base model, I ran into a model issue from Hugging Face. The following code was used:</p><pre>from peft import PeftModel<br>from transformers import AutoModelForCausalLM<br><br>base_model = AutoModelForCausalLM.from_pretrained(<br>     &quot;mistralai/Mistral-7B-v0.1&quot;,<br>      device_map = &quot;auto&quot;,<br>      torch_dtype = &quot;auto&quot;<br>)<br><br>model = PeftModel.from_pretrained(<br>      base_model,<br>      &quot;shikras/shikra-7b-delta-v1&quot;,<br>      adapter_name=&quot;default&quot;<br>)<br><br>model = model.merge_and_unload()</pre><p>Boom. Yet another error:</p><blockquote>GatedRepoError: 403 Client Error… Cannot access gated repo for url <a href="https://huggingface.co/mistralai/Mistral-Small-Instruct-2409/resolve/main/config.json.">https://huggingface.co/mistralai/Mistral-Small-Instruct-2409/resolve/main/config.json.</a></blockquote><p>Even after generating a HuggingFace token and logging in via CLI, I got:</p><blockquote>huggingface_humb.errors.HfHubHTTPError: 401 Client Error: Unauthorized</blockquote><p>Apparently, even token-based access didn’t work without explicit access approval for the gated model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5AXJ8lJYMthqdwntNTd0nA.png" /><figcaption>Actual error I encountered</figcaption></figure><h4>🔄Step 4: Multiple Reinstall Attempts (and User Account Switching)</h4><p>I tried reinstalling Shikra several times — switching between Hugging Face accounts, forcing GitHub installs, and re-logging in through different environments. The installation would sometimes succeed, but loading the delta weight consistently failed due to either gated access or import errors.</p><h4>✅ Step 5: Ditching Delta Weights — Just Use VLLM with Base Model</h4><p>After many painful attempts, I took a step back and asked:</p><blockquote>Do I really need the delta-weighted Shikra model?</blockquote><p>Turns out — no.<br>Instead, I directly loaded a smaller base model that fit within Colab’s limits:</p><pre>from transformers import AudoModelForCausalLM<br><br>model = AutoModelForCausalLM.from_pretrained(<br>    &quot;mistralai/Mistral-7B-Instruct-v0.1&quot;,<br>    device_map=&quot;auto&quot;,<br>    torch_dtype=&quot;auto&quot;<br>)</pre><h3>🧭 Why I Switched to VLLM</h3><p>At some point, I realized I didn’t need to fine-tune from a delta checkpoint just yet — I simply wanted <strong>clean, fast inference</strong> from pretrained multimodal models like LLaVA or Mistral-based variants.</p><p>So I pivoted to <a href="https://github.com/vllm-project/vllm">VLLM</a>, a framework that supports high-throughput LLM inference with <strong>OpenAI-like APIs</strong> and compatibility with models from Hugging Face.</p><p>Installation was refreshingly straightforward:</p><pre>!pip install vllm</pre><p>Running the VLLM server (on CUDA):</p><pre>python -m vllm.entrypoints.openai.api_server \<br>  --model mistralai/Mistral-7B-Instruct-v0.2</pre><p>And querying the model:</p><pre>from vllm import LLM<br>from vllm.sampling_params import SamplingParams<br>from vllm.inputs.data import TokensPrompt<br>import requests<br>from PIL import Image<br>from io import BytesIO<br>from vllm.multimodal import MultiModalDataBuiltins<br><br><br># Base model (ex: mistral/MIstral-7B-v0.1)<br>model_name = AutoModelForCausalLM.from_pretrained(&quot;mistralai/Mistral-Small-Instruct-2409&quot;)<br><br>sampling_params = SamplingParams(max_tokens=8192)<br><br>llm = LLM(model=model_name, tokenizer_mode=&quot;mistral&quot;, config_format=&quot;mistral&quot;, load_format=&quot;mistral&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2W0bnsYRg5ciZ4dZHCgFg.png" /><figcaption>Session stopped</figcaption></figure><p>This time, my session ran out of memory, so loading the model was forcefully stopped. I need more GPUs to run even the smallest model.</p><h3>💡 Key Takeaways</h3><ul><li><strong>Shikra is a great tool if you want delta-based fine-tuning</strong>, especially for training multimodal models from a base LLM. However, for pure inference or light customization, it can be tricky to configure.</li><li><strong>VLLM, on the other hand, is ideal for rapid prototyping</strong>, testing prompts, and deploying your own OpenAI-compatible LLM endpoints.</li><li>If your goal is fast iteration and flexible model access, starting with VLLM might save hours of debugging.</li></ul><h3>🚀 What’s Next?</h3><p>In future posts, I’ll share how I used VLLM to:</p><ul><li>Process large batches of image-caption pairs from the customized dataset,</li><li>Compare instruction-tuned models like LLaVA, MiniGPT-4, and IDEFICS,</li><li>And how I plan to extend the pipeline for <strong>vision-to-text-to-speech</strong> applications.</li></ul><p>Stay tuned!</p><p>#vllm #multimodal #huggingface</p><blockquote><strong><em>This work was carried out as part of a project I contributed to during my time with </em></strong><a href="https://www.apziva.com/"><strong><em>Apziva</em></strong></a><strong><em>. If you’re interested in collaboration opportunities or have any questions, I’d be delighted to connect — feel free to reach out via </em></strong><a href="https://www.linkedin.com/in/yoojinshinew99/"><strong><em>LinkedIn</em></strong></a><strong><em>.</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d429091ddd44" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>