Hugging Face Dataset Import
Import a public Hugging Face dataset into Future AGI with the SDK, run a completeness evaluation across every row, and download the scored results.
Import a public Hugging Face dataset into Future AGI with a single SDK call, run a completeness evaluation across every row, and download the scored results as CSV or a pandas DataFrame.
| Time | Difficulty | Package |
|---|---|---|
| 10 min | Beginner | futureagi, ai-evaluation |
- Future AGI account → app.futureagi.com
- API keys:
FI_API_KEYandFI_SECRET_KEY(see Get your API keys) - Python 3.11+
Install
pip install futureagi ai-evaluation
export FI_API_KEY="your-api-key"
export FI_SECRET_KEY="your-secret-key"
Tutorial
Import a Hugging Face dataset
Use HuggingfaceDatasetConfig to specify which dataset, subset, split, and how many rows to pull, then pass it as the source argument to dataset.create().
This example imports 50 rows from the SmolLM-Corpus cosmopedia-v2 subset: synthetic textbook-style content with prompts, generated text, audience labels, and format tags.
import os
from fi.datasets import Dataset, DatasetConfig, HuggingfaceDatasetConfig
from fi.utils.types import ModelTypes
hf_config = HuggingfaceDatasetConfig(
name="HuggingFaceTB/smollm-corpus",
subset="cosmopedia-v2",
split="train",
num_rows=50,
)
dataset = Dataset(
dataset_config=DatasetConfig(
name="smollm-cosmopedia-import",
model_type=ModelTypes.GENERATIVE_LLM,
),
fi_api_key=os.environ["FI_API_KEY"],
fi_secret_key=os.environ["FI_SECRET_KEY"],
)
dataset = dataset.create(source=hf_config)
print(f"Dataset created: {dataset.dataset_config.name}")
print(f"Dataset ID: {dataset.dataset_config.id}")You should see:
Dataset created: smollm-cosmopedia-import
Dataset ID: a1b2c3d4-...Tip
HuggingfaceDatasetConfig takes four fields: name (required, the Hugging Face dataset path), subset (defaults to "default"), split (defaults to "train"), and num_rows (optional, omit to import the entire split).
View the imported dataset in the dashboard
Open Dataset in the left sidebar. Your new dataset appears in the list. Click it to browse the imported rows and columns.
The cosmopedia-v2 subset includes columns like prompt, text, audience, format, and token_length, ready for evaluation.
Run an evaluation on the imported data
The prompt column holds the generation instruction and text holds the generated output, a natural fit for a completeness evaluation that checks whether the output fully addresses the input.
required_keys_to_column_names must map to columns that actually exist in the dataset. Mapping output to a column this dataset doesn’t have raises a DatasetError:
dataset.add_evaluation(
name="completeness-check",
eval_template="completeness",
required_keys_to_column_names={
"input": "prompt",
"output": "generated_text",
},
model="turing_small",
run=True,
reason_column=True,
)You should see:
DatasetError: Column 'generated_text' (mapped from key 'output') not found in dataset 'smollm-cosmopedia-import'.The cosmopedia-v2 subset names its output column text, not generated_text. Fix the mapping and rerun:
dataset = dataset.add_evaluation(
name="completeness-check",
eval_template="completeness",
required_keys_to_column_names={
"input": "prompt",
"output": "text",
},
model="turing_small",
run=True,
reason_column=True,
)
print("Evaluation 'completeness-check' started")You should see:
Evaluation 'completeness-check' startedNote
Column names depend on the Hugging Face dataset schema. Open the dataset in the dashboard to confirm the exact column names before mapping required_keys_to_column_names.
You should see the completeness-check column fill in on the dashboard, scoring each row on whether its text fully addresses its prompt.
Download scored results
add_evaluation(run=True) starts scoring and returns immediately, it does not wait for the run to finish. Confirm the evaluation has completed before downloading, either by checking that the completeness-check column is filled in on the dashboard, or with get_eval_stats():
stats = dataset.get_eval_stats()
print(stats)Once the stats show the run complete, pull the evaluated dataset back as a CSV or a pandas DataFrame.
As CSV:
dataset.download(file_path="smollm_scored.csv")
print("Downloaded scored results to smollm_scored.csv")As a pandas DataFrame:
df = dataset.download(load_to_pandas=True)
# Print all column names to see the exact eval and reason column names
print("Columns:", list(df.columns))
print(df[["completeness-check", "completeness-check_reason"]].head())You should see the eval column (named after the evaluation, completeness-check) and its matching _reason column, for example:
Columns: ['prompt', 'text', 'token_length', 'audience', 'format', 'seed_data', 'completeness-check', 'completeness-check_reason']
completeness-check completeness-check_reason
0 Passed The generated text fully covers the prompt's...
1 Failed The output omits the audience-specific frami... Clean up
dataset.delete()
print("Dataset deleted") Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
ValueError / dataset not found on dataset.create() | name doesn’t match the dataset’s exact Hugging Face path, or the dataset is private | Copy the path from the dataset’s URL (org/dataset-name) and confirm it’s public on huggingface.co |
dataset.create() fails on the subset | subset names a config that doesn’t exist for this dataset | Check the subset dropdown on the dataset’s Hugging Face page; omit subset to fall back to "default" |
| Import hangs or takes a long time | num_rows was omitted on a large dataset, so the SDK pulls the entire split | Pass an explicit num_rows while testing, then widen it once the flow works |
KeyError or empty scores from add_evaluation() | required_keys_to_column_names points at a column name that doesn’t exist in this dataset | Open the dataset in the dashboard and copy the exact column names before mapping |
401 Unauthorized on any SDK call | FI_API_KEY or FI_SECRET_KEY isn’t exported in the shell running the script | Re-export both keys in the same terminal session and confirm with echo $FI_API_KEY |
download() is missing the eval columns | Called before the evaluation finished running | Check the evaluation’s status in the dashboard, then download once it shows complete |
dataset.delete() removes data you still needed | Called before downloading the scored results | Download first, confirm the file or DataFrame has the eval columns, then delete |
Run a multi-metric evaluation across a dataset in Dataset SDK: Upload, Evaluate, and Download Results.
Questions & Discussion