{"title":"Hugging Face","description":"Query public and private datasets hosted on the Hugging Face Hub as an external catalog, pinned to any branch, tag or commit.","order":150,"askSuggestions":["How do I query a private or gated dataset?","How do I query a dataset at a specific tag or commit?","How do I avoid downloading the dataset on every query?"],"navigation":true,"body":{"code":"var Component=(()=>{var u=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var b=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),v=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},d=(t,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of m(e))!y.call(t,a)&&a!==r&&c(t,a,{get:()=>e[a],enumerable:!(i=p(e,a))||i.enumerable});return t};var x=(t,e,r)=>(r=t!=null?u(f(t)):{},d(e||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),H=t=>d(c({},\"__esModule\",{value:!0}),t);var s=b((E,l)=>{l.exports=_jsx_runtime});var F={};v(F,{default:()=>g,frontmatter:()=>q});var n=x(s()),q={title:\"Hugging Face\",description:\"Query public and private datasets hosted on the Hugging Face Hub as an external catalog, pinned to any branch, tag or commit.\",order:150,askSuggestions:[\"How do I query a private or gated dataset?\",\"How do I query a dataset at a specific tag or commit?\",\"How do I avoid downloading the dataset on every query?\"]};function h(t){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",li:\"li\",ol:\"ol\",p:\"p\",pre:\"pre\",strong:\"strong\",table:\"table\",tbody:\"tbody\",td:\"td\",th:\"th\",thead:\"thead\",tr:\"tr\",ul:\"ul\",...t.components},{DocsBeta:r,DocsPreviewDocument:i,DocsPreviewSection:a}=e;return r||o(\"DocsBeta\",!0),i||o(\"DocsPreviewDocument\",!0),a||o(\"DocsPreviewSection\",!0),(0,n.jsxs)(i,{anchors:\"hugging-face requirements connect-a-hugging-face-catalog query-example query-other-revisions performance\",children:[(0,n.jsxs)(a,{sectionId:\"hugging-face\",sectionTitle:\"Hugging Face\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,n.jsx)(e.h1,{id:\"hugging-face\",children:\"Hugging Face\"}),`\n`,(0,n.jsx)(r,{children:(0,n.jsx)(e.p,{children:`The Hugging Face external catalog is available in beta. Its syntax and\nbehavior may change as the implementation evolves.`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"Hugging Face external catalogs expose datasets hosted on the \",(0,n.jsx)(e.a,{href:\"https://huggingface.co/datasets\",children:\"Hugging Face Hub\"}),\" as tables. Files are read in place from the Hub: nothing is copied into Altertable.\"]}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"requirements\",sectionTitle:\"Requirements\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,n.jsx)(e.h2,{id:\"requirements\",children:\"Requirements\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"One or more dataset repositories on the Hugging Face Hub, stored as Parquet, CSV or JSON files\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"For private or gated datasets, a Hugging Face \",(0,n.jsx)(e.a,{href:\"https://huggingface.co/settings/tokens\",children:\"access token\"}),\" with read access to those datasets\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"Hugging Face catalogs are read-only in Altertable.\"}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"connect-a-hugging-face-catalog\",sectionTitle:\"Connect a Hugging Face Catalog\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,n.jsx)(e.h2,{id:\"connect-a-hugging-face-catalog\",children:\"Connect a Hugging Face Catalog\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"Open \",(0,n.jsx)(e.strong,{children:\"Catalogs\"}),\" in the target environment.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Click \",(0,n.jsx)(e.strong,{children:\"New catalog\"}),\" and choose \",(0,n.jsx)(e.strong,{children:\"Hugging Face\"}),\".\"]}),`\n`,(0,n.jsx)(e.li,{children:\"Paste an access token, or leave it empty for public datasets.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Select the file format of the datasets.\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"Map each table name to a dataset location, written as \",(0,n.jsx)(e.code,{children:\"owner/dataset[@revision][/path]\"}),\".\"]}),`\n`,(0,n.jsx)(e.li,{children:\"Test and create the catalog.\"}),`\n`]}),`\n`,(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:\"Location\"}),(0,n.jsx)(e.th,{children:\"Reads\"})]})}),(0,n.jsxs)(e.tbody,{children:[(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"acme/train-records\"})}),(0,n.jsx)(e.td,{children:\"Every file of the default branch\"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"acme/train-records/data\"})}),(0,n.jsxs)(e.td,{children:[\"Every file under \",(0,n.jsx)(e.code,{children:\"data/\"}),\" on the default branch\"]})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"acme/train-records@v3/data\"})}),(0,n.jsxs)(e.td,{children:[\"Every file under \",(0,n.jsx)(e.code,{children:\"data/\"}),\" at the \",(0,n.jsx)(e.code,{children:\"v3\"}),\" tag\"]})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"acme/train-records@~parquet\"})}),(0,n.jsx)(e.td,{children:\"The Parquet conversion maintained by Hugging Face\"})]})]})]}),`\n`,(0,n.jsx)(e.p,{children:\"The token is only sent to the dataset repositories mapped in the catalog.\"}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"query-example\",sectionTitle:\"Query Example\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,n.jsx)(e.h2,{id:\"query-example\",children:\"Query Example\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT language, stage, label, count(*) AS n\nFROM hf.main.train_records\nGROUP BY ALL\nORDER BY ALL;\n`})}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"query-other-revisions\",sectionTitle:\"Query Other Revisions\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,n.jsx)(e.h2,{id:\"query-other-revisions\",children:\"Query Other Revisions\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Every mapped table also gets a \",(0,n.jsx)(e.code,{children:\"<table>_at(rev)\"}),\" table function that reads the same dataset at any branch, tag or commit:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT block, label, count(*) AS n\nFROM hf.main.train_mix_at('v2')\nGROUP BY ALL;\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"Pin to a commit hash for fully reproducible results, since branches and tags can move.\"}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"performance\",sectionTitle:\"Performance\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,n.jsx)(e.h2,{id:\"performance\",children:\"Performance\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Each query reads the dataset files from the Hub, so large scans are bound by download speed and by \",(0,n.jsx)(e.a,{href:\"https://huggingface.co/docs/hub/rate-limits\",children:\"Hugging Face rate limits\"}),\", and queries you run again download the same files again.\"]}),`\n`,(0,n.jsx)(e.p,{children:\"For a dataset you query repeatedly, copy it into an Altertable catalog once and keep the copy in sync instead:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Open the Altertable catalog that should hold the copy \\u2014 not this Hugging Face catalog, which is read-only.\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"On its \",(0,n.jsx)(e.strong,{children:\"Ingest\"}),\" tab, click \",(0,n.jsx)(e.strong,{children:\"New synchronizer\"}),\" in \",(0,n.jsx)(e.strong,{children:\"Synchronizers\"}),\".\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Choose \",(0,n.jsx)(e.strong,{children:\"External catalog\"}),\" as the source type, select this Hugging Face catalog, and pick the schema and tables to copy.\"]}),`\n`,(0,n.jsx)(e.li,{children:\"Choose the destination schema and a schedule.\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"Each run replaces the copied tables with the latest data from the Hub, so queries read the local copy instead of downloading the dataset again.\"})]})]})}function g(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(h,{...t})}):h(t)}function o(t,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return H(F);})();\n;return Component;"},"_id":"docs/lakehouse/external-catalogs/hugging-face.mdx","_raw":{"sourceFilePath":"docs/lakehouse/external-catalogs/hugging-face.mdx","sourceFileName":"hugging-face.mdx","sourceFileDir":"docs/lakehouse/external-catalogs","contentType":"mdx","flattenedPath":"docs/lakehouse/external-catalogs/hugging-face"},"type":"Docs","path":"/lakehouse/external-catalogs/hugging-face","level":3,"parent":"lakehouse/external-catalogs"}