Datasets:
Upload verify dataset structure is correct.ipynb
Browse files
verify dataset structure is correct.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyMb0QuoCez3cbeulUoUrA1F"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"widgets":{"application/vnd.jupyter.widget-state+json":{"version_major":2,"version_minor":0,"state":{"a36734ba4f154559bd4c765732c496d5":{"model_module":"@jupyter-widgets/controls","model_name":"HBoxModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_b4dcf94ec56a4298b03242224f5da144","IPY_MODEL_57078d9c5ca84aacb31fd1dee9587d47","IPY_MODEL_08ccc9a968d04b7fa4b9396cc6556a31"],"layout":"IPY_MODEL_734953ff096e4efa97d0724e2a20eac6"}},"b4dcf94ec56a4298b03242224f5da144":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_8ebfe0f086a44d6095cc244e639ad91f","placeholder":"","style":"IPY_MODEL_8269829c75284cdbbad7a5fa8e111a78","value":"README.md: 100%"}},"57078d9c5ca84aacb31fd1dee9587d47":{"model_module":"@jupyter-widgets/controls","model_name":"FloatProgressModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_1ffd3211c8884fe4a9689f367c870219","max":8194,"min":0,"orientation":"horizontal","style":"IPY_MODEL_346c748efba14f07ad08c2ec051a689c","value":8194}},"08ccc9a968d04b7fa4b9396cc6556a31":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_46a8092fe73848968c0b72c5370faf0c","placeholder":"","style":"IPY_MODEL_a09aca2b576744d6955fe55026485738","value":" 8.19k/8.19k [00:00<00:00, 155kB/s]"}},"734953ff096e4efa97d0724e2a20eac6":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"8ebfe0f086a44d6095cc244e639ad91f":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"8269829c75284cdbbad7a5fa8e111a78":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"1ffd3211c8884fe4a9689f367c870219":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"346c748efba14f07ad08c2ec051a689c":{"model_module":"@jupyter-widgets/controls","model_name":"ProgressStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"46a8092fe73848968c0b72c5370faf0c":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"a09aca2b576744d6955fe55026485738":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}}}}}},"cells":[{"cell_type":"code","source":["\n","# ================================================================\n","# HUGGING FACE DATASET VIEWER FAILURE DIAGNOSTIC\n","# READ ONLY - DOES NOT MODIFY THE REPOSITORY\n","#\n","# Repository: codeShare/adcom_captioned_ai_images\n","# Excludes: authors/\n","#\n","# No package upgrades.\n","# No uploads.\n","# No deletions.\n","# ================================================================\n","\n","import os\n","import re\n","import json\n","import requests\n","import pandas as pd\n","import pyarrow.parquet as pq\n","\n","from collections import Counter\n","from huggingface_hub import HfApi, hf_hub_download\n","from tqdm.auto import tqdm\n","\n","REPO = \"codeShare/adcom_captioned_ai_images\"\n","TOKEN = None\n","\n","try:\n"," from huggingface_hub import get_token\n"," TOKEN = get_token()\n","except Exception:\n"," pass\n","\n","api = HfApi(token=TOKEN)\n","\n","OUT = \"/content/adcom_viewer_diagnostic\"\n","os.makedirs(OUT, exist_ok=True)\n","\n","HEADERS = {}\n","if TOKEN:\n"," HEADERS[\"Authorization\"] = f\"Bearer {TOKEN}\"\n","\n","BASE = f\"https://huggingface.co/datasets/{REPO}/resolve/main/\"\n","\n","# ------------------------------------------------\n","# 1. REPOSITORY INVENTORY\n","# ------------------------------------------------\n","\n","print(\"=\" * 65)\n","print(\"1. REPOSITORY INVENTORY\")\n","print(\"=\" * 65)\n","\n","tree = list(api.list_repo_tree(\n"," repo_id=REPO,\n"," repo_type=\"dataset\",\n"," recursive=True\n","))\n","\n","repo_paths = []\n","\n","for item in tree:\n"," if not hasattr(item, \"path\"):\n"," continue\n","\n"," path = item.path\n","\n"," if path.split(\"/\")[0].lower() == \"authors\":\n"," continue\n","\n"," repo_paths.append(path)\n","\n","for path in sorted(repo_paths):\n"," print(path)\n","\n","print(\"\\nTotal files outside authors/:\", len(repo_paths))\n","\n","# ------------------------------------------------\n","# 2. INSPECT DATASET CARD\n","# ------------------------------------------------\n","\n","print(\"\\n\" + \"=\" * 65)\n","print(\"2. DATASET CARD / DECLARED FEATURES\")\n","print(\"=\" * 65)\n","\n","readme_path = None\n","\n","for p in repo_paths:\n"," if p.lower() == \"readme.md\":\n"," readme_path = p\n"," break\n","\n","readme_text = \"\"\n","\n","if readme_path:\n","\n"," try:\n"," local = hf_hub_download(\n"," repo_id=REPO,\n"," repo_type=\"dataset\",\n"," filename=readme_path,\n"," token=TOKEN\n"," )\n","\n"," with open(local, encoding=\"utf-8\") as f:\n"," readme_text = f.read()\n","\n"," print(readme_text[:18000])\n","\n"," with open(\n"," os.path.join(OUT, \"dataset_card.txt\"),\n"," \"w\",\n"," encoding=\"utf-8\"\n"," ) as f:\n"," f.write(readme_text)\n","\n"," except Exception as e:\n"," print(\"README error:\", e)\n","\n","else:\n"," print(\"No root README.md found.\")\n","\n","# ------------------------------------------------\n","# 3. EXTRACT DECLARED FEATURES\n","# ------------------------------------------------\n","\n","print(\"\\n\" + \"=\" * 65)\n","print(\"3. DECLARED FEATURE SCHEMA\")\n","print(\"=\" * 65)\n","\n","features_section = \"\"\n","\n","match = re.search(\n"," r\"(?ms)^features:\\s*(.*?)(?=^[A-Za-z_][A-Za-z0-9_-]*:|\\Z)\",\n"," readme_text\n",")\n","\n","if match:\n"," features_section = match.group(1)\n"," print(features_section[:12000])\n","else:\n"," print(\"No explicit features section found in README YAML.\")\n","\n","# ------------------------------------------------\n","# 4. INSPECT ALL PARQUET SCHEMAS\n","# ------------------------------------------------\n","\n","print(\"\\n\" + \"=\" * 65)\n","print(\"4. PARQUET SCHEMA INSPECTION\")\n","print(\"=\" * 65)\n","\n","parquet_report = []\n","\n","for path in repo_paths:\n","\n"," if not path.lower().endswith(\".parquet\"):\n"," continue\n","\n"," print(\"\\nFILE:\", path)\n","\n"," try:\n","\n"," local = hf_hub_download(\n"," repo_id=REPO,\n"," repo_type=\"dataset\",\n"," filename=path,\n"," token=TOKEN\n"," )\n","\n"," pf = pq.ParquetFile(local)\n","\n"," schema = pf.schema_arrow\n","\n"," print(\"Rows:\", pf.metadata.num_rows)\n"," print(\"Columns:\", schema.names)\n"," print(\"Schema:\")\n"," print(schema)\n","\n"," parquet_report.append({\n"," \"file\": path,\n"," \"rows\": pf.metadata.num_rows,\n"," \"columns\": json.dumps(schema.names),\n"," \"schema\": str(schema)\n"," })\n","\n"," except Exception as e:\n","\n"," print(\"PARQUET ERROR:\", e)\n","\n"," parquet_report.append({\n"," \"file\": path,\n"," \"rows\": None,\n"," \"columns\": None,\n"," \"schema\": str(e)\n"," })\n","\n","# ------------------------------------------------\n","# 5. INSPECT JSON / JSONL FILE STRUCTURES\n","# ------------------------------------------------\n","\n","print(\"\\n\" + \"=\" * 65)\n","print(\"5. JSON / JSONL STRUCTURE INSPECTION\")\n","print(\"=\" * 65)\n","\n","json_report = []\n","\n","checkpoint_fields = {\n"," \"next_output_idx\",\n"," \"next_shard_number\",\n"," \"next_source_index\",\n"," \"last_download_start\",\n"," \"last_checkpoint_time\",\n"," \"source_fingerprint\",\n"," \"successful_count\",\n"," \"failed\",\n"," \"complete\"\n","}\n","\n","for path in repo_paths:\n","\n"," lower = path.lower()\n","\n"," if not (lower.endswith(\".json\") or lower.endswith(\".jsonl\")):\n"," continue\n","\n"," print(\"\\nFILE:\", path)\n","\n"," try:\n","\n"," url = BASE + requests.utils.quote(path, safe=\"/\")\n","\n"," response = requests.get(\n"," url,\n"," headers=HEADERS,\n"," stream=True,\n"," timeout=60\n"," )\n","\n"," response.raise_for_status()\n","\n"," records = []\n"," key_counter = Counter()\n"," checkpoint_hits = Counter()\n"," errors = []\n","\n"," if lower.endswith(\".jsonl\"):\n","\n"," for line_no, line in enumerate(response.iter_lines()):\n","\n"," if not line:\n"," continue\n","\n"," if line_no >= 1000:\n"," break\n","\n"," try:\n"," obj = json.loads(line)\n","\n"," if isinstance(obj, dict):\n","\n"," records.append(obj)\n","\n"," key_counter.update(obj.keys())\n","\n"," checkpoint_hits.update(\n"," set(obj.keys()) & checkpoint_fields\n"," )\n","\n"," except Exception as e:\n"," errors.append((line_no + 1, str(e)))\n","\n"," else:\n","\n"," content = response.content[:10_000_000]\n","\n"," obj = json.loads(content)\n","\n"," if isinstance(obj, list):\n"," records = obj[:1000]\n","\n"," elif isinstance(obj, dict):\n","\n"," records = [obj]\n","\n"," # Also inspect nested record lists.\n"," for key, value in obj.items():\n","\n"," if isinstance(value, list) and value:\n"," if isinstance(value[0], dict):\n"," records.extend(value[:1000])\n","\n"," for record in records:\n","\n"," if isinstance(record, dict):\n","\n"," key_counter.update(record.keys())\n","\n"," checkpoint_hits.update(\n"," set(record.keys()) & checkpoint_fields\n"," )\n","\n"," response.close()\n","\n"," print(\"Records inspected:\", len(records))\n"," print(\"Observed fields:\", sorted(key_counter.keys()))\n","\n"," if checkpoint_hits:\n"," print(\"CHECKPOINT FIELDS:\", dict(checkpoint_hits))\n","\n"," if errors:\n"," print(\"JSON parsing errors:\", errors[:10])\n","\n"," json_report.append({\n"," \"file\": path,\n"," \"records_inspected\": len(records),\n"," \"fields\": json.dumps(sorted(key_counter.keys())),\n"," \"checkpoint_fields\": json.dumps(dict(checkpoint_hits)),\n"," \"errors\": json.dumps(errors[:10])\n"," })\n","\n"," except Exception as e:\n","\n"," print(\"JSON ERROR:\", e)\n","\n"," json_report.append({\n"," \"file\": path,\n"," \"records_inspected\": 0,\n"," \"fields\": \"\",\n"," \"checkpoint_fields\": \"\",\n"," \"errors\": str(e)\n"," })\n","\n","# ------------------------------------------------\n","# 6. CHECK FOR THE VIEWER'S SCHEMA MISMATCH\n","# ------------------------------------------------\n","\n","print(\"\\n\" + \"=\" * 65)\n","print(\"6. VIEWER SCHEMA MISMATCH ANALYSIS\")\n","print(\"=\" * 65)\n","\n","viewer_actual_fields = {\n"," \"idx\", \"image\", \"caption\", \"tags\",\n"," \"next_output_idx\", \"complete\",\n"," \"source_count\", \"source_fingerprint\",\n"," \"next_shard_number\", \"slug\", \"source_json\",\n"," \"author\", \"last_download_start\",\n"," \"last_checkpoint_time\", \"successful_count\",\n"," \"failed\", \"next_source_index\"\n","}\n","\n","viewer_expected_fields = {\n"," \"author\", \"slug\", \"source_json\",\n"," \"source_fingerprint\", \"source_count\",\n"," \"next_source_index\", \"next_output_idx\",\n"," \"next_shard_number\", \"successful_count\",\n"," \"failed\", \"last_download_start\",\n"," \"complete\", \"last_checkpoint_time\"\n","}\n","\n","print(\"\\nFields reported by the viewer:\")\n","print(sorted(viewer_actual_fields))\n","\n","print(\"\\nFields in the viewer's expected schema:\")\n","print(sorted(viewer_expected_fields))\n","\n","print(\"\\nActual fields not declared:\")\n","print(sorted(viewer_actual_fields - viewer_expected_fields))\n","\n","print(\"\\nDeclared fields not present:\")\n","print(sorted(viewer_expected_fields - viewer_actual_fields))\n","\n","print(\"\\nIMPORTANT:\")\n","print(\n"," \"The viewer is attempting to cast a table containing \"\n"," \"image/caption dataset columns and checkpoint columns \"\n"," \"into a checkpoint-only schema.\"\n",")\n","\n","# ------------------------------------------------\n","# 7. SAVE DIAGNOSTIC REPORTS\n","# ------------------------------------------------\n","\n","pd.DataFrame(parquet_report).to_csv(\n"," os.path.join(OUT, \"parquet_schemas.csv\"),\n"," index=False\n",")\n","\n","pd.DataFrame(json_report).to_csv(\n"," os.path.join(OUT, \"json_structures.csv\"),\n"," index=False\n",")\n","\n","summary = {\n"," \"repository\": REPO,\n"," \"files_outside_authors\": len(repo_paths),\n"," \"parquet_files\": len(parquet_report),\n"," \"json_files\": len(json_report),\n"," \"viewer_actual_fields\": sorted(viewer_actual_fields),\n"," \"viewer_expected_fields\": sorted(viewer_expected_fields),\n"," \"undeclared_fields\": sorted(\n"," viewer_actual_fields - viewer_expected_fields\n"," ),\n"," \"missing_fields\": sorted(\n"," viewer_expected_fields - viewer_actual_fields\n"," ),\n"," \"diagnostic_only\": True\n","}\n","\n","with open(\n"," os.path.join(OUT, \"diagnostic_summary.json\"),\n"," \"w\"\n",") as f:\n"," json.dump(summary, f, indent=2)\n","\n","print(\"\\n\" + \"=\" * 65)\n","print(\"DIAGNOSTIC COMPLETE\")\n","print(\"=\" * 65)\n","\n","print(\"Reports:\", OUT)\n","\n","from google.colab import files\n","\n","files.download(\n"," os.path.join(OUT, \"diagnostic_summary.json\")\n",")\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":1000,"referenced_widgets":["a36734ba4f154559bd4c765732c496d5","b4dcf94ec56a4298b03242224f5da144","57078d9c5ca84aacb31fd1dee9587d47","08ccc9a968d04b7fa4b9396cc6556a31","734953ff096e4efa97d0724e2a20eac6","8ebfe0f086a44d6095cc244e639ad91f","8269829c75284cdbbad7a5fa8e111a78","1ffd3211c8884fe4a9689f367c870219","346c748efba14f07ad08c2ec051a689c","46a8092fe73848968c0b72c5370faf0c","a09aca2b576744d6955fe55026485738"]},"id":"sEQu36pgS3AA","outputId":"49a74d37-954f-451a-abb2-8e92854347d3"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["=================================================================\n","1. REPOSITORY INVENTORY\n","=================================================================\n",".gitattributes\n","Append preprocessed author into dataset.ipynb\n","README.md\n","captions.parquet\n","images\n","images/part_00000.jsonl\n","images/part_00001.jsonl\n","images/part_00002.jsonl\n","images/part_00003.jsonl\n","images/part_00004.jsonl\n","images/part_00005.jsonl\n","images/part_00006.jsonl\n","images/part_00007.jsonl\n","images/part_00008.jsonl\n","images/part_00009.jsonl\n","images/part_00010.jsonl\n","images/part_00011.jsonl\n","images/part_00012.jsonl\n","images/part_00013.jsonl\n","images/part_00014.jsonl\n","images/part_00015.jsonl\n","images/part_00016.jsonl\n","images/part_00017.jsonl\n","images/part_00018.jsonl\n","images/part_00019.jsonl\n","images/part_00020.jsonl\n","images/part_00021.jsonl\n","images/part_00022.jsonl\n","images/part_00023.jsonl\n","images/part_00024.jsonl\n","images/part_00025.jsonl\n","images/part_00026.jsonl\n","images/part_00027.jsonl\n","images/part_00028.jsonl\n","images/part_00029.jsonl\n","images/part_00030.jsonl\n","images/part_00031.jsonl\n","images/part_00032.jsonl\n","images/part_00033.jsonl\n","images/part_00034.jsonl\n","images/part_00035.jsonl\n","images/part_00036.jsonl\n","images/part_00037.jsonl\n","images/part_00038.jsonl\n","images/part_00039.jsonl\n","images/part_00040.jsonl\n","images/part_00041.jsonl\n","sample_adcom_dataset.ipynb\n","\n","Total files outside authors/: 48\n","\n","=================================================================\n","2. DATASET CARD / DECLARED FEATURES\n","=================================================================\n"]},{"output_type":"display_data","data":{"text/plain":["README.md: 0%| | 0.00/8.19k [00:00<?, ?B/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"a36734ba4f154559bd4c765732c496d5"}},"metadata":{}},{"output_type":"stream","name":"stdout","text":["---\n","pretty_name: Adcom Captioned AI Images\n","tags:\n","- images\n","- captions\n","- ai-generated-images\n","- natural-language\n","license: apache-2.0\n","language:\n","- en\n","---\n","\n","# ADCOM Captioned AI Images\n","\n","## Dataset description\n","\n","Adcom's captioned AI Images is a collection of images paired with associated\n","captioning and descriptive metadata.\n","\n","The repository uses an indexed storage layout designed to make image retrieval\n","more efficient. Instead of storing all image data directly inside a single\n","metadata file, it separates the metadata index from the image data.\n","\n","The dataset consists of:\n","\n","- A Parquet metadata index: `captions.parquet`\n","- JSONL image shards containing the image data\n","- Byte offsets and record lengths in the Parquet index for direct image access\n","\n","This layout allows users to retrieve individual images without downloading\n","and scanning every image shard.\n","\n","## Repository structure\n","\n","```text\n","adcom_captioned_ai_images/\n","│\n","├── README.md\n","├── captions.parquet\n","│\n","└── [JSONL image shards]\n"," ├── ...\n"," └── ...\n","```\n","\n","The exact shard paths are stored in the `json_file` column of\n","`captions.parquet`. Use those paths rather than assuming fixed shard names.\n","\n","### 1. Metadata index: `captions.parquet`\n","\n","The Parquet file contains one metadata/index row per image.\n","\n","| Column | Description |\n","|---|---|\n","| `idx` | Image identifier |\n","| `prompt` | Text prompt or caption associated with the image |\n","| `tags` | Descriptive tags associated with the image |\n","| `author` | Author or contributor |\n","| `json_file` | Repository-relative path to the JSONL shard containing the image |\n","| `byte_offset` | Zero-based byte offset of the JSONL record within that shard |\n","| `byte_length` | Number of bytes to read for that record |\n","\n","The index columns `json_file`, `byte_offset`, and `byte_length` are used\n","together to locate an image record directly.\n","\n","Offsets and lengths refer to bytes, not character positions.\n","\n","### 2. Image data: JSONL shards\n","\n","Images are stored in JSONL files. Each line represents an individual image\n","record encoded as JSON.\n","\n","A record has the following structure:\n","\n","```json\n","{\n"," \"idx\": \"IMAGE_ID\",\n"," \"image\": \"data:image/png;base64,...\"\n","}\n","```\n","\n","The `image` field contains a base64-encoded image, commonly represented as\n","a data URI. Consumers should also allow for a raw base64 string.\n","\n","The `idx` field identifies the image and corresponds to the `idx` value in\n","the Parquet index.\n","\n","### 3. How indexed retrieval works\n","\n","For an image with a given `idx`:\n","\n","1. Find its row in `captions.parquet`.\n","2. Read the row's `json_file`, `byte_offset`, and `byte_length`.\n","3. Download the referenced JSONL shard.\n","4. Seek to `byte_offset` in binary mode.\n","5. Read `byte_length` bytes.\n","6. Parse the JSON record and decode its base64 image.\n","\n","This avoids scanning the entire shard for the selected image.\n","\n","---\n","\n","## Quick start\n","\n","### Install dependencies\n","\n","```bash\n","pip install pandas pyarrow pillow huggingface_hub\n","```\n","\n","### Load the metadata index\n","\n","```python\n","import pandas as pd\n","from huggingface_hub import hf_hub_download\n","\n","REPO_ID = \"codeShare/adcom_captioned_ai_images\"\n","\n","parquet_path = hf_hub_download(\n"," repo_id=REPO_ID,\n"," filename=\"captions.parquet\",\n"," repo_type=\"dataset\"\n",")\n","\n","metadata = pd.read_parquet(parquet_path)\n","\n","print(metadata.head())\n","print(f\"Total indexed images: {len(metadata):,}\")\n","```\n","\n","For a private or gated repository, authenticate with a Hugging Face\n","access token and pass it as the `token` argument to `hf_hub_download`.\n","\n","### Retrieve one image by ID\n","\n","This example downloads only the shard containing the requested image and\n","reads only the indexed record.\n","\n","```python\n","import json\n","import base64\n","import re\n","import io\n","\n","import pandas as pd\n","from PIL import Image\n","from huggingface_hub import hf_hub_download\n","\n","REPO_ID = \"codeShare/adcom_captioned_ai_images\"\n","\n","# Load the metadata index.\n","parquet_path = hf_hub_download(\n"," repo_id=REPO_ID,\n"," filename=\"captions.parquet\",\n"," repo_type=\"dataset\"\n",")\n","\n","metadata = pd.read_parquet(parquet_path)\n","\n","# Choose an image ID from the index.\n","target_idx = str(metadata.iloc[0][\"idx\"])\n","\n","# Find its index entry.\n","row = metadata.loc[\n"," metadata[\"idx\"].astype(str) == target_idx\n","].iloc[0]\n","\n","# Download only the required shard.\n","shard_path = hf_hub_download(\n"," repo_id=REPO_ID,\n"," filename=str(row[\"json_file\"]),\n"," repo_type=\"dataset\"\n",")\n","\n","# Read the exact JSONL record using its byte location.\n","with open(shard_path, \"rb\") as f:\n"," f.seek(int(row[\"byte_offset\"]))\n"," raw_record = f.read(int(row[\"byte_length\"]))\n","\n","record = json.loads(raw_record.decode(\"utf-8\"))\n","\n","# Verify the retrieved record.\n","assert str(record[\"idx\"]) == target_idx\n","\n","# Decode the image.\n","image_value = record[\"image\"].strip()\n","\n","if image_value.startswith(\"data:\") and \",\" in image_value:\n"," image_value = image_value.split(\",\", 1)[1]\n","\n","image_value = re.sub(r\"\\s+\", \"\", image_value)\n","\n","image_bytes = base64.b64decode(image_value)\n","\n","image = Image.open(io.BytesIO(image_bytes)).convert(\"RGB\")\n","\n","display(image)\n","\n","print(\"Image ID:\", target_idx)\n","print(\"Prompt:\", row[\"prompt\"])\n","print(\"Author:\", row[\"author\"])\n","print(\"Tags:\", row[\"tags\"])\n","```\n","\n","### Retrieve a random sample of images\n","\n","The following example samples metadata first and downloads only the shards\n","needed for the selected images.\n","\n","```python\n","import json\n","import base64\n","import re\n","import io\n","\n","import pandas as pd\n","from PIL import Image\n","from huggingface_hub import hf_hub_download\n","\n","REPO_ID = \"codeShare/adcom_captioned_ai_images\"\n","\n","NUM_SAMPLES = 10\n","RANDOM_SEED = 42\n","\n","# Load the index.\n","parquet_path = hf_hub_download(\n"," repo_id=REPO_ID,\n"," filename=\"captions.parquet\",\n"," repo_type=\"dataset\"\n",")\n","\n","metadata = pd.read_parquet(parquet_path)\n","\n","# Optional author filter.\n","# Set to None to include all authors.\n","AUTHOR_FILTER = \"Adcom\"\n","\n","if AUTHOR_FILTER is not None:\n"," metadata = metadata[\n"," metadata[\"author\"].fillna(\"\").astype(str).str.casefold()\n"," == AUTHOR_FILTER.casefold()\n"," ]\n","\n","if metadata.empty:\n"," raise ValueError(\"No matching records found.\")\n","\n","# Reproducible random sample.\n","sampled = metadata.sample(\n"," n=min(NUM_SAMPLES, len(metadata)),\n"," random_state=RANDOM_SEED\n",")\n","\n","# Download only the shards required by the sample.\n","shard_cache = {}\n","\n","for _, row in sampled.iterrows():\n","\n"," shard_name = str(row[\"json_file\"])\n","\n"," if shard_name not in shard_cache:\n"," shard_cache[shard_name] = hf_hub_download(\n"," repo_id=REPO_ID,\n"," filename=shard_name,\n"," repo_type=\"dataset\"\n"," )\n","\n"," # Retrieve the indexed JSONL record.\n"," with open(shard_cache[shard_name], \"rb\") as f:\n"," f.seek(int(row[\"byte_offset\"]))\n"," raw_record = f.read(int(row[\"byte_length\"]))\n","\n"," record = json.loads(raw_record.decode(\"utf-8\"))\n","\n"," if str(record[\"idx\"]) != str(row[\"idx\"]):\n"," raise ValueError(\"Image ID does not match the metadata index.\")\n","\n"," # Decode image data.\n"," image_value = record[\"image\"].strip()\n","\n"," if image_value.startswith(\"data:\") and \",\" in image_value:\n"," image_value = image_value.split(\",\", 1)[1]\n","\n"," image_value = re.sub(r\"\\s+\", \"\", image_value)\n","\n"," image_bytes = base64.b64decode(image_value)\n"," image = Image.open(io.BytesIO(image_bytes)).convert(\"RGB\")\n","\n"," print(\"Image ID:\", row[\"idx\"])\n"," print(\"Prompt:\", row[\"prompt\"])\n"," print(\"Author:\", row[\"author\"])\n"," display(image)\n"," image.close()\n","```\n","\n","---\n","\n","## Performance notes\n","\n","- **Metadata-first sampling:** Select records from the Parquet index before downloading image data.\n","- **Selective shard downloads:** Only download shards referenced by the selected records.\n","- **Direct record access:** Use byte offsets and lengths instead of scanning JSONL files.\n","- **Reproducible sampling:** Set `random_state` to a fixed integer to reproduce a sample.\n","- **Private repository support:** Pass a Hugging Face token to the download functions when authentication is required.\n","\n","## Important notes\n","\n","- The Parquet index and JSONL shards must remain consistent. If shard contents are rewritten or reordered, the corresponding byte offsets and lengths must be regenerated.\n","- Image data is stored as base64 in JSONL records; it is decoded into image bytes when retrieved.\n","- The dataset card does not declare a license. Please consult the dataset owner for licensing and usage permissions before redistributing or using the data commercially.\n","\n","=================================================================\n","3. DECLARED FEATURE SCHEMA\n","=================================================================\n","No explicit features section found in README YAML.\n","\n","=================================================================\n","4. PARQUET SCHEMA INSPECTION\n","=================================================================\n","\n","FILE: captions.parquet\n","Rows: 8536\n","Columns: ['idx', 'prompt', 'tags', 'author', 'json_file', 'byte_offset', 'byte_length']\n","Schema:\n","idx: int64\n","prompt: large_string\n","tags: large_string\n","author: large_string\n","json_file: large_string\n","byte_offset: int64\n","byte_length: int64\n","-- schema metadata --\n","pandas: '{\"index_columns\": [], \"column_indexes\": [], \"columns\": [{\"name\":' + 880\n","\n","=================================================================\n","5. JSON / JSONL STRUCTURE INSPECTION\n","=================================================================\n","\n","FILE: images/part_00000.jsonl\n"]}]}]}
|