Views
No views yet
||.||1Your task is to separate the given caption into subcaptions. You are provided with a compound figure, {N} subfigures, and a main caption. For each subfigure, extract the corresponding subcaption from the main caption and separate them using "||". Make sure the number and order of subcaptions match the given subfigures.
2
3# Compound Figure
4<image>
5# Subfigure
6<image>
7# Subfigure
8<image>
9...
10# Main Caption
11{main_caption}1Your task is to separate the given caption into subcaptions. You are provided with a compound figure, 2 subfigures, and a main caption. For each subfigure, extract the corresponding subcaption from the main caption and separate them using "||". Make sure the number and order of subcaptions match the given subfigures.
2
3# Compound Figure
4<image>
5# Subfigure
6<image>
7# Subfigure
8<image>
9# Main Caption
10Figure 3. Effects of LIPUS treatment on brain edema in TBI mice. (a) Representative T2-weighted MRI images at 1 and 4 days post-TBI. The damaged area is defined as a hyperintense region over the right parietal cortex, indicating edema formation. Dotted line shows location of regions of interest. (b) Quantification revealed significantly smaller edema volumes in LIPUS-treated mice compared with non-treated mice at 1 and 4 days. # Denotes significantly different from non-treated TBI group (### p < 0.001, n = 6).( a ) Representative T2-weighted MRI images at 1 and 4 days post - TBI . The damaged area is defined as a hyperintense region over the right parietal cortex , indicating edema formation . Dotted line shows location of regions of interest .||( b ) Quantification revealed significantly smaller edema volumes in LIPUS - treated mice compared with non - treated mice at 1 and 4 days .pip install "lmdeploy==0.14.0" timm pillow1from lmdeploy import TurbomindEngineConfig, pipeline
2from lmdeploy.vl import load_image
3from lmdeploy.vl.constants import IMAGE_TOKEN
4
5
6MODEL_PATH = (
7 "Yale-BIDS-Chen/"
8 "medpmc-caption-separation-internvl-2.5-4b-mpo"
9)
10
11
12def build_prompt(main_caption: str, num_subfigures: int) -> str:
13 subfigure_blocks = "\n".join(
14 f"# Subfigure\n{IMAGE_TOKEN}"
15 for _ in range(num_subfigures)
16 )
17
18 return (
19 "Your task is to separate the given caption into subcaptions. "
20 f"You are provided with a compound figure, {num_subfigures} "
21 "subfigures, and a main caption. "
22 "For each subfigure, extract the corresponding subcaption from "
23 "the main caption and separate them using \"||\". "
24 "Make sure the number and order of subcaptions match the given "
25 "subfigures.\n\n"
26 f"# Compound Figure\n{IMAGE_TOKEN}\n"
27 f"{subfigure_blocks}\n"
28 "# Main Caption\n"
29 f"{main_caption}"
30 )
31
32
33pipe = pipeline(
34 MODEL_PATH,
35 backend_config=TurbomindEngineConfig(session_len=32768),
36 trust_remote_code=True,
37)
38
39image_paths = [
40 "compound_figure.png",
41 "subfigure_1.png",
42 "subfigure_2.png",
43]
44
45main_caption = (
46 "Figure 3. Effects of treatment on the measured outcome. "
47 "(a) Representative images from the control and treatment groups. "
48 "(b) Quantification of the outcome across groups."
49)
50
51prompt = build_prompt(
52 main_caption=main_caption,
53 num_subfigures=len(image_paths) - 1,
54)
55
56images = [load_image(path) for path in image_paths]
57response = pipe((prompt, images))
58
59subcaptions = [
60 text.strip()
61 for text in response.text.split("||")
62]
63
64print(response.text)
65print(subcaptions)1import json
2import os
3from pathlib import Path
4
5from lmdeploy import TurbomindEngineConfig, pipeline
6from lmdeploy.vl import load_image
7from lmdeploy.vl.constants import IMAGE_TOKEN
8
9
10def run_inference(
11 model_path: str,
12 input_jsonl: str,
13 image_root: str,
14 output_json: str,
15 batch_size: int = 4,
16) -> None:
17 pipe = pipeline(
18 model_path,
19 backend_config=TurbomindEngineConfig(session_len=32768),
20 trust_remote_code=True,
21 )
22
23 with open(input_jsonl, encoding="utf-8") as file:
24 examples = [
25 json.loads(line)
26 for line in file
27 if line.strip()
28 ]
29
30 outputs = []
31
32 for start in range(0, len(examples), batch_size):
33 batch = examples[start:start + batch_size]
34 requests = []
35
36 for example in batch:
37 image_paths = [
38 os.path.join(image_root, filename)
39 for filename in example["image"]
40 ]
41
42 images = [
43 load_image(path)
44 for path in image_paths
45 ]
46
47 prompt = example["conversations"][0]["value"].replace(
48 "<image>",
49 IMAGE_TOKEN,
50 )
51
52 requests.append((prompt, images))
53
54 responses = pipe(requests)
55
56 for example, response in zip(batch, responses):
57 subcaptions = [
58 text.strip()
59 for text in response.text.split("||")
60 ]
61
62 expected_count = len(example["image"]) - 1
63
64 outputs.append(
65 {
66 "id": example.get("id"),
67 "prediction": response.text,
68 "prediction_subcaptions": subcaptions,
69 "expected_subcaption_count": expected_count,
70 "predicted_subcaption_count": len(subcaptions),
71 "finish_reason": getattr(
72 response,
73 "finish_reason",
74 None,
75 ),
76 "valid": (
77 len(subcaptions) == expected_count
78 and all(subcaptions)
79 and getattr(response, "finish_reason", None)
80 != "length"
81 ),
82 }
83 )
84
85 output_path = Path(output_json)
86 output_path.parent.mkdir(parents=True, exist_ok=True)
87
88 with output_path.open("w", encoding="utf-8") as file:
89 json.dump(
90 outputs,
91 file,
92 indent=2,
93 ensure_ascii=False,
94 )
95
96
97if __name__ == "__main__":
98 run_inference(
99 model_path=(
100 "Yale-BIDS-Chen/"
101 "medpmc-caption-separation-internvl-2.5-4b-mpo"
102 ),
103 input_jsonl="input.jsonl",
104 image_root="images",
105 output_json="outputs/predictions.json",
106 batch_size=4,
107 ){subcaption_1}||{subcaption_2}||...||{subcaption_N}1subcaptions = [
2 text.strip()
3 for text in response.text.split("||")
4]( a ) or post - TBI. Optional spacing normalization may be applied after parsing and validation.1@article{kim2026medpmc,
2 title={MedPMC: A Systematic Framework for Scaling High-Fidelity Medical Multimodal Data for Foundation Models},
3 author={Kim, Hyunjae and Kim, Dain and Xiao, Pan and Applebaum, Serina S and Chung, Younjoon and Ai, Xuguang and Yin, Yu and Jiang, Roy and Du, Yuexi and Wei, Yawen and others},
4 journal={arXiv preprint arXiv:2607.07673},
5 year={2026}
6}hyunjae.kim@yale.edu.