Datasets:
add README.md file
Browse files
README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- pt
|
| 4 |
+
size_categories:
|
| 5 |
+
- 100K<n<1M
|
| 6 |
+
task_categories:
|
| 7 |
+
- image-to-text
|
| 8 |
+
tags:
|
| 9 |
+
- image-captioning
|
| 10 |
+
- multimodal
|
| 11 |
+
- oil-and-gas
|
| 12 |
+
- geosciences
|
| 13 |
+
- portuguese
|
| 14 |
+
configs:
|
| 15 |
+
- config_name: images
|
| 16 |
+
data_files:
|
| 17 |
+
- split: train
|
| 18 |
+
path: data/images/train-*.parquet
|
| 19 |
+
- config_name: annotations
|
| 20 |
+
data_files:
|
| 21 |
+
- split: train
|
| 22 |
+
path: data/annotations/train-*.parquet
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# ImREGIS
|
| 26 |
+
|
| 27 |
+
ImREGIS (Image-REGIS) is a Portuguese multimodal image-text dataset,
|
| 28 |
+
automatically extracted from the REGIS collection — a set of technical
|
| 29 |
+
documents, theses, and reports from the Oil & Gas (O&G) and Geosciences
|
| 30 |
+
domain.
|
| 31 |
+
|
| 32 |
+
The dataset contains over 439,000 unique images and 581,000
|
| 33 |
+
image-text pairs, extracted from more than 20,000 PDF documents,
|
| 34 |
+
combining captions (descriptive text placed near the image) and
|
| 35 |
+
descriptions (textual references to the image scattered throughout
|
| 36 |
+
the document body).
|
| 37 |
+
|
| 38 |
+
## Structure
|
| 39 |
+
|
| 40 |
+
The dataset is split into two tables (configs) linked by the `image_id`
|
| 41 |
+
column.
|
| 42 |
+
|
| 43 |
+
A single `doc_id` may have more than one image associated with it
|
| 44 |
+
(documents with multiple figures/pages).
|
| 45 |
+
|
| 46 |
+
### `images`
|
| 47 |
+
One row per unique image (deduplicated by `image_id`).
|
| 48 |
+
|
| 49 |
+
| column | type | description |
|
| 50 |
+
|---|---|---|
|
| 51 |
+
| `image_id` | string | unique image identifier (join key) |
|
| 52 |
+
| `doc_id` | string | source document identifier |
|
| 53 |
+
| `width` | int32 | width in pixels |
|
| 54 |
+
| `height` | int32 | height in pixels |
|
| 55 |
+
| `format` | string | original format |
|
| 56 |
+
| `image` | binary (bytes) | raw image content |
|
| 57 |
+
|
| 58 |
+
### `annotations`
|
| 59 |
+
One or more text rows per image.
|
| 60 |
+
|
| 61 |
+
| column | type | description |
|
| 62 |
+
|---|---|---|
|
| 63 |
+
| `row_id` | string | unique annotation row identifier |
|
| 64 |
+
| `doc_id` | string | source document identifier |
|
| 65 |
+
| `image_id` | string | identifier of the associated image (key for `images`) |
|
| 66 |
+
| `type` | string | `caption` or `description` |
|
| 67 |
+
| `text` | string | text content |
|
| 68 |
+
| `lang` | string | language |
|
| 69 |
+
|
| 70 |
+
## How to load
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
from datasets import load_dataset
|
| 74 |
+
|
| 75 |
+
images = load_dataset("Geologi/imregis", "images", split="train")
|
| 76 |
+
annotations = load_dataset("Geologi/imregis", "annotations", split="train")
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
Given the dataset size (250GB+), streaming is recommended instead of
|
| 80 |
+
loading everything into memory:
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
images = load_dataset("Geologi/imregis", "images", split="train", streaming=True)
|
| 84 |
+
annotations = load_dataset("Geologi/imregis", "annotations", split="train", streaming=True)
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### Joining images and text
|
| 88 |
+
|
| 89 |
+
For local use (if it fits in memory/disk), via pandas, always join on
|
| 90 |
+
`image_id`:
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
import pandas as pd
|
| 94 |
+
|
| 95 |
+
df_images = images.to_pandas()
|
| 96 |
+
df_annot = annotations.to_pandas()
|
| 97 |
+
|
| 98 |
+
df = df_annot.merge(df_images, on="image_id", how="left", suffixes=("", "_img"))
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
For streaming use, perform the join on demand, for example by building an
|
| 102 |
+
in-memory index of images (if the `images` table fits) and iterating over
|
| 103 |
+
`annotations`:
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
from datasets import load_dataset
|
| 107 |
+
|
| 108 |
+
images_index = {
|
| 109 |
+
row["image_id"]: row["image"]
|
| 110 |
+
for row in load_dataset("Geologi/imregis", "images", split="train", streaming=True)
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
for row in load_dataset("Geologi/imregis", "annotations", split="train", streaming=True):
|
| 114 |
+
image_bytes = images_index.get(row["image_id"])
|
| 115 |
+
# use row["text"], row["type"], row["lang"], and image_bytes
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
### Decoding the image bytes
|
| 119 |
+
|
| 120 |
+
The `image` column contains the raw bytes of the original file. To open
|
| 121 |
+
it as an image:
|
| 122 |
+
|
| 123 |
+
```python
|
| 124 |
+
from PIL import Image
|
| 125 |
+
import io
|
| 126 |
+
|
| 127 |
+
img = Image.open(io.BytesIO(images[0]["image"]))
|
| 128 |
+
img.show()
|
| 129 |
+
```
|