Seeding with an External Dataset

View as Markdown

🎨 Data Designer Tutorial: Seeding Synthetic Data Generation with an External Dataset

📚 What you'll learn

In this notebook, we will demonstrate how to seed synthetic data generation in Data Designer with an external dataset.

If this is your first time using Data Designer, we recommend starting with the first notebook in this tutorial series.

📦 Import Data Designer

  • data_designer.config provides access to the configuration API.

  • DataDesigner is the main interface for data generation.

Python
1import data_designer.config as dd
2from data_designer.interface import DataDesigner
3

⚙️ Initialize the Data Designer interface

  • DataDesigner is the main object responsible for managing the data generation process.

  • When initialized without arguments, the default model providers are used.

Python
1data_designer = DataDesigner()
2

🎛️ Define model configurations

  • Each ModelConfig defines a model that can be used during the generation process.

  • The "model alias" is used to reference the model in the Data Designer config (as we will see below).

  • The "model provider" is the external service that hosts the model (see the model config docs for more details).

  • By default, we use build.nvidia.com as the model provider.

Python
1# This name is set in the model provider configuration.
2MODEL_PROVIDER = "nvidia"
3
4# The model ID is from build.nvidia.com.
5MODEL_ID = "nvidia/nemotron-3-nano-30b-a3b"
6
7# We choose this alias to be descriptive for our use case.
8MODEL_ALIAS = "nemotron-nano-v3"
9
10model_configs = [
11 dd.ModelConfig(
12 alias=MODEL_ALIAS,
13 model=MODEL_ID,
14 provider=MODEL_PROVIDER,
15 inference_parameters=dd.ChatCompletionInferenceParams(
16 temperature=1.0,
17 top_p=1.0,
18 max_tokens=2048,
19 extra_body={"chat_template_kwargs": {"enable_thinking": False}},
20 ),
21 )
22]
23

🏗️ Initialize the Data Designer Config Builder

  • The Data Designer config defines the dataset schema and generation process.

  • The config builder provides an intuitive interface for building this configuration.

  • The list of model configs is provided to the builder at initialization.

Python
1config_builder = dd.DataDesignerConfigBuilder(model_configs=model_configs)
2

🏥 Prepare a seed dataset

  • For this notebook, we'll create a synthetic dataset of patient notes.

  • We will seed the generation process with a symptom-to-diagnosis dataset.

  • The notebook downloads the source CSV before generation.


🌱 Why use a seed dataset?

  • Seed datasets let you steer the generation process by providing context that is specific to your use case.

  • Seed datasets are also an excellent way to inject real-world diversity into your synthetic data.

  • During generation, prompt templates can reference any of the seed dataset fields.

Python
1# Download sample dataset from Github
2import urllib.request
3
4url = "https://raw.githubusercontent.com/NVIDIA/GenerativeAIExamples/refs/heads/main/nemo/NeMo-Data-Designer/data/gretelai_symptom_to_diagnosis.csv"
5local_filename, _ = urllib.request.urlretrieve(url, "gretelai_symptom_to_diagnosis.csv")
6
7# Seed datasets are passed as reference objects to the config builder.
8seed_source = dd.LocalFileSeedSource(path=local_filename)
9
10config_builder.with_seed_dataset(seed_source)
11

🎨 Designing our synthetic patient notes dataset

  • The prompt template can reference fields from our seed dataset:
    • {{ diagnosis }} - the medical diagnosis from the seed data
    • {{ patient_summary }} - the symptom description from the seed data
Python
1config_builder.add_column(
2 dd.SamplerColumnConfig(
3 name="patient_sampler",
4 sampler_type=dd.SamplerType.PERSON_FROM_FAKER,
5 params=dd.PersonFromFakerSamplerParams(),
6 )
7)
8
9config_builder.add_column(
10 dd.SamplerColumnConfig(
11 name="doctor_sampler",
12 sampler_type=dd.SamplerType.PERSON_FROM_FAKER,
13 params=dd.PersonFromFakerSamplerParams(),
14 )
15)
16
17config_builder.add_column(
18 dd.SamplerColumnConfig(
19 name="patient_id",
20 sampler_type=dd.SamplerType.UUID,
21 params=dd.UUIDSamplerParams(
22 prefix="PT-",
23 short_form=True,
24 uppercase=True,
25 ),
26 )
27)
28
29config_builder.add_column(dd.ExpressionColumnConfig(name="first_name", expr="{{ patient_sampler.first_name }}"))
30
31config_builder.add_column(dd.ExpressionColumnConfig(name="last_name", expr="{{ patient_sampler.last_name }}"))
32
33config_builder.add_column(dd.ExpressionColumnConfig(name="dob", expr="{{ patient_sampler.birth_date }}"))
34
35config_builder.add_column(
36 dd.SamplerColumnConfig(
37 name="symptom_onset_date",
38 sampler_type=dd.SamplerType.DATETIME,
39 params=dd.DatetimeSamplerParams(start="2024-01-01", end="2024-12-31"),
40 )
41)
42
43config_builder.add_column(
44 dd.SamplerColumnConfig(
45 name="date_of_visit",
46 sampler_type=dd.SamplerType.TIMEDELTA,
47 params=dd.TimeDeltaSamplerParams(dt_min=1, dt_max=30, reference_column_name="symptom_onset_date"),
48 )
49)
50
51config_builder.add_column(dd.ExpressionColumnConfig(name="physician", expr="Dr. {{ doctor_sampler.last_name }}"))
52
53config_builder.add_column(
54 dd.LLMTextColumnConfig(
55 name="physician_notes",
56 prompt="""\
57You are a primary-care physician who just had an appointment with {{ first_name }} {{ last_name }},
58who has been struggling with symptoms from {{ diagnosis }} since {{ symptom_onset_date }}.
59The date of today's visit is {{ date_of_visit }}.
60
61{{ patient_summary }}
62
63Write careful notes about your visit with {{ first_name }},
64as Dr. {{ doctor_sampler.first_name }} {{ doctor_sampler.last_name }}.
65
66Format the notes as a busy doctor might.
67Respond with only the notes, no other text.
68""",
69 model_alias=MODEL_ALIAS,
70 )
71)
72
73data_designer.validate(config_builder)
74

🔁 Iteration is key – preview the dataset!

  1. Use the preview method to generate a sample of records quickly.

  2. Inspect the results for quality and format issues.

  3. Adjust column configurations, prompts, or parameters as needed.

  4. Re-run the preview until satisfied.

Python
1preview = data_designer.preview(config_builder, num_records=2)
2
Python
1# Run this cell multiple times to cycle through the 2 preview records.
2preview.display_sample_record()
3
Python
1# The preview dataset is available as a pandas DataFrame.
2preview.dataset
3

📊 Analyze the generated data

  • Data Designer automatically generates a basic statistical analysis of the generated data.

  • This analysis is available via the analysis property of generation result objects.

Python
1# Print the analysis as a table.
2preview.analysis.to_report()
3

🆙 Scale up!

  • Happy with your preview data?

  • Use the create method to submit larger Data Designer generation jobs.

Python
1results = data_designer.create(config_builder, num_records=10, dataset_name="tutorial-3")
2
Python
1# Load the generated dataset as a pandas DataFrame.
2dataset = results.load_dataset()
3
4dataset.head()
5
Python
1# Load the analysis results into memory.
2analysis = results.load_analysis()
3
4analysis.to_report()
5

⏭️ Next Steps

Check out the following notebook to learn more about: