Bespoke Labs
  • Welcome
  • BESPOKE CURATOR
    • Getting Started
      • Quick Tour
      • Key Concepts
      • Visualize your dataset with the Bespoke Curator Viewer
      • Automatic recovery and caching
      • Structured Output
    • Save $$$ on LLM inference
      • Using OpenAI for batch inference
      • Using Anthropic for batch inference
      • Using Gemini for batch inference
      • Using Mistral for batch inference
      • Using kluster.ai for batch inference
    • How-to Guides
      • Using vLLM with Curator
      • Using Ollama with Curator
      • Using LiteLLM with curator
      • Handling Multimodal Data in Curator
      • Executing LLM-generated code
      • Using HuggingFace inference providers with Curator
    • Data Curation Recipes
      • Generating a diverse QA dataset
      • Using SimpleStrat block for generating diverse data
      • Curate Reasoning data with Claude-3.7 Sonnet
      • Synthetic Data for function calling
    • Finetuning Examples
      • Aspect based sentiment analysis
      • Finetuning a model to identify features of a product
    • API Reference
  • Models
    • Bespoke MiniCheck
      • Self-Hosting
      • Integrations
      • API Service
    • Bespoke MiniChart
    • OpenThinker
Powered by GitBook
On this page
  • What is Inference Providers
  • Setup
  • Steps
  • Tips
  1. BESPOKE CURATOR
  2. How-to Guides

Using HuggingFace inference providers with Curator

PreviousExecuting LLM-generated codeNextData Curation Recipes

Last updated 1 month ago

This guide demonstrates how to use Hugging Face Inference Providers with curator to generate synthetic data using various LLM providers available as Inference Providers on Hugging Face. We’ll walk through an example of generating synthetic recipes, but this approach can be adapted for any synthetic data generation task.

What is Inference Providers

Hugging Face’s give developers streamlined, unified access to hundreds of machine learning models, powered by Hugging Face’s serverless inference partners. Using Inference Providers gives you access to a wide range of state of the art models, with newly released models regularly added by providers.

Since Inference Providers are available using OpenAI compatible APIs, you can use them as a drop in replacement for OpenAI in your project. This is the approach we’ll take in this guide.

Setup

  1. Ensure you have a Hugging Face account, you can sign up .

  2. Create a Hugging Face API key, you can create one . This will be used to authenticate your requests to the Inference Providers.

  3. Ensure you have at least one Inference Provider enabled in your Hugging Face account. You can configure this in the page.

First, install the necessary packages:

pip install bespokelabs-curator
pip install huggingface_hub openai

Steps

1. Create a curator.LLM Subclass

First, create a class that inherits from curator.LLM. You’ll need to implement two key methods:

  • prompt(): Generates the prompt for the LLM

  • parse(): Processes the LLM’s response into your desired format

"""Generate synthetic recipes for different cuisines using curator."""

from datasets import Dataset
from bespokelabs import curator


class RecipeGenerator(curator.LLM):
    """A recipe generator that generates recipes for different cuisines."""

    def prompt(self, input: dict) -> str:
        """Generate a prompt using the template and cuisine."""
        return f"Generate a random {input['cuisine']} recipe. Be creative but keep it realistic and make the recipe vegan"

    def parse(self, input: dict, response: str) -> dict:
        """Parse the model response along with the input to the model into the desired output format."""
        return {
            "recipe": response,
            "cuisine": input["cuisine"],
        }

2. Set Up Your Seed Dataset

Create a dataset of inputs using the HuggingFace Dataset class:

# List of cuisines to generate recipes for
cuisines = [
    {"cuisine": cuisine}
    for cuisine in [
        "Chinese",
        "Italian",
        "Mexican",
        "French",
        "Japanese",
        "Indian",
        "Thai",
        "Korean",
        "Vietnamese",
        "Brazilian",
    ]
]
cuisines = Dataset.from_list(cuisines)

3. Configure the OpenAI Backend to use an Inference Provider

Since Inference Providers are available using OpenAI compatible APIs, we can use them as a drop in replacement for OpenAI in our project. We just need to configure a few things:

  • the base_url

  • the api_key

  • the model_name

recipe_generator = RecipeGenerator(
    model_name="meta-llama/Llama-4-Scout-17B-16E-Instruct",
    backend="openai",
    backend_params={
        "base_url": "https://router.huggingface.co/together/v1",
        "api_key": HF_TOKEN, # your Hugging Face API key
    },
)

results = recipe_generator(cuisines)
print(results.to_pandas())

4. Push to Hub

You can view the dataset in Curator Viewer or HuggingFace hub

Curator Viewer

# We can visualize data using Curator viewer easily.

import os
os.environ['CURATOR_VIEWER']='1'

from bespokelabs.curator.utils import push_to_viewer
url = push_to_viewer(results)

OR

since curator is using 🤗 datasets, you can push the results to the Hub just like any other dataset!

results.push_to_hub(
    "hf_username/llama-recipes",
    private=False,
    token=HF_TOKEN,
)

Tips

Since Inference Providers are available via a standard protocol, it’s easy to swap out models on providers in your pipeline depending on the needs of your project.

You can find this infromation on the model page of the Inference Provider. For example, here’s the information for the Together Inference Provider:

You can see what the dataset looks like on the Hub !

You can find a list of models that are available via a specific Inference Provider by using a Inference Provider filter on the Hub. For example, that are available via the Together Inference Provider.

Inference Providers
here
here
Inference Providers
https://huggingface.co/meta-llama/Llama-4-Scout-17B-16E-Instruct?inference_provider=together&language=python&inference_api=true
here
here’s the list of models