├── .dockerignore ├── .gitignore ├── Dockerfile ├── License.txt ├── Taskfile.yml ├── datasheet.md ├── datasheet.pdf ├── poetry.lock ├── pyproject.toml ├── readme.md ├── readme.pdf ├── requirements.txt ├── rvl-cdip.sh ├── setup.sh ├── to_text.py └── tobacco3482.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | datasets/ 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | datasets/ 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3-stretch 2 | 3 | COPY . /work 4 | WORKDIR /work 5 | RUN ./setup.sh 6 | RUN pip install poetry && poetry config settings.virtualenvs.create false 7 | RUN poetry install --no-dev 8 | 9 | CMD bash 10 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 - Quicksign 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Taskfile.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | tasks: 4 | build: 5 | desc: Build the Docker container 6 | cmds: 7 | - docker build . -t qs/ocrized 8 | run: 9 | desc: Run the Docker container 10 | deps: [build] 11 | cmds: 12 | - mkdir -p datasets && docker run --user $(id -u):$(id -g) -it --rm -v `pwd`/datasets:/work/datasets/ qs/ocrized 13 | make_pdf: 14 | desc: Generate the README and Datasheet PDF files 15 | cmds: 16 | - pandoc readme.md --variable urlcolor=blue -t latex -o readme.pdf 17 | - pandoc datasheet.md --variable urlcolor=blue -t latex -o datasheet.pdf 18 | setup: 19 | desc: Setup the requirements for the manual install 20 | cmds: 21 | - pip install poetry 22 | - poetry install 23 | - sudo ./setup.sh 24 | - poetry shell 25 | -------------------------------------------------------------------------------- /datasheet.md: -------------------------------------------------------------------------------- 1 | # Datasheet: qs-ocrized-text 2 | 3 | - [Datasheet: qs-ocrized-text](#datasheet-qs-ocrized-text) 4 | - [Motivation](#motivation) 5 | - [For what purpose was the dataset created?](#for-what-purpose-was-the-dataset-created) 6 | - [Who created this dataset and on behalf of which entity?](#who-created-this-dataset-and-on-behalf-of-which-entity) 7 | - [Composition](#composition) 8 | - [What do the instances that comprise the dataset represent?](#what-do-the-instances-that-comprise-the-dataset-represent) 9 | - [How many instances are there in total ?](#how-many-instances-are-there-in-total) 10 | - [Does the dataset contain all possible instances or is it a sample (not necessarily random) of instances from a larger set?](#does-the-dataset-contain-all-possible-instances-or-is-it-a-sample-not-necessarily-random-of-instances-from-a-larger-set) 11 | - [What data does each instance consist of?](#what-data-does-each-instance-consist-of) 12 | - [Is there a label or target associated with each instance?](#is-there-a-label-or-target-associated-with-each-instance) 13 | - [Is any information missing from individual instances?](#is-any-information-missing-from-individual-instances) 14 | - [Are relationships between individual instances made explicit (e.g.,users’ movie ratings, social network links) ?](#are-relationships-between-individual-instances-made-explicit-egusers-movie-ratings-social-network-links) 15 | - [Are there recommended data splits ?](#are-there-recommended-data-splits) 16 | - [Are there any errors, sources of noise, or redundancies in the dataset?](#are-there-any-errors-sources-of-noise-or-redundancies-in-the-dataset) 17 | - [Is the dataset self-contained, or does it link to or otherwise rely onexternal resources (e.g., websites, tweets, other datasets)?](#is-the-dataset-self-contained-or-does-it-link-to-or-otherwise-rely-onexternal-resources-eg-websites-tweets-other-datasets) 18 | - [Does the dataset contain data that might be considered confidential (e.g., data that is protected by legal privilege or by doctor-patient confidentiality, data that includes the content of individuals non-public communications)?](#does-the-dataset-contain-data-that-might-be-considered-confidential-eg-data-that-is-protected-by-legal-privilege-or-by-doctor-patient-confidentiality-data-that-includes-the-content-of-individuals-non-public-communications) 19 | - [Does the dataset contain data that, if viewed directly, might be offensive, insulting, threatening, or might otherwise cause anxiety?](#does-the-dataset-contain-data-that-if-viewed-directly-might-be-offensive-insulting-threatening-or-might-otherwise-cause-anxiety) 20 | - [Does the dataset contain data that might be considered sensitive in any way?](#does-the-dataset-contain-data-that-might-be-considered-sensitive-in-any-way) 21 | - [Collection process](#collection-process) 22 | - [How was the data associated with each instance acquired?](#how-was-the-data-associated-with-each-instance-acquired) 23 | - [What mechanisms or procedures were used to collect the data (e.g., hardware apparatus or sensor, manual human curation, software program, software API)?](#what-mechanisms-or-procedures-were-used-to-collect-the-data-eg-hardware-apparatus-or-sensor-manual-human-curation-software-program-software-api) 24 | - [If the dataset is a sample from a larger set, what was the sampling strategy (e.g., deterministic, probabilistic with specific sampling probabilities)](#if-the-dataset-is-a-sample-from-a-larger-set-what-was-the-sampling-strategy-eg-deterministic-probabilistic-with-specific-sampling-probabilities) 25 | - [Who was involved in the data collection process (e.g., students, crowdworkers, contractors) and how were they compensated (e.g.,how much were crowdworkers paid)?](#who-was-involved-in-the-data-collection-process-eg-students-crowdworkers-contractors-and-how-were-they-compensated-eghow-much-were-crowdworkers-paid) 26 | - [Over what timeframe was the data collected?](#over-what-timeframe-was-the-data-collected) 27 | - [Were any ethical review processes conducted (e.g., by an institutional review board)?](#were-any-ethical-review-processes-conducted-eg-by-an-institutional-review-board) 28 | - [Does the dataset relate to people?](#does-the-dataset-relate-to-people) 29 | - [Did you collect the data from the individuals in question directly, or obtain it via third parties or other sources (e.g., websites)?](#did-you-collect-the-data-from-the-individuals-in-question-directly-or-obtain-it-via-third-parties-or-other-sources-eg-websites) 30 | - [Were the individuals in question notified about the data collection?](#were-the-individuals-in-question-notified-about-the-data-collection) 31 | - [Did the individuals in question consent to the collection and use oftheir data?](#did-the-individuals-in-question-consent-to-the-collection-and-use-oftheir-data) 32 | - [Preprocessing/cleaning/labeling](#preprocessingcleaninglabeling) 33 | - [Was any preprocessing/cleaning/labeling of the data done (e.g., discretization or bucketing, tokenization, part-of-speech tagging, SIFTfeature extraction, removal of instances, processing of missing values)?](#was-any-preprocessingcleaninglabeling-of-the-data-done-eg-discretization-or-bucketing-tokenization-part-of-speech-tagging-siftfeature-extraction-removal-of-instances-processing-of-missing-values) 34 | - [Was the "raw" data saved in addition to the preprocessed/cleaned/labeled data (e.g.,to support unanticipated future uses)?](#was-the-%22raw%22-data-saved-in-addition-to-the-preprocessedcleanedlabeled-data-egto-support-unanticipated-future-uses) 35 | - [Is the software used to preprocess/clean/label the instances available?](#is-the-software-used-to-preprocesscleanlabel-the-instances-available) 36 | - [Uses](#uses) 37 | - [Has the dataset been used for any tasks already?](#has-the-dataset-been-used-for-any-tasks-already) 38 | - [Is there a repository that links to any or all papers or systems that use the dataset?](#is-there-a-repository-that-links-to-any-or-all-papers-or-systems-that-use-the-dataset) 39 | - [What (other) tasks could the dataset be used for?](#what-other-tasks-could-the-dataset-be-used-for) 40 | - [Is there anything about the composition of the dataset or the way it was collected and preprocessed/cleaned/labeled that might impact future uses?](#is-there-anything-about-the-composition-of-the-dataset-or-the-way-it-was-collected-and-preprocessedcleanedlabeled-that-might-impact-future-uses) 41 | - [Are there tasks for which the dataset should not be used?](#are-there-tasks-for-which-the-dataset-should-not-be-used) 42 | - [Distribution](#distribution) 43 | - [Will the dataset be distributed to third parties outside of the entity (e.g., company, institution, organization) on behalf of which the dataset was created?](#will-the-dataset-be-distributed-to-third-parties-outside-of-the-entity-eg-company-institution-organization-on-behalf-of-which-the-dataset-was-created) 44 | - [How will the dataset will be distributed (e.g., tarball on website, API, GitHub)? Does the dataset have a digital object identifier (DOI)?](#how-will-the-dataset-will-be-distributed-eg-tarball-on-website-api-github-does-the-dataset-have-a-digital-object-identifier-doi) 45 | - [Will the dataset be distributed under a copyright or other intellectualproperty (IP) license, and/or under applicable terms of use (ToU)?](#will-the-dataset-be-distributed-under-a-copyright-or-other-intellectualproperty-ip-license-andor-under-applicable-terms-of-use-tou) 46 | - [Have any third parties imposed IP-based or other restrictions on thedata associated with the instances?](#have-any-third-parties-imposed-ip-based-or-other-restrictions-on-thedata-associated-with-the-instances) 47 | - [Do any export controls or other regulatory restrictions apply to thedataset or to individual instances?](#do-any-export-controls-or-other-regulatory-restrictions-apply-to-thedataset-or-to-individual-instances) 48 | - [Maintenance](#maintenance) 49 | - [Who is supporting/hosting/maintaining the dataset?](#who-is-supportinghostingmaintaining-the-dataset) 50 | - [How can the owner/curator/manager of the dataset be contacted (e.g., email address)?](#how-can-the-ownercuratormanager-of-the-dataset-be-contacted-eg-email-address) 51 | - [Is there an erratum? If so, please provide a link or other access point.](#is-there-an-erratum-if-so-please-provide-a-link-or-other-access-point) 52 | - [Will the dataset be updated (e.g., to correct labeling errors, add new instances, delete instances)? If so, please describe how often, bywhom, and how updates will be communicated to users (e.g., mailing list, GitHub)?](#will-the-dataset-be-updated-eg-to-correct-labeling-errors-add-new-instances-delete-instances-if-so-please-describe-how-often-bywhom-and-how-updates-will-be-communicated-to-users-eg-mailing-list-github) 53 | - [Will older versions of the dataset continue to be supported/hosted/maintained?](#will-older-versions-of-the-dataset-continue-to-be-supportedhostedmaintained) 54 | - [If others want to extend/augment/build on/contribute to the dataset, is there a mechanism for them to do so? Will these contributions be validated/verified? If not, why not? Is there a process for communicating/distributing these contributions to other users?](#if-others-want-to-extendaugmentbuild-oncontribute-to-the-dataset-is-there-a-mechanism-for-them-to-do-so-will-these-contributions-be-validatedverified-if-not-why-not-is-there-a-process-for-communicatingdistributing-these-contributions-to-other-users) 55 | 56 | ## Motivation 57 | 58 | ### For what purpose was the dataset created? 59 | 60 | At Quicksign, we thrive to deliver smart and powerful document analysis tools for digital onboarding. 61 | To do so, our R&D team applies state-of-the-art research from computer vision, deep learning and natural language processing. 62 | We work at lot with optical character recognition (OCR) and although we deploy lots of efforts to make it as accurate as possible, we sometimes have to deal with noisy text due to recognition errors. 63 | To our surprise, very few public datasets for text classification address this problem. From IMDB and Amazon reviews to Toxic Tweets classification, existing datasets deal with user-generated content which can be considered "clean". 64 | 65 | Leveraging a previous dataset of more than 400,000 annotated document images, we applied Tesseract OCR to generate two new text datasets. We reuse the existing classification labels. 66 | By combining the generated text files and the existing labels, this repository constitutes a new text classification dataset. 67 | We hope this help the field go further into automated document image analysis. 68 | 69 | ### Who created this dataset and on behalf of which entity? 70 | 71 | This dataset was built by Nicolas Audebert, Catherine Herold and Kuider Slimani while employed in the Quicksign Research and Development team on behalf of [Quicksign](https://quicksign.com). 72 | The original document images dataset from which the texts have been extracted were created respectively by Adam Harley et al. at Ryerson University ([RVL-CDIP](http://www.cs.cmu.edu/~aharley/rvl-cdip/)) and Jayant Kumar et al. at University of Maryland ([Tobacco3482](https://lampsrv02.umiacs.umd.edu/projdb/project.php?id=72)). 73 | 74 | ## Composition 75 | 76 | ### What do the instances that comprise the dataset represent? 77 | 78 | Each instance is a pair between a text document labeled with its type. Documents have been extracted from the [Truth Tobacco Industry Documents](https://www.industrydocuments.ucsf.edu/tobacco/) archive which houses corporate documents that have been made public during litigation between the US governement and several major tobacco companies. 79 | 80 | ### How many instances are there in total ? 81 | 82 | The dataset consists in 399,999 + 3,482 = 403,481 text files and as many labels. 83 | 84 | ### Does the dataset contain all possible instances or is it a sample (not necessarily random) of instances from a larger set? 85 | 86 | The dataset does not contain all possible instances. It is a subset from the still-updated (as of April 2019) [Truth Tobacco Industry Documents](https://www.industrydocuments.ucsf.edu/tobacco/) which contains more than 14 million unique documents and more than 90 million pages. 87 | 88 | ### What data does each instance consist of? 89 | 90 | Each instance is a text file encoded in UTF-8. The text was extracted from digitized documents using optical character recognition. 91 | 92 | ### Is there a label or target associated with each instance? 93 | 94 | Each text file is accompanied by a label indicating the document category it belongs to (e.g. "email" or "scientific report"). 95 | 96 | ### Is any information missing from individual instances? 97 | 98 | One text file is missing from the QS-OCR-Large dataset since the corresponding image in the RVL-CDIP dataset was corrupted (`2500126531_2500126536.tif`). 99 | Some text files might be empty due to failures of the OCR: absence of detected text in the corresponding image. 100 | Otherwise, everything is included in the dataset. 101 | 102 | ### Are relationships between individual instances made explicit (e.g.,users’ movie ratings, social network links) ? 103 | 104 | Due to the corporate natures of the documents, especially emails, some people and entities might be named and appear in several documents. No relationships between instances are explicited in the dataset and we are not aware of stronger relationships than just appearing the same corpus (i.e. the Truth Tobacco Industry Documents public archive). 105 | 106 | ### Are there recommended data splits ? 107 | 108 | The QS-OCR-Large comes with a predefined training/validation/testing split according to the one used by Harley et al. in their ICDAR'15 paper for the RVL-CDIP. 109 | 110 | The QS-OCR-Small does not come with such a split and we recommend evaluating models using k-fold cross-validation. 111 | 112 | ### Are there any errors, sources of noise, or redundancies in the dataset? 113 | 114 | The dataset contains a significant part of noise due to the OCR processing. Spelling errors, missing words and spurious words are common. 115 | Some text files can be identical or near-identical due to the images containing originally the same text. 116 | 117 | ### Is the dataset self-contained, or does it link to or otherwise rely onexternal resources (e.g., websites, tweets, other datasets)? 118 | 119 | The text dataset is self-contained. However, its generation relies on the availability of the Tobacco3482 and RVL-CDIP datasets. For multimodal learning, e.g. document classification based on both text and image, these datasets are also required. 120 | The Tobacco3482 dataset has been archived by the [Internet Archive](https://web.archive.org/web/20160301000000*/https://lampsrv02.umiacs.umd.edu/projdb/project.php?id=72). 121 | The RVL-CDIP is only available through Google Drive as far we know. 122 | 123 | ### Does the dataset contain data that might be considered confidential (e.g., data that is protected by legal privilege or by doctor-patient confidentiality, data that includes the content of individuals non-public communications)? 124 | 125 | This dataset only contains data that has been ruled publicly accessible and is already available in the Truth Tobacco Industry Documents archive. 126 | 127 | ### Does the dataset contain data that, if viewed directly, might be offensive, insulting, threatening, or might otherwise cause anxiety? 128 | 129 | Not that we know of. 130 | 131 | ### Does the dataset contain data that might be considered sensitive in any way? 132 | 133 | The dataset contains data regarding the internal organization of tobacco companies, although these are already public on the Truth Tobacco Industry Documents archive. 134 | 135 | ## Collection process 136 | 137 | ### How was the data associated with each instance acquired? 138 | 139 | The text was extracted using OCR and the labels were reused from the Tobacco3482 and RVL-CDIP datasets. 140 | 141 | ### What mechanisms or procedures were used to collect the data (e.g., hardware apparatus or sensor, manual human curation, software program, software API)? 142 | 143 | The text was extracted from document images using the [Tesseract OCR engine](https://github.com/tesseract-ocr/tesseract/). 144 | 145 | ### If the dataset is a sample from a larger set, what was the sampling strategy (e.g., deterministic, probabilistic with specific sampling probabilities) 146 | 147 | We do not know how Harley et al. and Kumar et al. sampled the images from the larger TTID archive. 148 | 149 | ### Who was involved in the data collection process (e.g., students, crowdworkers, contractors) and how were they compensated (e.g.,how much were crowdworkers paid)? 150 | 151 | The dataset was built by employees of the R&D team at Quicksign. 152 | 153 | ### Over what timeframe was the data collected? 154 | 155 | Document images cover several years and therefore so do the texts. The dataset was built in 2019 over several weeks. 156 | 157 | ### Were any ethical review processes conducted (e.g., by an institutional review board)? 158 | 159 | No. 160 | 161 | ### Does the dataset relate to people? 162 | 163 | This dataset relates to people in that the texts have been authored by people and might refer to others. 164 | 165 | ### Did you collect the data from the individuals in question directly, or obtain it via third parties or other sources (e.g., websites)? 166 | 167 | The data was obtained through the RVL-CDIP and Tobacco3482, which have been built using documents from the TTID archive. 168 | 169 | ### Were the individuals in question notified about the data collection? 170 | 171 | Unknown. Since documents have been made public during legal procedures (e.g. litigations) of which the involved institutions are aware. 172 | 173 | ### Did the individuals in question consent to the collection and use oftheir data? 174 | 175 | No, see previous question. 176 | 177 | ## Preprocessing/cleaning/labeling 178 | 179 | ### Was any preprocessing/cleaning/labeling of the data done (e.g., discretization or bucketing, tokenization, part-of-speech tagging, SIFTfeature extraction, removal of instances, processing of missing values)? 180 | 181 | No specific preprocessing was used. Tesseract was directly applied to the original TIFF images. 182 | 183 | ### Was the "raw" data saved in addition to the preprocessed/cleaned/labeled data (e.g.,to support unanticipated future uses)? 184 | 185 | The text dataset is the raw data computed by Tesseract. 186 | 187 | ### Is the software used to preprocess/clean/label the instances available? 188 | 189 | Yes, on [Github](https://github.com/Quicksign/ocrized-text-dataset). 190 | 191 | ## Uses 192 | 193 | ### Has the dataset been used for any tasks already? 194 | At the time of first release, the dataset has only been used internally at Quicksign. 195 | 196 | ### Is there a repository that links to any or all papers or systems that use the dataset? 197 | 198 | No. 199 | 200 | ### What (other) tasks could the dataset be used for? 201 | 202 | The dataset could be used for anything related to modeling or understanding OCRized documents. This includes self-supervised/unsupervised modeling of documents with plausible OCR errors. 203 | 204 | ### Is there anything about the composition of the dataset or the way it was collected and preprocessed/cleaned/labeled that might impact future uses? 205 | 206 | Not that we are aware of. 207 | 208 | ### Are there tasks for which the dataset should not be used? 209 | 210 | The dataset should not be used to model generic noisy language. Human errors, especially when talking or writing text, do not follow the same distribution as OCR errors. OCR might confuse similarly looking characters such as "l" and "|" which is not something that a human might do when typing on a keyboard. Therefore, this dataset is only reprentative of OCRized text, not general natural language. 211 | 212 | ## Distribution 213 | 214 | ### Will the dataset be distributed to third parties outside of the entity (e.g., company, institution, organization) on behalf of which the dataset was created? 215 | 216 | Yes, the dataset is publicly available on the Internet. 217 | 218 | ### How will the dataset will be distributed (e.g., tarball on website, API, GitHub)? Does the dataset have a digital object identifier (DOI)? 219 | 220 | The dataset will be distributed (including code) on Github: [https://github.com/Quicksign/ocrized-text-dataset](https://github.com/Quicksign/ocrized-text-dataset). 221 | The dataset does not have a DOI. 222 | 223 | ### Will the dataset be distributed under a copyright or other intellectualproperty (IP) license, and/or under applicable terms of use (ToU)? 224 | 225 | The crawled data copyright from the TTID archive belongs to the authors of the documents. There is no license although this work depends on the previous publications: 226 | 227 | * A. W. Harley, A. Ufkes, K. G. Derpanis, "Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval," in ICDAR, 2015. 228 | * J. Kumar, P. Ye and D. Doermann, "Structural Similarity for Document Image Classification and Retrieval", in Pattern Recognition Letters, November 2013. 229 | 230 | It is expected that these are cited when using this dataset to acknowledge their work in agregating and labeling the original document images. 231 | 232 | ### Have any third parties imposed IP-based or other restrictions on thedata associated with the instances? 233 | 234 | No. 235 | 236 | ### Do any export controls or other regulatory restrictions apply to thedataset or to individual instances? 237 | 238 | Unknown. 239 | 240 | ## Maintenance 241 | 242 | ### Who is supporting/hosting/maintaining the dataset? 243 | 244 | Nicolas Audebert is supporting and maintaining the dataset. The dataset is hosted on Quicksign's public Github repository. 245 | 246 | ### How can the owner/curator/manager of the dataset be contacted (e.g., email address)? 247 | 248 | The recommended contact point is the Github repository issues. 249 | 250 | ### Is there an erratum? If so, please provide a link or other access point. 251 | 252 | No. 253 | 254 | ### Will the dataset be updated (e.g., to correct labeling errors, add new instances, delete instances)? If so, please describe how often, bywhom, and how updates will be communicated to users (e.g., mailing list, GitHub)? 255 | 256 | The dataset might be updated depending on how OCR performance improves in the near future. News will be posted on the Github repository if this is the case. 257 | 258 | ### Will older versions of the dataset continue to be supported/hosted/maintained? 259 | 260 | Older versions stay available on the releases section of the Github repository. Obsolete version will be tagged as such. 261 | 262 | ### If others want to extend/augment/build on/contribute to the dataset, is there a mechanism for them to do so? Will these contributions be validated/verified? If not, why not? Is there a process for communicating/distributing these contributions to other users? 263 | 264 | Others may do so and should contact the original authors about incorporating fixes/extensions. Pull requests are welcomed on the repository to include new information and contributions will be curated and merged by the authors. -------------------------------------------------------------------------------- /datasheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickSign/ocrized-text-dataset/8d90fee5b51037699c0baaaaa1f70bfb7f2d4f24/datasheet.pdf -------------------------------------------------------------------------------- /poetry.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | category = "main" 3 | description = "Lightweight pipelining: using Python functions as pipeline jobs." 4 | name = "joblib" 5 | optional = false 6 | python-versions = "*" 7 | version = "0.13.2" 8 | 9 | [[package]] 10 | category = "main" 11 | description = "Python Imaging Library (Fork)" 12 | name = "pillow" 13 | optional = false 14 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" 15 | version = "6.0.0" 16 | 17 | [[package]] 18 | category = "main" 19 | description = "Python-tesseract is a python wrapper for Google's Tesseract-OCR" 20 | name = "pytesseract" 21 | optional = false 22 | python-versions = "*" 23 | version = "0.2.6" 24 | 25 | [package.dependencies] 26 | Pillow = "*" 27 | 28 | [[package]] 29 | category = "main" 30 | description = "Fast, Extensible Progress Meter" 31 | name = "tqdm" 32 | optional = false 33 | python-versions = ">=2.6, !=3.0.*, !=3.1.*" 34 | version = "4.31.1" 35 | 36 | [metadata] 37 | content-hash = "b240b93bab1937d57c3b779773ac9c7675eebe12a69d3e97a0b724cc9e2f4c18" 38 | python-versions = ">=3.5" 39 | 40 | [metadata.hashes] 41 | joblib = ["21e0c34a69ad7fde4f2b1f3402290e9ec46f545f15f1541c582edfe05d87b63a", "315d6b19643ec4afd4c41c671f9f2d65ea9d787da093487a81ead7b0bac94524"] 42 | pillow = ["0683e80d81e840d401b687ebc00a02bbb23d0793c34d0852a5af64cfa1589540", "09c4e81c3277199898e8dc2d85d94febad87c41251ecbd447ba7d64d94765bd8", "0ee74a23022af9baf997e3016b4e090e4ff08688d37a6f49010338ab46cfe101", "10860baedfe5da7c43cd17835b091494dcc59dda5ad176a011713fe398ea6ac2", "15c056bfa284c30a7f265a41ac4cbbc93bdbfc0dfe0613b9cb8a8581b51a9e55", "1a4e06ba4f74494ea0c58c24de2bb752818e9d504474ec95b0aa94f6b0a7e479", "1c3c707c76be43c9e99cb7e3d5f1bee1c8e5be8b8a2a5eeee665efbf8ddde91a", "1fd0b290203e3b0882d9605d807b03c0f47e3440f97824586c173eca0aadd99d", "24114e4a6e1870c5a24b1da8f60d0ba77a0b4027907860188ea82bd3508c80eb", "258d886a49b6b058cd7abb0ab4b2b85ce78669a857398e83e8b8e28b317b5abb", "2734c55f7d054b0ad889c971136cbb0a5b35a921e27beaa44fdc2436af529c6e", "2ac36ec56727a95bd5a04dfca6abce1db8042c31ee73b65796a42f31fd52d009", "2bc1002b573d107c0b172a5da0f34b4900b2ddc6c3296b82d601e966d5ac1959", "33c79b6dd6bc7f65079ab9ca5bebffb5f5d1141c689c9c6a7855776d1b09b7e8", "367385fc797b2c31564c427430c7a8630db1a00bd040555dfc1d5c52e39fcd72", "3c1884ff078fb8bf5f63d7d86921838b82ed4a7d0c027add773c2f38b3168754", "44e5240e8f4f8861d748f2a58b3f04daadab5e22bfec896bf5434745f788f33f", "46aa988e15f3ea72dddd81afe3839437b755fffddb5e173886f11460be909dce", "492e1e4df823b57f9334f591c78a1e0e65a361e92594534e0568eeeeea56bbba", "50fb9e25d25cfcb50b2e6842c4e104e4f0b424be4624e1724532bf005c67589a", "5ceadd60dbd1e56ab7faffbfee1df5ecb83c3f0420e47f652cd5306d70eb0296", "74d90d499c9c736d52dd6d9b7221af5665b9c04f1767e35f5dd8694324bd4601", "7eeac51fc37e6b19631a4b8e38b8261a074efcf7cc27fc16a6bee4697af7aaa5", "809c0a2ce9032cbcd7b5313f71af4bdc5c8c771cb86eb7559afd954cab82ebb5", "85d1ef2cdafd5507c4221d201aaf62fc9276f8b0f71bd3933363e62a33abc734", "8c3889c7681af77ecfa4431cd42a2885d093ecb811e81fbe5e203abc07e0995b", "9218d81b9fca98d2c47d35d688a0cea0c42fd473159dfd5612dcb0483c63e40b", "9319215530e236822169cbe92426cdc18d16b88c943fdf365a6309a89876e335", "96ec275c83bf839972d6a7dd7d685fdfb6a3233c3c382ecff839d04e7d53955d", "9aa4f3827992288edd37c9df345783a69ef58bd20cc02e64b36e44bcd157bbf1", "9d80f44137a70b6f84c750d11019a3419f409c944526a95219bea0ac31f4dd91", "b7ebd36128a2fe93991293f997e44be9286503c7530ace6a55b938b20be288d8", "c30857e1fbf7d4a4b79d7d376eefaf293ea4307b8293d00a62e6f517f51bfe9b", "c4c78e2c71c257c136cdd43869fd3d5e34fc2162dc22e4a5406b0ebe86958239", "c5472ea3945e8f9eb0659f37fc1f592fd06f4f725f0f03774a8999ad8c130334", "c6a842537f887be1fe115d8abb5daa9bc8cc124e455ff995830cc785624a97af", "cf0a2e040fdf5a6d95f4c286c6ef1df6b36c218b528c8a9158ec2452a804b9b8", "cfd28aad6fc61f7a5d4ee556a997dc6e5555d9381d1390c00ecaf984d57e4232", "d0fd1ec2e7c3e0aeaae999efe83f5d0f42c1160a1f8be5120d40857d20baa452", "dca5660e25932771460d4688ccbb515677caaf8595f3f3240ec16c117deff89a", "de7aedc85918c2f887886442e50f52c1b93545606317956d65f342bd81cb4fc3", "e6c0bbf8e277b74196e3140c35f9a1ae3eafd818f7f2d3a15819c49135d6c062"] 43 | pytesseract = ["11c20321595b6e2e904b594633edf1a717212b13bac7512986a2d807b8849770"] 44 | tqdm = ["d385c95361699e5cf7622485d9b9eae2d4864b21cd5a2374a9c381ffed701021", "e22977e3ebe961f72362f6ddfb9197cc531c9737aaf5f607ef09740c849ecd05"] 45 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "ocrized-text-dataset" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Nicolas Audebert "] 6 | 7 | [tool.poetry.dependencies] 8 | python = ">=3.5" 9 | pytesseract = "^0.2.6" 10 | tqdm = "^4.31" 11 | joblib = "^0.13.2" 12 | Pillow = "^6.0" 13 | 14 | [tool.poetry.dev-dependencies] 15 | 16 | [build-system] 17 | requires = ["poetry>=0.12"] 18 | build-backend = "poetry.masonry.api" 19 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Quicksign OCRized Text Dataset (QS-OCR) 2 | 3 | ![Quicksign Logo](https://www.quicksign.com/wp-content/uploads/2018/07/Logo-QuickSign-935x193-.png) 4 | 5 | - [Quicksign OCRized Text Dataset (QS-OCR)](#quicksign-ocrized-text-dataset-qs-ocr) 6 | - [Download](#download) 7 | - [Motivation](#motivation) 8 | - [Details](#details) 9 | - [QS-OCR-Large](#qs-ocr-large) 10 | - [QS-OCR-Small](#qs-ocr-small) 11 | - [Methodology](#methodology) 12 | - [How to reproduce](#how-to-reproduce) 13 | - [Using Docker](#using-docker) 14 | - [Manual installation](#manual-installation) 15 | 16 | The Quicksign OCRized Text Dataset is a collection of more than 400,000 labeled text files that have been extracted from real documents using optical character recognition (OCR). Each file is associated to a class of interest such as email, advertisement or scientific publication. 17 | 18 | It is based on the [RVL-CDIP (Ryerson Vision Lab Complex Document Information Processing) dataset](http://www.cs.cmu.edu/~aharley/rvl-cdip/) [^1] and the [Tobacco3482 dataset](https://lampsrv02.umiacs.umd.edu/projdb/project.php?id=72) [^2]. Both datasets are subsets of the large [Truth Tobacco Industry Documents](https://www.industrydocuments.ucsf.edu/tobacco/) archive. 19 | 20 | This README tries to follow the Datasheets for Datasets guidelines [^3]. See the [datasheet](datasheet.pdf) for more information. 21 | 22 | *First release*: May 2019. 23 | 24 | [^1]: A. W. Harley, A. Ufkes, K. G. Derpanis, "Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval," in ICDAR, 2015. 25 | [^2]: J. Kumar, P. Ye and D. Doermann, "Structural Similarity for Document Image Classification and Retrieval", in Pattern Recognition Letters, November 2013. 26 | [^3]: T. Gebru, J. Morgenstern, B. Vecchione, J. W. Vaughan, H. Wallach, H. Daumé III and K. Crawford, "Datasheets for Datasets," in CoRR, 2018. 27 | 28 | ## Download 29 | 30 | Both datasets are available in the ["releases" section](https://github.com/Quicksign/ocrized-text-dataset/releases). 31 | 32 | ## Motivation 33 | 34 | At Quicksign, we thrive to deliver smart and powerful document analysis tools for digital onboarding. 35 | To do so, our R&D team applies state-of-the-art research from computer vision, deep learning and natural language processing. 36 | We work at lot with optical character recognition (OCR) and although we deploy lots of efforts to make it as accurate as possible, we sometimes have to deal with noisy text due to recognition errors. 37 | To our surprise, very few public datasets for text classification address this problem. From IMDB and Amazon reviews to Toxic Tweets classification, existing datasets deal with user-generated content which can be considered "clean". 38 | 39 | Leveraging a previous dataset of more than 400,000 annotated document images, we applied Tesseract OCR to generate two new text datasets. We reuse the existing classification labels. 40 | By combining the generated text files and the existing labels, this repository constitutes a new text classification dataset. 41 | We hope this help the field go further into automated document image analysis. 42 | 43 | ## Details 44 | 45 | There are two versions of the dataset: QS-OCR-Large and QS-OCR-Small. 46 | 47 | ### QS-OCR-Large 48 | 49 | QS-OCR-Large is the result of running the [Tesseract OCR](https://github.com/tesseract-ocr/tesseract/) tool on the documents from the RVL-CDIP dataset. 50 | It contains 400,000 labeled text documents in 15 classes: 51 | 52 | * 0. Letter 53 | * 1. Form 54 | * 2. Email 55 | * 3. Handwritten 56 | * 4. Advertisement 57 | * 5. Scientific report 58 | * 6. Scientific publication 59 | * 7. Specification 60 | * 8. File folder 61 | * 9. News article 62 | * 10. Budget 63 | * 11. Invoice 64 | * 12. Presentation 65 | * 13. Questionnaire 66 | * 14. Resume 67 | * 15. Memo 68 | 69 | We use the same format as the original RVL-CDIP dataset and the same folder structure as to remain as compatible as possible. 70 | Train, validation and test splits are predefined and given in a text format: 71 | 72 | ```bash 73 | path/to/the/text/file.txt category 74 | ``` 75 | 76 | ### QS-OCR-Small 77 | 78 | QS-OCR-Small is the result of running the [Tesseract OCR](https://github.com/tesseract-ocr/tesseract/) tool on the documents from the Tobacco3482 dataset. 79 | It contains 3,482 labeled text documents in 10 classes: 80 | 81 | * 0. Advertisement (ADVE) 82 | * 1. Email 83 | * 2. Form 84 | * 3. Letter 85 | * 4. Memo 86 | * 5. News 87 | * 6. Note 88 | * 7. Report 89 | * 8. Resume 90 | * 9. Scientific 91 | 92 | We use the same folder structure as the original dataset to remain as compatible as possible. 93 | Samples for each class are stored in specifically named folder. 94 | 95 | As there are no predefined train/val/test split, we encourage users to perform k-fold cross-validation on this dataset. 96 | 97 | **Be careful:** there is some partial overlap between QS-OCR-Small and QS-OCR-Large (due to overlap between Tobacco3482 and RVL-CDIP). Take care to remove the common samples if you want to evaluate transfer learning performance. 98 | 99 | ## Methodology 100 | 101 | Thanks to the effort of the Truth Tobacco Industry Documents archive, document images from the datasets are well-oriented and relatively clean. 102 | It is quite straightforward to run the [Tesseract OCR](https://github.com/tesseract-ocr/tesseract/) engine on such documents. 103 | 104 | We used the version `4.0.0-beta.1` of Tesseract using the following parameters: 105 | 106 | * LSTM engine for better accuracy (`--oem 1`), 107 | * fully automatic page segmentation without orientation or script detection (`--psm 3`), 108 | * English language (`-l eng`). 109 | 110 | We relied on the Python library [pytesseract](https://github.com/madmaze/pytesseract) for automation. 111 | 112 | We did not preprocess further the original TIFF grayscale images since they were clean scanned documents to begin with. 113 | 114 | The resulting text was not postprocessed. Although it could benefit from some level of spell checking, we chose to provide the true output of Tesseract OCR "as is". 115 | 116 | ## How to reproduce 117 | 118 | In addition to the generated text files, we also provide scripts to regenerate the text outputs from the document images based on the existing annotated RVL-CDIP and Tobacco3482 datasets. 119 | These scripts have been tested on Ubuntu 18.04 although they should also work on MacOS X and Windows (using WSL). 120 | 121 | ### Using Docker 122 | 123 | The simplest way to reproduce the dataset is using [Docker](https://docker.com). 124 | 125 | After cloning the repository, run: 126 | 127 | ```bash 128 | docker build . -t qs/ocrized 129 | mkdir -p datasets && docker run --user $(id -u):$(id -g) -it --rm \ 130 | -v `pwd`/datasets:/work/datasets/ qs/ocrized 131 | # --user $(id -u):$(id -g) sets the user in the container as the user 132 | # that runs the command (useful with the shared directory) 133 | # -it activates interactive mode 134 | # --rm deletes the container after usage 135 | # -v mounts a volume that will be seen inside the container 136 | ``` 137 | 138 | _Note_: if you use [Task](https://taskfile.dev), you can simply execute `task run`. 139 | 140 | This will create a `datasets/` folder in the current directory and mount it in the container. 141 | Running the `tobacco3842.sh` or `rvl-cdip.sh` scripts will download and process the datasets as needed. 142 | 143 | For example: 144 | ```bash 145 | ./tobacco3842.sh 146 | # Downloading files from UMIACS server... 147 | # Decompressing .zip archives... 148 | # 149 | # 2 archives were successfully processed. 150 | # Generating filelist 151 | # Do you want to run the OCR script now? [y/N] N 152 | ``` 153 | 154 | You can manually run the `to_text.py` script using Python if you want. See `python to_text.py -h` for usage information. 155 | 156 | ### Manual installation 157 | 158 | A manual installation needs a few requirements: 159 | 160 | * tesseract, wget, zip, tar, 161 | * a Python 3 interpreter, 162 | * Python dependencies: joblib, tqdm, pytesseract, Pillow, 163 | * *optionally:* the languages files for tesseract (e.g. `tesseract-ocr-fra`, `tesseract-ocr-ger` on Ubuntu). 164 | 165 | _Note_: if you use [Task](https://taskfile.dev), you can simply execute `task setup`. 166 | 167 | Installation of Tesseract and other softwares is OS-dependent. On Ubuntu/Debian you can run the `setup.sh` script using root privileges or: 168 | 169 | ```bash 170 | apt-get install -y wget unzip tesseract-ocr 171 | ``` 172 | 173 | Python dependencies can be installed using pip (`pip install -r requirements.txt`) or (**recommended**) using poetry: 174 | 175 | ```bash 176 | # Use pip install poetry if you do not use poetry yet 177 | poetry install 178 | poetry shell 179 | ``` 180 | 181 | Running the `tobacco3842.sh` or `rvl-cdip.sh` scripts will download and process the datasets as needed. 182 | 183 | ```bash 184 | ./tobacco3842.sh 185 | # Downloading files from UMIACS server... 186 | # Decompressing .zip archives... 187 | # 188 | # 2 archives were successfully processed. 189 | # Generating filelist 190 | # Do you want to run the OCR script now? [y/N] N 191 | ``` 192 | 193 | You can manually run the `to_text.py` script using Python if you want. See `python to_text.py -h` for usage information. 194 | -------------------------------------------------------------------------------- /readme.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickSign/ocrized-text-dataset/8d90fee5b51037699c0baaaaa1f70bfb7f2d4f24/readme.pdf -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.13.2 2 | Pillow==6.0.0 3 | pytesseract==0.2.6 4 | tqdm==4.31.1 5 | -------------------------------------------------------------------------------- /rvl-cdip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | FILELIST=images/filelist.txt 4 | 5 | wget_from_gdrive() { 6 | # This is a helper function to download files from Google Drive despite the annoying 7 | # "file to large to scan" antivirus warning. 8 | TMP_COOKIES=/tmp/cookies.txt 9 | CONFIRM_FILE=/tmp/confirm.txt 10 | fileid="$1" 11 | filename="$2" 12 | wget -q --save-cookies "${TMP_COOKIES}" 'https://docs.google.com/uc?export=download&id='$fileid -O- \ 13 | | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p' > "${CONFIRM_FILE}" 14 | 15 | wget -nv --show-progress -c --load-cookies "${TMP_COOKIES}" -O "$filename" \ 16 | 'https://docs.google.com/uc?export=download&id='$fileid'&confirm='$(<"${CONFIRM_FILE}") 17 | 18 | rm "${TMP_COOKIES}" 19 | } 20 | 21 | FOLDER=datasets/rvl-cdip/ 22 | mkdir -p "${FOLDER}" && cd "${FOLDER}" 23 | echo "Downloading files from Google Drive..." 24 | wget_from_gdrive "0B0NKIRwUL9KYcXo3bV9LU0t3SGs" labels.tar.gz 25 | wget_from_gdrive "0Bz1dfcnrpXM-MUt4cHNzUEFXcmc" images.tar.gz 26 | echo "Extracting archives..." 27 | tar xvzf labels.tar.gz 28 | echo "Generating filelist" 29 | cat labels/{train,val,test}.txt | cut -d ' ' -f 1 > "${FILELIST}" 30 | for file in train.txt val.txt test.txt; do 31 | sed 's/\.tif/.txt/g' < "${file}" > "text_${file}.txt" 32 | done 33 | read -p "Do you want to run the OCR script now? " -n 1 -r 34 | if [[ $REPLY =~ ^[Yy]$ ]] 35 | then 36 | python ../../to_text.py "${FILELIST}" --lang eng --format txt 37 | else 38 | echo 39 | fi -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | apt-get update && apt-get install -y wget unzip tesseract-ocr 3 | -------------------------------------------------------------------------------- /to_text.py: -------------------------------------------------------------------------------- 1 | """ 2 | Convert a list of images to text using Tesseract OCR. 3 | Author: nicolas.audebert@quicksign.com 4 | """ 5 | import argparse 6 | import os 7 | import pytesseract 8 | 9 | from builtins import str 10 | from joblib import Parallel, delayed 11 | from PIL import Image 12 | from tqdm import tqdm 13 | 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument("file", type=str, help="Path to the file containing the list of docs to OCR") 16 | parser.add_argument( 17 | "--lang", 18 | type=str, 19 | default="eng", 20 | help="Language to use for Tesseract, e.g. fra, eng, ger, ... (default=eng)", 21 | ) 22 | parser.add_argument( 23 | "--jobs", type=int, default=1, help="Number of parallel jobs to run (default=1)" 24 | ) 25 | parser.add_argument( 26 | "--format", 27 | type=str, 28 | default="txt", 29 | help="Output Tesseract format, either .txt or .hocr (default=.txt)", 30 | ) 31 | parser.add_argument("--noerror", action="store_true", default=False, help="Ignore errors.") 32 | 33 | 34 | def to_text(filename, lang="eng", format_="txt", ignore_error=False): 35 | """ Extract text from an image using Tesseract OCR. 36 | 37 | Arguments: 38 | filename {str} -- path to an image 39 | 40 | Keyword Arguments: 41 | lang {str} -- Tesseract OCR language option (default: "eng") 42 | format_ {str} -- Tesseract output format (.hocr or .txt, default: "txt") 43 | ignore_error {bool} -- catch and ignore all exceptions (default: False) 44 | """ 45 | try: 46 | im = Image.open(filename) 47 | basename, ext = os.path.splitext(filename) 48 | target = basename + "." + format_ 49 | if format_ == "txt": 50 | tess_output = pytesseract.image_to_string(im, lang=lang, config="--psm 3 --oem 1") 51 | elif format_ == "hocr": 52 | tess_output = pytesseract.image_to_pdf_or_hocr( 53 | im, lang=lang, config="--psm 3 --oem 1", extension=format_ 54 | ) 55 | with open(target, "w") as fp: 56 | fp.write(str(tess_output)) 57 | except Exception as e: 58 | if ignore_error: 59 | print("Error: {}".format(e)) 60 | else: 61 | raise e 62 | 63 | 64 | if __name__ == "__main__": 65 | args = parser.parse_args() 66 | with open(args.file, "r") as f: 67 | dirname = os.path.dirname(args.file) 68 | filenames = map(str.strip, f.readlines()) 69 | filenames = list(map(lambda path: os.path.join(dirname, path), filenames)) 70 | Parallel(n_jobs=args.jobs)( 71 | delayed(to_text)(filename, lang=args.lang, format_=args.format, ignore_error=args.noerror) 72 | for filename in tqdm(filenames) 73 | ) 74 | -------------------------------------------------------------------------------- /tobacco3482.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | FOLDER=datasets/Tobacco3482/ 3 | mkdir -p "${FOLDER}" && cd "${FOLDER}" 4 | echo "Downloading files from UMIACS server..." 5 | wget -nv --show-progress -c http://lampsrv02.umiacs.umd.edu/projdb/edit/userfiles/datasets/Tobacco3482_1.zip 6 | wget -nv --show-progress -c http://lampsrv02.umiacs.umd.edu/projdb/edit/userfiles/datasets/Tobacco3482_2.zip 7 | echo "Decompressing .zip archives..." 8 | unzip -q -n 'Tobacco3482_*.zip' 9 | echo "Generating filelist" 10 | find . -name '*.tif' > images.txt 11 | read -p "Do you want to run the OCR script now? [y/N] " -n 1 -r 12 | if [[ $REPLY =~ ^[Yy]$ ]] 13 | then 14 | python ../../to_text.py images.txt --lang eng --format txt 15 | else 16 | echo 17 | fi 18 | sed 's/\.tif/.txt/g' < images.txt > texts.txt 19 | --------------------------------------------------------------------------------