davidberenstein1957 HF staff commited on
Commit
5afa3f9
1 Parent(s): b228035

feat: add cached examples

Browse files
src/distilabel_dataset_generator/apps/sft.py CHANGED
@@ -6,9 +6,9 @@ import pandas as pd
6
  from distilabel.distiset import Distiset
7
 
8
  from src.distilabel_dataset_generator.pipelines.sft import (
9
- DEFAULT_DATASET,
10
  DEFAULT_DATASET_DESCRIPTIONS,
11
- DEFAULT_SYSTEM_PROMPT,
 
12
  PROMPT_CREATION_PROMPT,
13
  generate_pipeline_code,
14
  get_pipeline,
@@ -29,6 +29,11 @@ def _run_pipeline(result_queue, num_turns, num_rows, system_prompt, is_sample):
29
 
30
 
31
  def generate_system_prompt(dataset_description, progress=gr.Progress()):
 
 
 
 
 
32
  progress(0.1, desc="Initializing text generation")
33
  generate_description = get_prompt_generation_step()
34
  progress(0.4, desc="Loading model")
@@ -49,6 +54,11 @@ def generate_system_prompt(dataset_description, progress=gr.Progress()):
49
 
50
 
51
  def generate_sample_dataset(system_prompt, progress=gr.Progress()):
 
 
 
 
 
52
  progress(0.1, desc="Initializing sample dataset generation")
53
  result = generate_dataset(
54
  system_prompt, num_turns=1, num_rows=1, progress=progress, is_sample=True
@@ -76,7 +86,7 @@ def generate_dataset(
76
  if repo_id is not None:
77
  if not all([repo_id, org_name, repo_name]):
78
  raise gr.Error(
79
- "Please provide a repo_name and org_name to push the dataset to."
80
  )
81
 
82
  if num_turns > 4:
@@ -150,8 +160,8 @@ css = """
150
  """
151
 
152
  with gr.Blocks(
153
- title="⚗️ Distilabel Dataset Generator",
154
- head="⚗️ Distilabel Dataset Generator",
155
  css=css,
156
  ) as app:
157
  with gr.Row():
@@ -181,12 +191,12 @@ with gr.Blocks(
181
 
182
  system_prompt = gr.TextArea(
183
  label="System prompt for dataset generation. You can tune it and regenerate the sample",
184
- value=DEFAULT_SYSTEM_PROMPT,
185
  )
186
 
187
  with gr.Row():
188
  table = gr.DataFrame(
189
- value=DEFAULT_DATASET,
190
  label="Sample dataset. Prompts and completions truncated to 256 tokens.",
191
  interactive=False,
192
  wrap=True,
@@ -266,7 +276,7 @@ with gr.Blocks(
266
  success_message = gr.Markdown(visible=False)
267
  with gr.Row():
268
  final_dataset = gr.DataFrame(
269
- value=DEFAULT_DATASET,
270
  label="Generated dataset",
271
  interactive=False,
272
  wrap=True,
 
6
  from distilabel.distiset import Distiset
7
 
8
  from src.distilabel_dataset_generator.pipelines.sft import (
 
9
  DEFAULT_DATASET_DESCRIPTIONS,
10
+ DEFAULT_DATASETS,
11
+ DEFAULT_SYSTEM_PROMPTS,
12
  PROMPT_CREATION_PROMPT,
13
  generate_pipeline_code,
14
  get_pipeline,
 
29
 
30
 
31
  def generate_system_prompt(dataset_description, progress=gr.Progress()):
32
+ if dataset_description in DEFAULT_DATASET_DESCRIPTIONS:
33
+ index = DEFAULT_DATASET_DESCRIPTIONS.index(dataset_description)
34
+ if index < len(DEFAULT_SYSTEM_PROMPTS):
35
+ return DEFAULT_SYSTEM_PROMPTS[index]
36
+
37
  progress(0.1, desc="Initializing text generation")
38
  generate_description = get_prompt_generation_step()
39
  progress(0.4, desc="Loading model")
 
54
 
55
 
56
  def generate_sample_dataset(system_prompt, progress=gr.Progress()):
57
+ if system_prompt in DEFAULT_SYSTEM_PROMPTS:
58
+ index = DEFAULT_SYSTEM_PROMPTS.index(system_prompt)
59
+ if index < len(DEFAULT_DATASETS):
60
+ return DEFAULT_DATASETS[index]
61
+
62
  progress(0.1, desc="Initializing sample dataset generation")
63
  result = generate_dataset(
64
  system_prompt, num_turns=1, num_rows=1, progress=progress, is_sample=True
 
86
  if repo_id is not None:
87
  if not all([repo_id, org_name, repo_name]):
88
  raise gr.Error(
89
+ "Please provide a `repo_name` and `org_name` to push the dataset to."
90
  )
91
 
92
  if num_turns > 4:
 
160
  """
161
 
162
  with gr.Blocks(
163
+ title="🧶 DataCraft",
164
+ head="🧶 DataCraft",
165
  css=css,
166
  ) as app:
167
  with gr.Row():
 
191
 
192
  system_prompt = gr.TextArea(
193
  label="System prompt for dataset generation. You can tune it and regenerate the sample",
194
+ value=DEFAULT_SYSTEM_PROMPTS[0],
195
  )
196
 
197
  with gr.Row():
198
  table = gr.DataFrame(
199
+ value=DEFAULT_DATASETS[0],
200
  label="Sample dataset. Prompts and completions truncated to 256 tokens.",
201
  interactive=False,
202
  wrap=True,
 
276
  success_message = gr.Markdown(visible=False)
277
  with gr.Row():
278
  final_dataset = gr.DataFrame(
279
+ value=DEFAULT_DATASETS[0],
280
  label="Generated dataset",
281
  interactive=False,
282
  wrap=True,
src/distilabel_dataset_generator/pipelines/sft.py CHANGED
@@ -122,17 +122,65 @@ DEFAULT_DATASET_DESCRIPTIONS = (
122
  "skilled high school math assistant who helps students solve problems",
123
  "attentive and well-educated customer service assistant for a clothes e-commerce platform",
124
  )
125
- DEFAULT_SYSTEM_PROMPT = """You are an AI assistant specialized in solving complex math problems using Python. Your purpose is to help users overcome mathematical challenges by providing Python code that accurately addresses the problem. Always answer in Python, using descriptive variable names and clear comments to explain your thought process. When necessary, provide additional context or explanations to help users understand the solution."""
126
- DEFAULT_DATASET = pd.DataFrame(
127
- {
128
- "prompt": [
129
- "Find the roots of the equation y = 2x^3 - 3x^2 - 5x + 1, using the numpy library in Python."
130
- ],
131
- "completion": [
132
- """```python import numpy as np # Define the coefficients of the polynomial a = 2 b = -3 c = -5 d = 1 # Create a polynomial object p = np.poly1d([a, b, c, d]) # Find the roots of the polynomial roots = np.roots(p) print("The roots of the equation are: ", roots) ``` This code uses the `np.poly1d` function to create a polynomial object from the coefficients, and then the `np.roots` function to find the roots of the polynomial. The roots are then printed to the console."""
133
- ],
134
- }
135
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  _STOP_SEQUENCES = [
137
  "<|eot_id|>",
138
  "<|start_header_id|>",
@@ -227,7 +275,10 @@ def get_pipeline(num_turns, num_rows, system_prompt, is_sample):
227
  model_id=MODEL,
228
  tokenizer_id=MODEL,
229
  api_key=api_key,
230
- generation_kwargs={"temperature": 0.8, "max_new_tokens": 256 if is_sample else 1024},
 
 
 
231
  ),
232
  system_prompt=system_prompt,
233
  output_mappings={"generation": "completion"},
 
122
  "skilled high school math assistant who helps students solve problems",
123
  "attentive and well-educated customer service assistant for a clothes e-commerce platform",
124
  )
125
+ DEFAULT_SYSTEM_PROMPTS = [
126
+ """You are an AI assistant specialized in solving complex math problems using Python. Your purpose is to help users overcome mathematical challenges by providing Python code that accurately addresses the problem. Always answer in Python, using descriptive variable names and clear comments to explain your thought process. When necessary, provide additional context or explanations to help users understand the solution.""",
127
+ """You are an AI assistant designed to provide thoughtful and reflective responses to a wide range of questions and problems. Your purpose is to guide users through a chain of thought by breaking down complex issues into manageable steps, analyzing each component, and evaluating potential solutions. Offer step-by-step explanations of your reasoning process, clearly define the assumptions that underlie your responses, and be willing to revise or refine your answers based on additional information or new perspectives. Provide transparent and reflective thinking in your responses, and engage users in the problem-solving process by encouraging them to consider alternatives and evaluate the implications of different approaches.""",
128
+ """You are a highly specialized AI assistant for expert PyTorch and CUDA developers. Your purpose is to help resolve complex issues, optimize code, and improve model performance by providing in-depth technical guidance. Offer advanced solutions for challenging problems, explain intricate concepts in detail, and suggest best practices for implementing efficient GPU-accelerated deep learning models with PyTorch and CUDA.""",
129
+ """You are a math assistant designed to support high school students with various mathematical topics. Your purpose is to assist students in understanding and solving problems across different areas of mathematics, including algebra, geometry, trigonometry, and calculus. Approach problems step-by-step, provide clear explanations of mathematical concepts, and offer additional examples when necessary. Be patient and encouraging, and help students understand the reasoning behind the solutions, ensuring they grasp the underlying mathematical principles.""",
130
+ """You are an AI assistant designed to provide exceptional customer service for a clothes e-commerce platform. Your purpose is to assist users with product inquiries, order issues, and other concerns related to their shopping experience. Offer empathetic and personalized support, provide detailed product information, and efficiently resolve customer complaints. Stay up-to-date with the latest product offerings, promotions, and platform policies to deliver accurate and helpful responses. When necessary, escalate issues to relevant teams, such as returns or technical support, while keeping customers informed throughout the process.""",
131
+ ]
132
+ DEFAULT_DATASETS = [
133
+ pd.DataFrame.from_dict(
134
+ {
135
+ "prompt": [
136
+ "Find the roots of the equation y = 2x^3 - 3x^2 - 5x + 1, using the numpy library in Python."
137
+ ],
138
+ "completion": [
139
+ """```python import numpy as np # Define the coefficients of the polynomial a = 2 b = -3 c = -5 d = 1 # Create a polynomial object p = np.poly1d([a, b, c, d]) # Find the roots of the polynomial roots = np.roots(p) print("The roots of the equation are: ", roots) ``` This code uses the `np.poly1d` function to create a polynomial object from the coefficients, and then the `np.roots` function to find the roots of the polynomial. The roots are then printed to the console."""
140
+ ],
141
+ }
142
+ ),
143
+ pd.DataFrame.from_dict(
144
+ {
145
+ "prompt": [
146
+ "1. Find the number of words in the phrase'multiply large numbers by 5, and divide the result by 3.'"
147
+ ],
148
+ "completion": [
149
+ """To find the number of words in the given phrase, we will count each word individually: 1. multiply 2. large 3. numbers 4. by 5. 5, 6. and 7. divide 8. the 9. result 10. by 11. 3. There are 11 words in the phrase "multiply large numbers by 5, and divide the result by 3."""
150
+ ],
151
+ }
152
+ ),
153
+ pd.DataFrame.from_dict(
154
+ {
155
+ "prompt": [
156
+ "Given a large image dataset, implement a data pipeline that reads images from a directory, applies data augmentation, and shuffles the dataset for efficient data loading and training of a deep learning model.'"
157
+ ],
158
+ "completion": [
159
+ '**Image Data Pipeline with PyTorch** ===================================== In this example, we\'ll create a data pipeline that reads images from a directory, applies data augmentation, and shuffles the dataset for efficient data loading and training of a deep learning model. **Prerequisites** ----------------- * PyTorch 1.10 or later * CUDA toolkit (for GPU acceleration) * PyTorch Lightning 1.6 or later * Optional: Augmentation techniques (e.g., random cropping, flipping, rotation, color jittering) **Code** ------ ```python import os import glob import cv2 import torch from torch.utils.data import DataLoader, Dataset from torchvision import transforms from torchvision.transforms import Compose, ToTensor, Normalize from torchvision.transforms import functional as TF from pytorch_lightning.core.lightning import LightningDataModule from pytorch_lightning.core import seed_everything import numpy as np class ImageDataset(Dataset): """Custom dataset class for loading images from a directory.""" def __init__(self, image_dir, transform): self.image_dir = image_dir self.transform = transform self.image_files = glob.glob(os.path.join(image_dir, "*.jpg")) +'
160
+ ],
161
+ }
162
+ ),
163
+ pd.DataFrame.from_dict(
164
+ {
165
+ "prompt": [
166
+ "# How do you stay so patient and encouraging with your assistance? ## Developing a Supportive Learning Environment To stay patient and encouraging as a math assistant'"
167
+ ],
168
+ "completion": [
169
+ """Developing a supportive learning environment is crucial for effective assistance, and I'm glad you asked. As a math assistant, my primary goal is to create a safe and non-intimidating space for students to learn and grow. Here are some strategies I use to stay patient and encouraging: ### 1. **Active Listening** Actively listening to the student's concerns, questions, and problems helps me understand their thought process and difficulties. This allows me to tailor my explanations and examples to their specific needs. ### 2. **Empathy and Understanding** I recognize that math can be challenging, and it's okay to make mistakes. I acknowledge students' feelings and frustrations, providing reassurance that they're not alone in their struggles. ### 3. **Breaking Down Complex Concepts** I believe that breaking down complex math concepts into manageable, bite-sized pieces helps students build confidence and comprehension. By explaining each step clearly and concisely, I help students see the logic and beauty of mathematics. ### 4. **Positive Reinforcement** I celebrate small victories and accomplishments along the way, no matter how insignificant they may seem. This encourages students to continue practicing and pushing themselves beyond their comfort zones. ### 5. **Adapting to Learning Styles** Every student learns differently"""
170
+ ],
171
+ }
172
+ ),
173
+ pd.DataFrame.from_dict(
174
+ {
175
+ "prompt": [
176
+ "How do I start shopping on this website? 1. To begin shopping on our website, simply navigate to our home page. 2. Click on the 'Shop' button located at the top right corner of the page. 3. Browse through the various categories of clothing that we offer to find what you are looking for. 4. Once you find an item you're interested in, click on it to view its product details. 5. Select your desired size and color from the available options. 6. Add the item to your cart by clicking the 'Add to Cart' button. 7. Once you've added all the items you want, proceed to checkout. 8. Review your order details, select your shipping options, and complete the payment. If you need help with any of these steps, I'm here to answer any questions you may have."
177
+ ],
178
+ "completion": [
179
+ """It sounds like you're all set to start shopping on our website. If you have any specific questions or need assistance with navigating the site, I'd be more than happy to help. However, if you're ready to get started, you can simply follow the steps I outlined earlier. To summarize, you can begin by clicking the 'Shop' button at the top right corner of the home page, then browse through our categories to find the products that interest you. If you have any questions about specific products or categories, feel free to ask, and I'll do my best to provide you with more information. Additionally, if you need any help with sizing or color options, please let me know, and I can provide you with more details on those. We have a size chart and product descriptions available to help you make the best choice for your needs. Let me know if there's anything specific you're looking for or if you have any questions about our products or services. I'm here to help make your shopping experience as smooth and enjoyable as possible."""
180
+ ],
181
+ }
182
+ ),
183
+ ]
184
  _STOP_SEQUENCES = [
185
  "<|eot_id|>",
186
  "<|start_header_id|>",
 
275
  model_id=MODEL,
276
  tokenizer_id=MODEL,
277
  api_key=api_key,
278
+ generation_kwargs={
279
+ "temperature": 0.8,
280
+ "max_new_tokens": 256 if is_sample else 1024,
281
+ },
282
  ),
283
  system_prompt=system_prompt,
284
  output_mappings={"generation": "completion"},