> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# Import data from Hugging Face datasets

[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/data/data-import-huggingface.ipynb)  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/data/data-import-huggingface.ipynb)  [![Download Notebook](https://img.shields.io/badge/%E2%AC%87-Download%20Notebook-blue)](https://raw.githubusercontent.com/pixeltable/pixeltable/refs/tags/release/docs/release/howto/cookbooks/data/data-import-huggingface.ipynb)

> [!TIP]
>
> This documentation page is also available as an interactive notebook. You can launch the notebook in
> Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
> above links.

Load datasets from Hugging Face Hub into Pixeltable tables for
processing with AI models.

## Problem

You want to use a dataset from Hugging Face Hub—for fine-tuning,
evaluation, or analysis. You need to load it into a format where you can
add computed columns, embeddings, or AI transformations.

## Solution

**What’s in this recipe:**

* Import Hugging Face datasets directly into tables
* Handle datasets with multiple splits (train/test/validation)
* Work with image datasets

You use `pxt.create_table()` with a Hugging Face dataset as the `source`
parameter. Pixeltable automatically maps HF types to Pixeltable column
types.

### Setup

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
%pip install -qU pixeltable datasets
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import pixeltable as pxt
from datasets import load_dataset

# Create a fresh directory
pxt.drop_dir('hf_demo', force=True)
pxt.create_dir('hf_demo')
```

<pre>
  Created directory 'hf\_demo'.
  \<pixeltable.catalog.dir.Dir at 0x31e39d8d0>
</pre>

### Import a single split

Load a specific split from a dataset:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Load a small subset for demo (first 100 rows of rotten_tomatoes)
hf_dataset = load_dataset(
    'cornell-movie-review-data/rotten_tomatoes', split='train[:100]'
)
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Import into Pixeltable
reviews = pxt.create_table('hf_demo/reviews', source=hf_dataset)
```

<pre>
  Created table 'reviews'.
  Inserting rows into \`reviews\`: 100 rows \[00:00, 14781.69 rows/s]
  Inserted 100 rows with 0 errors.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View imported data
reviews.head(5)
```

### Import multiple splits

Load a DatasetDict with multiple splits and track which split each row
came from:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Load dataset with multiple splits (small subset for demo)
hf_dataset_dict = load_dataset(
    'cornell-movie-review-data/rotten_tomatoes',
    split={'train': 'train[:50]', 'test': 'test[:50]'},
)
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Import each split separately for clarity
train_data = pxt.create_table(
    'hf_demo/reviews_train', source=hf_dataset_dict['train']
)
test_data = pxt.create_table(
    'hf_demo/reviews_test', source=hf_dataset_dict['test']
)
```

<pre>
  Created table 'reviews\_train'.
  Inserting rows into \`reviews\_train\`: 50 rows \[00:00, 10150.29 rows/s]
  Inserted 50 rows with 0 errors.
  Created table 'reviews\_test'.
  Inserting rows into \`reviews\_test\`: 50 rows \[00:00, 9883.37 rows/s]
  Inserted 50 rows with 0 errors.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View training data
train_data.head(5)
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View test data
test_data.head(3)
```

### Add AI-powered computed columns

Enrich the dataset with AI models:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Add a computed column for text length
reviews.add_computed_column(text_length=reviews.text.len())
```

<pre>
  Added 100 column values with 0 errors.
  100 rows updated, 200 values computed.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View with computed column
reviews.select(reviews.text, reviews.label, reviews.text_length).head(5)
```

### Type mapping

Pixeltable automatically maps Hugging Face types to Pixeltable types:

Use `schema_overrides` to customize type mapping when needed.

## Explanation

**Why import Hugging Face datasets into Pixeltable:**

1. **Add computed columns** - Enrich data with embeddings, AI analysis,
   or transformations
2. **Incremental processing** - Add new rows without reprocessing
   existing data
3. **Persistent storage** - Keep processed results across sessions
4. **Query capabilities** - Filter, aggregate, and join with other
   tables

**Working with large datasets:**

For very large datasets, consider loading in batches or using streaming
mode in the `datasets` library before importing.

## See also

* [Import CSV
  files](https://docs.pixeltable.com/howto/cookbooks/data/data-import-csv.md) -
  For CSV and Excel imports
* [Semantic text
  search](https://docs.pixeltable.com/howto/cookbooks/search/search-semantic-text.md) -
  Add embeddings to text data
* [Hugging Face integration
  notebook](https://docs.pixeltable.com/howto/providers/working-with-hugging-face.md) -
  Full integration guide


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.