---
title: 'LongVLM: Hierarchical Video Language Model'
url: https://www.emergentmind.com/topics/longvlm
type: topic
---

# LongVLM: Hierarchical Video Language Model

LongVLM is a Video-based Large Language Model (VideoLLM) architecture designed for efficient understanding of long videos, which typically consist of thousands of frames and thus tens of thousands of visual tokens. Unlike previous VideoLLMs that aggregate visual features into a single global representation, LongVLM decomposes videos into sequential short-term segments, applies hierarchical token merging to retain fine-grained local information, and integrates global semantic cues to enhance context comprehension. This approach balances computational efficiency with detailed temporal and spatial analysis, enabling significant gains over prior methods in both quantitative and qualitative evaluation benchmarks [2404.03384].

## 1. Motivation and Problem Formulation

Long video understanding poses challenges due to the high token count arising from many frames. For example, sampling 100 frames with 256 patch tokens per frame yields 25,600 tokens for a CLIP-ViT-L/14 backbone, exceeding the practical input constraints of off-the-shelf LLMs. Most existing VideoLLMs address this by compressing all frame features into a single vector, typically via pooling or learned queries, which captures overall context but fails to model fine-grained, temporally localized events. Further, there is often inadequate modeling of sequential sub-events and insufficient propagation of global semantics into localized representations. The formal goal is, given a video $I\in\mathbb{R}^{T\times H\times W\times 3}$ and user query $q$, to generate a comprehensive answer $a$ such that
\[
a = \mathrm{LLM}\left(\Phi_V (\mathrm{VideoRep}(I)),\, q\right),
\]
where $\mathrm{VideoRep}(I)$ must preserve temporal order, retain both local and global information, and limit the total number of tokens [2404.03384].

## 2. Model Architecture

LongVLM’s pipeline comprises several distinct steps:

1. **Frame-level Feature Extraction:** Uniformly sample $T$ video frames $\{x^t\}_{t=1}^T$, extract per-frame patch features $v^t \in \mathbb{R}^{N \times d}$ from a frozen vision encoder (e.g., CLIP-ViT-L/14), as well as $E$ [CLS] tokens $c^t_e$ from the last $E$ layers.
2. **Segmentation and Hierarchical Token Merging:** Divide frames into $S$ contiguous segments of length $K=T/S$. Within each segment $s$, collect all patch tokens to form $V^s$, then reduce $V^s$ to $M$ tokens using a hierarchical bipartite matching mechanism inspired by ToMe.
3. **Global Semantic Integration:** Average [CLS] tokens temporally for each selected layer to obtain global feature vectors $\bar c_e$, then stack them as $F_{\text{global}}$ and concatenate them with the temporally ordered local segment tokens $F_{\text{local}}$. This ensures every local token can attend to the global context through self-attention.
4. **Projection and Generation:** Project the concatenated video token sequence $F_{\text{vid}} = [F_{\text{global}}; F_{\text{local}}]$ using a learned linear mapping $\Phi_V$ to the LLM’s input space. The frozen LLM (Vicuna-7B v1.1) receives both the visually encoded tokens and the text query, autoregressively generating the answer [2404.03384].

## 3. Mathematical Formulation

Key notation and computational steps are as follows:
- $T$: number of sampled frames; $N$: patch tokens per frame; $d$: channel dimension; $E$: [CLS] global feature layers.
- Hierarchical merging reduces segment patch tokens from $K N$ to $M$ via:
  1. Randomly split tokens into $\mathcal{A}_i$ and $\mathcal{B}_i$,
  2. Compute multi-head cosine similarities across all pairs,
  3. Pool and merge top-scoring pairs iteratively until $M$ remain.
- Concatenated token sequence: $F_{\text{vid}} \in \mathbb{R}^{(E + M S) \times d}$.
- Only the projection layer $\Phi_V$ is fine-tuned, optimizing the autoregressive token cross-entropy loss
\[
\mathcal{L} = -\sum_{t=1}^L \log P(a_t \mid a_{<t}, Z, q)
\]
with $Z = \Phi_V(F_{\text{vid}})$ [2404.03384].

## 4. Training Protocol and Experimental Design

The model is evaluated on both VideoChatGPT benchmarks and zero-shot video question-answering (VideoQA) datasets. Training specifics:
- Vision encoder: CLIP-ViT-L/14 (frozen).
- LLM: Vicuna-7B v1.1 (frozen).
- Fine-tune only $\Phi_V$, using 3 epochs, learning rate 2e-5, batch size 32, and 4 × A100-80GB GPUs.
- Frame sampling: $T=100$; segments: $S=10$, $K=10$; merged tokens: $M=30$ per segment; global tokens: $E=5$; total visual tokens: 305.
- Baselines: VideoChat, LLaMA Adapter v2, Video LLaMA, BT-Adapter, Valley, Video-ChatGPT [2404.03384].

## 5. Quantitative and Qualitative Results

LongVLM achieves state-of-the-art results on key long-video understanding benchmarks:
- **VideoChatGPT (mean across five criteria):** LongVLM 2.89 vs. BT-Adapter 2.69, VideoChatGPT 2.42.
- **Zero-shot VideoQA:**

| Dataset      | BT-Adapter | LongVLM (Acc. %) | LongVLM (Gen. Score) |
|--------------|------------|------------------|----------------------|
| ANET-QA      |    45.7    |      47.6        |         3.3          |
| MSRVTT-QA    |    57.0    |      59.8        |         3.3          |
| MSVD-QA      |    67.5    |      70.0        |         3.8          |

- **Ablation and Sensitivity:**
  - Global semantic integration yields the best mean score (2.89).
  - Increasing $M$ from 10 to 30 improves accuracy and mean score without significant memory overhead.
  - Ablations confirm that both hierarchical merging and global integration are essential for optimal performance.

Qualitative comparisons demonstrate that LongVLM avoids the common errors of previous models (e.g., misclassifying object colors or actions) by preserving segment-level detail and incorporating global context. For example, on a bike repair video, LongVLM correctly identifies "brown clothes" and "bicycle chain," while VideoChatGPT outputs "gray clothes" and "wheel" [2404.03384].

## 6. Limitations and Future Directions

Current limitations include:
- Output restricted to video-to-text generation.
- Fixed frame sampling ($T=100$) may be suboptimal for much longer videos.
- Segments are merged only intra-segment; no cross-segment token reduction.
Possible future extensions involve support for multimodal generation (e.g., video+audio), pretraining hierarchical merging and global semantics integration on large-scale video datasets, and more adaptive segmentation schemes for variable-length videos [2404.03384].

## 7. Code and Accessibility

The implementation and pretrained models for LongVLM are available at https://github.com/ziplab/LongVLM [2404.03384]. This enables reproducibility and further research exploration into efficient, high-fidelity video understanding using large language models.

Source: https://www.emergentmind.com/topics/longvlm