upload pmc_oa (#4)
Browse files- upload pmc_oa (d3c99812a696878a30bf5b1cf779f10c8bae0f66)
Co-authored-by: Ziheng Zhao <[email protected]>
- .gitattributes +2 -0
- pmc_oa.jsonl +3 -0
- pmc_oa.py +99 -44
- pmc_oa_beta.jsonl +3 -0
.gitattributes
CHANGED
@@ -55,3 +55,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
55 |
test.jsonl filter=lfs diff=lfs merge=lfs -text
|
56 |
train.jsonl filter=lfs diff=lfs merge=lfs -text
|
57 |
valid.jsonl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
55 |
test.jsonl filter=lfs diff=lfs merge=lfs -text
|
56 |
train.jsonl filter=lfs diff=lfs merge=lfs -text
|
57 |
valid.jsonl filter=lfs diff=lfs merge=lfs -text
|
58 |
+
pmc_oa_beta.jsonl filter=lfs diff=lfs merge=lfs -text
|
59 |
+
pmc_oa.jsonl filter=lfs diff=lfs merge=lfs -text
|
pmc_oa.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:05702cd5fb41ebf55a7226ca3c53e68edff4b4455224d7e6ff9d01157f5aaf23
|
3 |
+
size 454568741
|
pmc_oa.py
CHANGED
@@ -5,10 +5,8 @@ import jsonlines
|
|
5 |
|
6 |
import datasets
|
7 |
|
8 |
-
|
9 |
logger = datasets.logging.get_logger(__name__)
|
10 |
|
11 |
-
|
12 |
_CITATION = """\
|
13 |
@article{lin2023pmc,
|
14 |
title={PMC-CLIP: Contrastive Language-Image Pre-training using Biomedical Documents},
|
@@ -28,57 +26,114 @@ including image-text retrieval on ROCO, MedMNIST image classification, Medical V
|
|
28 |
|
29 |
_HOMEPAGE = "https://weixionglin.github.io/PMC-CLIP/"
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
"
|
34 |
-
"
|
35 |
-
"valid": _URL + "valid.jsonl",
|
36 |
-
"test": _URL + "test.jsonl"
|
37 |
}
|
38 |
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
class PMC_OA(datasets.GeneratorBasedBuilder):
|
41 |
-
"""PMC_OA Dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def _info(self):
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
def _split_generators(self, dl_manager):
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
def _generate_examples(self, filepath, image_dir):
|
67 |
-
"""
|
68 |
logger.info("generating examples from = %s", filepath)
|
69 |
-
|
70 |
with jsonlines.open(filepath) as reader:
|
71 |
-
_id
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
import datasets
|
7 |
|
|
|
8 |
logger = datasets.logging.get_logger(__name__)
|
9 |
|
|
|
10 |
_CITATION = """\
|
11 |
@article{lin2023pmc,
|
12 |
title={PMC-CLIP: Contrastive Language-Image Pre-training using Biomedical Documents},
|
|
|
26 |
|
27 |
_HOMEPAGE = "https://weixionglin.github.io/PMC-CLIP/"
|
28 |
|
29 |
+
_URLs = {
|
30 |
+
"images": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/images.zip",
|
31 |
+
"pmc_oa_beta": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/pmc_oa_beta.jsonl",
|
32 |
+
"pmc_oa": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/pmc_oa.jsonl",
|
|
|
|
|
33 |
}
|
34 |
|
35 |
|
36 |
+
class PMC_OA_Config(datasets.BuilderConfig):
|
37 |
+
"""BuilderConfig for PMC_OA"""
|
38 |
+
|
39 |
+
def __init__(self, **kwargs):
|
40 |
+
"""
|
41 |
+
Args:
|
42 |
+
**kwargs: keyword arguments forwarded to super.
|
43 |
+
"""
|
44 |
+
super(PMC_OA_Config, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
45 |
+
|
46 |
+
|
47 |
class PMC_OA(datasets.GeneratorBasedBuilder):
|
48 |
+
"""PMC_OA Dataset"""
|
49 |
+
|
50 |
+
VERSION = datasets.Version("1.0.0")
|
51 |
+
BUILDER_CONFIGS = [
|
52 |
+
PMC_OA_Config(
|
53 |
+
name="pmc_oa_beta",
|
54 |
+
description="<subfigure, caption> pairs. Subfigures detected by a DETR model.",
|
55 |
+
),
|
56 |
+
PMC_OA_Config(
|
57 |
+
name="pmc_oa",
|
58 |
+
description="<subfigure, subcaption> pairs. Subfigures detected by a DETR model. Subcaptions detected by ChatGPT and aligned with subfigures.",
|
59 |
+
),
|
60 |
+
]
|
61 |
|
62 |
def _info(self):
|
63 |
+
if self.config.name == "pmc_oa_beta":
|
64 |
+
return datasets.DatasetInfo(
|
65 |
+
description=_DESCRIPTION,
|
66 |
+
features=datasets.Features(
|
67 |
+
{
|
68 |
+
"image": datasets.Value("string"),
|
69 |
+
"caption": datasets.Value("string"),
|
70 |
+
}
|
71 |
+
),
|
72 |
+
supervised_keys=None,
|
73 |
+
citation=_CITATION,
|
74 |
+
homepage=_HOMEPAGE,
|
75 |
+
)
|
76 |
+
elif self.config.name == "pmc_oa":
|
77 |
+
return datasets.DatasetInfo(
|
78 |
+
description=_DESCRIPTION,
|
79 |
+
features=datasets.Features(
|
80 |
+
{
|
81 |
+
"image": datasets.Value("string"),
|
82 |
+
"caption": datasets.Value("string"),
|
83 |
+
"alignment_type": datasets.Value("string"),
|
84 |
+
"alignment_score": datasets.Value("float"),
|
85 |
+
}
|
86 |
+
),
|
87 |
+
supervised_keys=None,
|
88 |
+
citation=_CITATION,
|
89 |
+
homepage=_HOMEPAGE,
|
90 |
+
)
|
91 |
|
92 |
def _split_generators(self, dl_manager):
|
93 |
+
"""Returns SplitGenerators."""
|
94 |
+
downloaded_files = dl_manager.download_and_extract(_URLs)
|
95 |
+
if self.config.name == "pmc_oa_beta":
|
96 |
+
return [
|
97 |
+
datasets.SplitGenerator(
|
98 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["pmc_oa_beta"], "image_dir": downloaded_files['images']}
|
99 |
+
)
|
100 |
+
]
|
101 |
+
elif self.config.name == "pmc_oa":
|
102 |
+
return [
|
103 |
+
datasets.SplitGenerator(
|
104 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["pmc_oa"], "image_dir": downloaded_files['images']}
|
105 |
+
)
|
106 |
+
]
|
107 |
|
108 |
def _generate_examples(self, filepath, image_dir):
|
109 |
+
"""Yields examples."""
|
110 |
logger.info("generating examples from = %s", filepath)
|
111 |
+
|
112 |
with jsonlines.open(filepath) as reader:
|
113 |
+
for _id, obj in enumerate(reader):
|
114 |
+
if self.config.name == "pmc_oa_beta":
|
115 |
+
relative_image_path = obj['image']
|
116 |
+
image_path = os.path.join(image_dir, "caption_T060_filtered_top4_sep_v0_subfigures", relative_image_path)
|
117 |
+
caption = obj['caption']
|
118 |
+
yield _id, {
|
119 |
+
"image": {
|
120 |
+
"path": image_path,
|
121 |
+
"bytes": open(image_path, "rb").read(),
|
122 |
+
},
|
123 |
+
"caption": caption,
|
124 |
+
}
|
125 |
+
elif self.config.name == "pmc_oa":
|
126 |
+
relative_image_path = obj['image']
|
127 |
+
image_path = os.path.join(image_dir, "caption_T060_filtered_top4_sep_v0_subfigures", relative_image_path)
|
128 |
+
caption = obj['caption']
|
129 |
+
alignment_type = obj['alignment_type']
|
130 |
+
alignment_score = obj['alignment_score']
|
131 |
+
yield _id, {
|
132 |
+
"image": {
|
133 |
+
"path": image_path,
|
134 |
+
"bytes": open(image_path, "rb").read(),
|
135 |
+
},
|
136 |
+
"caption": caption,
|
137 |
+
"alignment_type": alignment_type,
|
138 |
+
"alignment_score": alignment_score,
|
139 |
+
}
|
pmc_oa_beta.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0b2d7178ac8b329edad198a6ad25bc86c212fd2c1373d626f6767ede61cfa2ae
|
3 |
+
size 1302951005
|