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.
Pixeltable provides seamless integration with Hugging Face datasets and
models. This tutorial covers:
Importing datasets directly into Pixeltable tables
Working with dataset splits (train/test/validation)
Use pxt.create_table() with the source= parameter to import a
Hugging Face dataset directly. Pixeltable automatically maps Hugging
Face feature types to Pixeltable column types.
import datasetsimport numpy as npimport pixeltable as pxtpxt.drop_dir('hf_demo', force=True)pxt.create_dir('hf_demo')# Load a dataset with imagespadoru = datasets.load_dataset( 'not-lain/padoru', split='train').select_columns(['Image', 'ImageSize', 'Name', 'ImageSource'])# Import into Pixeltableimages = pxt.create_table('hf_demo/images', source=padoru)
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘hf_demo’.
Created table ‘images’.
Inserting rows into `images`: 100 rows [00:00, 310.24 rows/s]
Inserting rows into `images`: 100 rows [00:00, 353.22 rows/s]
Inserting rows into `images`: 100 rows [00:00, 368.40 rows/s]
Inserting rows into `images`: 82 rows [00:00, 567.89 rows/s]
Inserted 382 rows with 0 errors.
images.head(3)
Working with Dataset Splits
When importing a DatasetDict (which contains multiple splits like
train/test), use extra_args={'column_name_for_split': 'split'} to
preserve split information in a column.
# Load a dataset with multiple splitsimdb = datasets.load_dataset('stanfordnlp/imdb')# Import all splits, storing split info in 'split' columnreviews = pxt.create_table( 'hf_demo/reviews', source=imdb, extra_args={'column_name_for_split': 'split'},)
# Query by splitreviews.where(reviews.split == 'train').limit(3).select( reviews.text, reviews.label, reviews.split).collect()
# Count rows per splitreviews.group_by(reviews.split).select( reviews.split, count=pxt.functions.count(reviews.text)).collect()
Using schema_overrides for EmbeddingsWhen importing datasets with pre-computed embeddings (common in RAG),
use schema_overrides to specify the exact array shape:
Audio datasets work seamlessly - Pixeltable stores audio files locally:
# Import a small audio datasetaudio_ds = datasets.load_dataset( 'hf-internal-testing/librispeech_asr_dummy', 'clean', split='validation',)audio_table = pxt.create_table('hf_demo/audio_samples', source=audio_ds)audio_table.select(audio_table.audio, audio_table.text).limit(2).collect()
Created table ‘audio_samples’.
Inserting rows into `audio_samples`: 73 rows [00:00, 3960.27 rows/s]
Inserted 73 rows with 0 errors.
Inserting More Data
Use table.insert() to add more data from a HuggingFace dataset to an
existing table:
# Insert more data from the same or similar datasetmore_audio = datasets.load_dataset( 'hf-internal-testing/librispeech_asr_dummy', 'clean', split='validation',).select(range(5))audio_table.insert(more_audio)audio_table.count()
Inserting rows into `audio_samples`: 5 rows [00:00, 3186.68 rows/s]
Inserted 5 rows with 0 errors.
78
Type Mappings Reference
Using Hugging Face Models
Pixeltable integrates with Hugging Face models for embeddings and
inference, running locally without API keys.
Image Embeddings with CLIP
from pixeltable.functions.huggingface import clip# Add CLIP embedding index for cross-modal image searchimages.add_embedding_index( 'Image', embedding=clip.using(model_id='openai/clip-vit-base-patch32'))# Search images using textsim = images.Image.similarity(string='anime character with red clothes')images.order_by(sim, asc=False).limit(3).select( images.Image, images.Name, sim=sim).collect()
Text Embeddings with Sentence Transformers
from pixeltable.functions.huggingface import sentence_transformer# Create table with text embedding indexsample_reviews = pxt.create_table( 'hf_demo/sample_reviews', source=datasets.load_dataset('stanfordnlp/imdb', split='test').select( range(100) ),)sample_reviews.add_embedding_index( 'text', string_embed=sentence_transformer.using(model_id='all-MiniLM-L6-v2'),)# Semantic searchquery = 'great acting and cinematography'sim = sample_reviews.text.similarity(string=query)sample_reviews.order_by(sim, asc=False).limit(3).select( sample_reviews.text, sim=sim).collect()
Created table ‘sample_reviews’.
Inserting rows into `sample_reviews`: 100 rows [00:00, 21625.70 rows/s]
Inserted 100 rows with 0 errors.
More Hugging Face Models
Pixeltable supports many more HuggingFace models including: