SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2601.03100 · 2026

TGIF: Text-Guided Layer Fusion Mitigates Hallucination in Multimodal LLMs

Yan Wang, Marco Pavone, Yuxiao Chen, Fei Miao, Chenchen Lin, Sanbao Su, Rachel Luo

arXiv · PDF · Open in the Atlas

Code that ran

2 of 2 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 0 failures of our instrument; 0 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2601.03100.json · badge: /api/ran/2601.03100.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
Linchenchen/TGIF community
Papers with Code archive
2 ran · 0 no recorded run
FunctionStatusWhere it lives
LayerSelector Ran
ran on a synthesized input
Linchenchen/TGIF/llava/model/multimodal_projector/layer_selection.py
code served (permissive licence) · get_code("e531e63fd8c8d657")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import torch.nn.functional as F

def get_num_vision_layers(config, default=24):
    return getattr(config, 'mm_vision_num_layers', getattr(config, 'num_hidden_layers', default))

class LayerSelector(nn.Module):
    """
    Dynamically reweights and combines image features from different layers
    based on a given sentence embedding, matching the LayerRouter logic.
    """

    def __init__(self, config):
        super().__init__()
        self.num_layers = get_num_vision_layers(config)
        self.feat_dim = config.hidden_size
        self.hidden_size = config.mm_hidden_size
        intermediate_dim = 512
        self.layer_weights_projection = nn.Sequential(nn.Linear(self.feat_dim, intermediate_dim), nn.ReLU(), nn.Linear(intermediate_dim, self.num_layers))
        self.norm = nn.LayerNorm(self.hidden_size)

    def forward(self, all_layers_features: torch.Tensor, text_features: torch.Tensor):
        layer_logits = self.layer_weights_projection(text_features)
        layer_weights = F.softmax(layer_logits, dim=-1)
        reshaped_weights = layer_weights.unsqueeze(-1).unsqueeze(-1)
        dynamic_features = torch.sum(all_layers_features * reshaped_weights, dim=1)
        baseline_features = all_layers_features[:, -2, :, :]
        final_features = baseline_features + dynamic_features
        final_features = self.norm(final_features)
        return (final_features, layer_weights)


class Config:
    def __init__(self):
        self.hidden_size = 4
        self.mm_hidden_size = 8
        self.num_hidden_layers = 2


config = Config()

INIT_ARGS = {
    'config': config
}

ARGS = {
    'all_layers_features': torch.randn(2, 2, 3, 8),
    'text_features': torch.randn(2, 4)
}

if __name__ == '__main__':
    layer_selector = LayerSelector(**INIT_ARGS)
    final_features, layer_weights = layer_selector(**ARGS)
    print("Final features shape:", final_features.shape)
    print("Layer weights shape:", layer_weights.shape)
    print("Final features:", final_features)
    print("Layer weights:", layer_weights)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
get_num_vision_layers Ran
ran, honoured the contract we drafted
Linchenchen/TGIF/llava/model/multimodal_projector/layer_selection.py
code served (permissive licence) · get_code("48fc72e801535075")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

class ConfigStandIn:
    """Stand-in config class with optional vision layer attributes."""
    def __init__(self, mm_vision_num_layers=None, num_hidden_layers=None):
        if mm_vision_num_layers is not None:
            self.mm_vision_num_layers = mm_vision_num_layers
        if num_hidden_layers is not None:
            self.num_hidden_layers = num_hidden_layers

# Test with a config that has mm_vision_num_layers
config = ConfigStandIn(mm_vision_num_layers=32)

ARGS = {
    'config': config,
    'default': 24
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block

Also present in other papers' code

Of 2 samples lifted from this paper's linked repositories, 2 carry a function identity and 0 do not. Of the 2 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 2 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Multimodal large language models (MLLMs) often generate confident but visually ungrounded responses, a phenomenon known as hallucination. While prior mitigation methods primarily operate at decoding time or rely on additional training, they typically expose the language model to a fixed, late-layer visual representation, overlooking the rich hierarchy encoded by vision transformers. We show that hallucination behavior is strongly influenced by the depth of visual features provided to the LLM, and that no single layer is optimal across queries. To address this, we propose Text-Guided Inter-layer Fusion (TGIF), a lightweight architectural module that dynamically reweights visual features across transformer layers based on the input text, without modifying the vision encoder or increasing the token budget. Experiments on hallucination, OCR, and general VQA benchmarks demonstrate that TGIF substantially improves visual grounding and hallucination robustness while preserving strong overall reasoning performance. Code: github.com/Linchenchen/TGIF.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2601.03100")
get_code_for_paper("2601.03100")
have("2601.03100")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2601.03100.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2601.03100.svg)](https://syntology.ai/paper/2601.03100)

Connect an agent — have() is free.