Views
No views yet
contextualized_panels (N, 512) — per-panel embeddings enriched with sequential narrative contextstrip_embeddings (512,) — a single vector summarising an entire page/stripcomic-strip-encoder-v1 is a BERT-style Transformer Encoder (Stage4SequenceModel):[CLS]-style query attends over all panel outputs to produce a single strip-level vector.| Head | Task | Paper |
|---|---|---|
ReadingOrderHead | Pairwise panel ordering (adjacency matrix) | ComicsPAP |
PanelPickingHead | Select missing panel from candidates | ComicsPAP |
CharacterCoherenceHead | Visual identity consistency across panels | ComicsPAP |
VisualClosureHead | Action continuation plausibility | ComicsPAP |
TextClosureHead | Dialogue continuation plausibility | ComicsPAP |
CaptionRelevanceHead | Text-visual alignment scoring | ComicsPAP |
TextClozeHead | Select correct dialogue given visual context | Text-Cloze |
L_total = Σ(weighted task losses) + 0.5 * L_contrastive + 0.3 * L_reading_order1task_weights = {
2 'panel_picking': 1.0, # Primary ComicsPAP task
3 'text_cloze': 1.0, # Primary Text-Cloze task
4 'reading_order': 0.7,
5 'visual_closure': 0.8,
6 'text_closure': 0.8,
7 'character_coherence': 0.5,
8 'caption_relevance': 0.5,
9}src/version2/stage4_sequence_modeling_framework.py.1import torch
2from stage4_sequence_modeling_framework import Stage4SequenceModel
3
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5
6# 1. Initialize model
7model = Stage4SequenceModel(d_model=512, num_layers=6, nhead=8).to(device)
8
9# Load weights from Hugging Face
10state_dict = torch.hub.load_state_dict_from_url(
11 "https://huggingface.co/RichardScottOZ/comic-strip-encoder-v1/resolve/main/best_model.pt",
12 map_location=device
13)
14model.load_state_dict(state_dict['model_state_dict'])
15model.eval()
16
17# 2. Inputs: panel embeddings from comic-panel-vlm-v1
18# panel_embeddings: (B, N, 512) — N panels on one page, up to 16
19# panel_mask: (B, N) — True where panel exists
20
21panel_embeddings = torch.randn(1, 6, 512).to(device) # 1 page, 6 panels
22panel_mask = torch.ones(1, 6, dtype=torch.bool).to(device)
23
24# 3. Generate embeddings
25with torch.no_grad():
26 outputs = model(panel_embeddings, panel_mask)
27
28contextualized_panels = outputs['contextualized_panels'] # (1, 6, 512)
29strip_embedding = outputs['strip_embedding'] # (1, 512)
30
31print(f"Contextualized panels: {contextualized_panels.shape}")
32print(f"Strip embedding: {strip_embedding.shape}")1with torch.no_grad():
2 # order_matrix[0, i, j] = score indicating if panel i comes before panel j
3 order_matrix = model.reading_order_head(panel_embeddings) # (1, N, N)
4
5# Compute sorting order based on average row scores
6predicted_order = order_matrix[0].sum(dim=1).argsort(descending=True)
7print(f"Predicted reading order: {predicted_order.tolist()}")1# context: panels from the strip with one masked out
2# candidates: 5 panel embeddings (1 correct, 4 distractors)
3context_emb = contextualized_panels[:, :5, :] # (1, 5, 512)
4candidate_embs = torch.randn(1, 5, 512).to(device) # (1, 5 candidates, 512)
5
6with torch.no_grad():
7 scores = model.panel_picking_head(context_emb.mean(dim=1), candidate_embs)
8 predicted_idx = scores.argmax(dim=-1)
9print(f"Predicted panel index: {predicted_idx.item()}")Stage 1: Raw Comics → Panel crops + OCR text
Stage 2: CoSMo (PSS) → Narrative page classification
Stage 3: comic-panel-vlm-v1 → Multimodal panel embeddings (V + T + Composition) → (N, 512)
Stage 4: comic-strip-encoder-v1 → Contextualized panel + strip embeddings ← THIS MODEL
Stage 5: Storage & Query → Zarr store + semantic searchReadingOrderHead pairwise matrix to verify or correct panel sequencing in digitised comics.TextClozeHead to flag pages where dialogue is likely misattributed or out of order.comic-panel-vlm-v1) embeddings as input; raw images are not accepted directly.CharacterCoherenceHead scores visual consistency but does not track named characters across pages.| Task | Expected Accuracy | Random Baseline |
|---|---|---|
| Panel Picking | 60–70% | 20% |
| Visual Closure | 55–65% | 20% |
| Text Closure | 50–60% | 20% |
| Reading Order | 75–85% | 50% |
| Text-Cloze | 50–60% | 25% |
1@article{comicspap2025,
2 title={ComicsPAP: A Panel-Aware Pipeline for Comic Understanding},
3 year={2025},
4 url={https://arxiv.org/abs/2503.08561}
5}
6
7@article{textcloze2024,
8 title={Text-Cloze: Multimodal Dialogue Prediction in Comics},
9 year={2024},
10 url={https://arxiv.org/abs/2403.03719}
11}