Datasets:

Modalities:
Text
Formats:
webdataset
Languages:
English
Libraries:
Datasets
WebDataset
License:
File size: 6,832 Bytes
1198455
a627a19
74b08db
 
 
 
 
 
 
a627a19
74b08db
 
 
 
 
 
 
 
 
1198455
74b08db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1198455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74b08db
 
 
 
 
 
 
 
 
 
 
 
1198455
 
 
 
 
74b08db
 
 
 
 
1198455
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

---
license: other
license_name: pdfa-eng-train
license_link: LICENSE
task_categories:
- image-to-text
size_categories:
- 10M<n<100M
---
# Dataset Card for PDF Association dataset (PDFA)

## Dataset Description

- **Point of Contact from curators:** [Peter Wyatt, PDF Association CTO](mailto:peter.wyatt@pdfa.org)
- **Point of Contact Hugging Face:** [Pablo Montalvo](mailto:pablo@huggingface.co)

### Dataset Summary

PDFA dataset is a document dataset filtered from the SafeDocs corpus, aka CC-MAIN-2021-31-PDF-UNTRUNCATED. The original purpose of that corpus is for comprehensive file format analysis. The purpose of that subset differs in that regard, as focus has been done on making the dataset machine learning-ready. 

### Usage

This instance of PDFA is in [webdataset](https://github.com/webdataset/webdataset/commits/main) .tar format.
It can be used with webdataset library or current releases of Hugging Face `datasets` library. It can also be streamed directly from the hub that way.

```python
from datasets import load_dataset

pdfa_english = load_dataset('pixparse/pdfa-english-train', streaming=True)

print(next(iter(dataset['train'])).keys())
>> dict_keys(['__key__', '__url__', 'json', 'pdf'])

```

Further, a metadata file `_pdfa-english-train-info-minimal.json` contains the list of samples per shard, with same basename and `.json` or `.pdf` extension, 
as well as the count of files per shard. 


#### Words and lines document metadata

Initially, we started from the readily available ~11TB zip files from PDFA in their initial [data release](https://digitalcorpora.org/corpora/file-corpora/cc-main-2021-31-pdf-untruncated/).
From the pdf digital files, we extracted words, bounding boxes and image bounding boxes that are available in the pdf file. This information is then reshaped into lines organized in reading order, under the key `lines`. We keep non-reshaped word and bounding box information under the `word` key, should users want to use their own heuristic.

The way we obtain an approximate reading order is simply by looking at the frequency peaks of the leftmost word x-coordinate. A frequency peak means that a high number of lines are starting from the same point. Then, we keep track of the x-coordinate of each such identified column. If no peaks are found, the document is assumed to be readable in plain format.

```python
def get_columnar_separators(page, min_prominence=0.3, num_bins=10, kernel_width=1):
    """
    Identifies the x-coordinates that best separate columns by analyzing the derivative of a histogram
    of the 'left' values (xmin) of bounding boxes.

    Args:
        page (dict): Page data with 'bbox' containing bounding boxes of words.
        min_prominence (float): The required prominence of peaks in the histogram.
        num_bins (int): Number of bins to use for the histogram.
        kernel_width (int): The width of the Gaussian kernel used for smoothing the histogram.

    Returns:
        separators (list): The x-coordinates that separate the columns, if any.
    """
    try:
        left_values = [b[0] for b in page['bbox']]
        hist, bin_edges = np.histogram(left_values, bins=num_bins)
        hist = scipy.ndimage.gaussian_filter1d(hist, kernel_width)
        min_val = min(hist)
        hist = np.insert(hist, [0, len(hist)], min_val)
        bin_width = bin_edges[1] - bin_edges[0]
        bin_edges = np.insert(bin_edges, [0, len(bin_edges)], [bin_edges[0] - bin_width, bin_edges[-1] + bin_width])

        peaks, _ = scipy.signal.find_peaks(hist, prominence=min_prominence * np.max(hist))
        derivatives = np.diff(hist)

        separators = []
        if len(peaks) > 1:
            # This finds the index of the maximum derivative value between peaks
            # which indicates peaks after trough --> column
            for i in range(len(peaks)-1):
                peak_left = peaks[i]
                peak_right = peaks[i+1]
                max_deriv_index = np.argmax(derivatives[peak_left:peak_right]) + peak_left
                separator_x = bin_edges[max_deriv_index + 1]
                separators.append(separator_x)
    except Exception as e:
        separators = []
    return separators
```

For each pdf document, we store statistics on the file size, number of words (as characters separated by spaces), number of pages, as well as the rendering times of each page for a given dpi. 
#### Filtering process

File size and page rendering time are used to set thresholds in the final dataset: the goal is to remove files that are larger than 100 MB, or that take more than 500ms to render on a modern machine, to optimize dataloading at scale. Having "too large" or "too slow" files would add a burden to large-scale training pipelines and we choose to alleviate this in the current release. Finally, a full pass over the dataset is done, trying to open a bytestream 

We get to 48 million pages kept as valid samples.

As a last step, we use XLM-Roberta to restrict the dataset to an english subset, specifically `papluca/xlm-roberta-base-language-detection` , on the first 512 words of the first page of each document. 
Be aware that some documents may have several languages embedded in them, or that some predictions might be inaccurate. 


At the end, each document exists as a pairing of a pdf and a json file containing extensive OCR annotation as well as metadata information about rendering times. The filterings and packaging in 
webdataset format are tailored towards multimodal machine learning at scale, specifically image-to-text tasks.

### Dataset statistics


In this dataset, an additional filtering has been done to restrict documents to the english language to 18.6 million pages over 2.16 million documents. This filtering has been done using XLM

Further, the metadata for each document has been formatted in this way:

TODO add formatting

Such a formatting follows the multimodal dataset from the Industry Document Library,  `https://huggingface.co/datasets/pixparse/IDL-wds`. 

### Data Splits

#### Train
* `pdfa-eng-train-*.tar`
* Downloaded on 2024/01/22
* 1800 shards, 2,159,433 samples, 18,686,346 pages, 5,997,818,991 words

## Additional Information

### Dataset Curators

Pablo Montalvo, Ross Wightman

### Disclaimer

This dataset, as a corpus, does not represent the intent and purpose from  CC-MAIN-2021-31-PDF-UNTRUNCATED. 
TODO add disclaimer on biases of using that dataset as a faithful representation of existing documents on the web

### Licensing Information

Data has been filtered from the original corpus. As a consequence, users should note [Common Crawl's license and terms of use](https://commoncrawl.org/terms-of-use) and the [Digital Corpora project's Terms of Use](https://digitalcorpora.org/about-digitalcorpora/terms-of-use/).

### Citation Information
??