Unlocking the Power of Data with Hugging Face Hub
The Hugging Face Hub has emerged as a pivotal resource for machine learning enthusiasts, researchers, and developers alike. With a commitment to open access, the Hub provides a vast array of datasets that can be seamlessly explored and understood. Whether you’re interested in training large language models (LLMs) like Falcon, Dolly, MPT, or StarCoder, the Hugging Face Hub is your gateway to high-quality data.
Discovering Datasets for Large Language Models
At the core of the Hugging Face Hub is its extensive collection of datasets tailored for training advanced language models. These datasets are not just random collections of text; they are meticulously curated to ensure quality and relevance. Popular models use these datasets as foundational building blocks, enabling them to understand and generate human-like text across various contexts.
Tools for Fairness and Bias Assessment
Understanding the nuances of the datasets you are working with is crucial, especially in today’s landscape where fairness and bias in AI are hot topics. The Hub offers specialized tools such as Disaggregators, designed to help users analyze and address these issues within datasets. This is part of a broader initiative to promote ethical AI practices and ensure that the models trained on these datasets are as fair and unbiased as possible.
Visualizing Data with the Dataset Viewer
One of the standout features of the Hugging Face Hub is the Dataset Viewer. This tool allows users to preview examples inside a dataset effortlessly. The Dataset Viewer automatically converts all public datasets into Parquet files, which are optimized for storage and retrieval. This means that you can quickly access and analyze data without getting bogged down by inefficient formats.
Preview of the OpenAssistant dataset with the Dataset Viewer.
SQL Queries Made Easy with DuckDB
In an exciting development, the Hugging Face Hub has integrated DuckDB, a fast database management system, allowing users to run SQL queries on any dataset stored on the Hub. According to the 2022 StackOverflow Developer Survey, SQL is the third most popular programming language, making this feature incredibly relevant for data scientists and analysts.
Accessing Parquet Files
The dataset viewer’s automatic conversion of datasets to Parquet files is a game changer. By simply clicking the "Auto-converted to Parquet" button at the top of any dataset page, you can access these files easily. For developers, utilizing a simple HTTP call provides direct access to the list of Parquet file URLs, streamlining the data retrieval process.
Here’s a quick example of how to access Parquet files using Python:
import requests
r = requests.get("https://datasets-server.huggingface.co/parquet?dataset=blog_authorship_corpus")
j = r.json()
urls = [f['url'] for f in j['parquet_files'] if f['split'] == 'train']
print(urls)
This code snippet fetches the URLs of the Parquet files for the specified dataset, making it easy to pull in the data you need for analysis.
Running SQL Queries on Parquet Files
Once you have the Parquet file URL, you can easily connect to DuckDB and analyze your data using SQL. Start by installing and loading the httpfs extension to enable reading and writing of remote files. Here’s how to get started:
import duckdb
url = "https://huggingface.co/datasets/blog_authorship_corpus/resolve/refs%2Fconvert%2Fparquet/blog_authorship_corpus/blog_authorship_corpus-train-00000-of-00002.parquet"
con = duckdb.connect()
con.execute("INSTALL httpfs;")
con.execute("LOAD httpfs;")
With your DuckDB connection established, you can dive into data analysis using SQL queries. For instance, you could run a query to find the average length of blog posts categorized by horoscope:
con.sql(f"""SELECT horoscope,
count(*),
AVG(LENGTH(text)) AS avg_blog_length
FROM '{url}'
GROUP BY horoscope
ORDER BY avg_blog_length
DESC LIMIT(5)""")
The Efficiency of Parquet Files
Parquet files are columnar, which significantly enhances their efficiency for storage, loading, and analytical queries. This efficiency is vital in the era of large datasets, particularly with the growing popularity of LLMs. The Hugging Face Hub’s dataset viewer automatically converts and publishes public datasets as Parquet files, which can be accessed through the /parquet endpoint.
The Future of Data Analysis on Hugging Face Hub
Understanding the contents of a dataset is crucial for developing high-quality models. By empowering users to write and execute SQL queries on Hub datasets, the Hugging Face Hub enhances transparency and accessibility. This initiative aims to foster a deeper understanding of datasets, ultimately leading to improved model performance and insights.
As the Hugging Face Hub continues to evolve, the community is encouraged to explore these features and uncover valuable insights from the wealth of data available. The integration of DuckDB and the automatic conversion to Parquet files are just the beginning of what promises to be a revolutionary approach to data analytics in the field of machine learning.
Inspired by: Source

