Datasets:
Size:
1M<n<10M
ArXiv:
Tags:
Document_Understanding
Document_Packet_Splitting
Document_Comprehension
Document_Classification
Document_Recognition
Document_Segmentation
DOI:
License:
File size: 2,770 Bytes
165da3c | 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 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 1: Create Assets from Raw PDFs\n",
"\n",
"This notebook processes raw PDFs and creates structured assets:\n",
"- Page images (PNG at 300 DPI)\n",
"- OCR text (AWS Textract)\n",
"\n",
"**Output**: Structured assets for benchmark creation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(\"../src/assets\")\n",
"\n",
"from services.pdf_loader import PdfLoader\n",
"from services.textract_ocr import TextractOcr\n",
"from services.asset_writer import AssetWriter\n",
"from services.asset_creator import AssetCreator"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configuration"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"RAW_DATA_PATH = '../data/raw_pdfs'\n",
"OUTPUT_PATH = '../data/assets'\n",
"WORKERS = 10\n",
"LIMIT = None # Set to number to limit processing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load PDFs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"loader = PdfLoader(raw_data_path=RAW_DATA_PATH)\n",
"documents = loader.get_all_documents()\n",
"\n",
"print(f\"Loaded {len(documents)} documents\")\n",
"print(f\"Sample: {documents[0]}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create Assets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ocr = TextractOcr()\n",
"writer = AssetWriter(output_base_path=OUTPUT_PATH)\n",
"creator = AssetCreator(writer, ocr)\n",
"\n",
"results = creator.create_all(\n",
" documents=documents,\n",
" workers=WORKERS,\n",
" limit=LIMIT\n",
")\n",
"\n",
"print(f\"\\nResults: {results}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save Document Mapping (Optional)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"loader.save_document_mapping(\n",
" documents,\n",
" output_path='../data/document_mapping.csv'\n",
")\n",
"\n",
"print(\"Document mapping saved!\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|