Skip to content

Instantly share code, notes, and snippets.

@wesslen
Created June 26, 2024 20:22
Show Gist options
  • Save wesslen/5793c4786c2a5be3ea22a8bc7d514752 to your computer and use it in GitHub Desktop.
Save wesslen/5793c4786c2a5be3ea22a8bc7d514752 to your computer and use it in GitHub Desktop.
anthropic-distilabel-selfinstruct.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMkf0mFA5Fea2Uv4Lb280PH",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/wesslen/5793c4786c2a5be3ea22a8bc7d514752/anthropic-distilabel-selfinstruct.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"!pip install distilabel"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 115
},
"id": "Dx_yb3LaGIx6",
"outputId": "415536c1-9b20-489a-98bf-330ffca24be7"
},
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"application/vnd.colab-display-data+json": {
"pip_warning": {
"packages": [
"pyarrow",
"requests"
]
},
"id": "e9bcb320af1a4fa49a4e5e7669accc82"
}
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"!pip install anthropic"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "KsAgOB6wH-xm",
"outputId": "ea0b5ca3-2571-4a43-b2e9-aa7116b37b8b"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting anthropic\n",
" Downloading anthropic-0.30.0-py3-none-any.whl (863 kB)\n",
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/863.5 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m112.6/863.5 kB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m860.2/863.5 kB\u001b[0m \u001b[31m14.8 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m863.5/863.5 kB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from anthropic) (3.7.1)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from anthropic) (1.7.0)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from anthropic) (0.27.0)\n",
"Collecting jiter<1,>=0.4.0 (from anthropic)\n",
" Downloading jiter-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (318 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.9/318.9 kB\u001b[0m \u001b[31m28.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from anthropic) (2.7.4)\n",
"Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from anthropic) (1.3.1)\n",
"Requirement already satisfied: tokenizers>=0.13.0 in /usr/local/lib/python3.10/dist-packages (from anthropic) (0.19.1)\n",
"Requirement already satisfied: typing-extensions<5,>=4.7 in /usr/local/lib/python3.10/dist-packages (from anthropic) (4.12.2)\n",
"Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->anthropic) (3.7)\n",
"Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->anthropic) (1.2.1)\n",
"Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->anthropic) (2024.6.2)\n",
"Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->anthropic) (1.0.5)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->anthropic) (0.14.0)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->anthropic) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.18.4 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->anthropic) (2.18.4)\n",
"Requirement already satisfied: huggingface-hub<1.0,>=0.16.4 in /usr/local/lib/python3.10/dist-packages (from tokenizers>=0.13.0->anthropic) (0.23.4)\n",
"Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (3.15.3)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2023.6.0)\n",
"Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (24.1)\n",
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (6.0.1)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2.32.3)\n",
"Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (4.66.4)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (3.3.2)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2.0.7)\n",
"Installing collected packages: jiter, anthropic\n",
"Successfully installed anthropic-0.30.0 jiter-0.5.0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# seed_tasks=[\n",
"# {\"id\": \"seed_task_0\", \"name\": \"window_replacement\", \"instruction\": \"Can I replace my old windows with new energy-efficient ones without permission from the HDC?\", \"instances\": [{\"input\": \"\", \"output\": \"No, you cannot replace windows without permission from the Historic District Commission (HDC). Window replacement is considered a significant alteration to the exterior appearance of a historic building. You must submit an application to the HDC for review and approval before proceeding with any window replacement project, even if the new windows are energy-efficient.\"}], \"is_classification\": True},\n",
"# {\"id\": \"seed_task_1\", \"name\": \"paint_color_change\", \"instruction\": \"I want to repaint my house exterior. Do I need HDC approval for this?\", \"instances\": [{\"input\": \"\", \"output\": \"Yes, you need HDC approval to repaint the exterior of your house in the Historic Residential District. The HDC typically reviews and approves exterior color changes to ensure they are appropriate for the historic character of the neighborhood. You'll need to submit an application with your proposed color scheme for review.\"}], \"is_classification\": True},\n",
"# {\"id\": \"seed_task_2\", \"name\": \"solar_panel_installation\", \"instruction\": \"What's the process for installing solar panels on my roof in the historic district?\", \"instances\": [{\"input\": \"\", \"output\": \"To install solar panels on your roof in the historic district, you must follow these steps:\\n1. Submit an application to the HDC for review.\\n2. Provide detailed plans showing the proposed location and appearance of the solar panels.\\n3. Include information on how visible the panels will be from public streets.\\n4. Wait for HDC review and approval before proceeding.\\n5. If approved, obtain necessary building permits.\\n6. Install the solar panels according to the approved plans.\\nThe HDC will consider the visual impact on the historic character of your property and the surrounding area when making their decision.\"}], \"is_classification\": False},\n",
"# {\"id\": \"seed_task_3\", \"name\": \"fence_repair\", \"instruction\": \"Do I need permission to repair my existing fence?\", \"instances\": [{\"input\": \"\", \"output\": \"Generally, you do not need HDC permission to repair an existing fence if you are using the same materials and design. However, if the repair involves replacing a significant portion of the fence or changing any aspect of its appearance (height, style, material), you will need to submit an application to the HDC for review and approval.\"}], \"is_classification\": True},\n",
"# {\"id\": \"seed_task_4\", \"name\": \"roof_replacement\", \"instruction\": \"I need to replace my roof due to leaks. What are the guidelines for roof replacement in the historic district?\", \"instances\": [{\"input\": \"\", \"output\": \"For roof replacement in the historic district:\\n1. HDC approval is required before starting work.\\n2. Submit an application with details of the proposed roofing material.\\n3. The new roofing should match the original in color, texture, and pattern as closely as possible.\\n4. If changing the roofing material (e.g., from slate to asphalt shingles), provide a justification for the change.\\n5. Consider using materials that maintain the historic character while meeting modern standards.\\n6. Retain and repair decorative elements like cornices, brackets, or chimneys if possible.\\n7. After HDC approval, obtain necessary building permits before beginning work.\"}], \"is_classification\": False},\n",
"# {\"id\": \"seed_task_5\", \"name\": \"landscaping_changes\", \"instruction\": \"Are there any restrictions on landscaping changes I can make to my front yard?\", \"instances\": [{\"input\": \"\", \"output\": \"While minor landscaping changes typically don't require HDC approval, there are some restrictions:\\n1. Significant changes to the landscape design or hardscaping (e.g., adding a large patio) require HDC review.\\n2. Removing mature trees often requires permission.\\n3. Adding or removing walls, fences, or other structures needs HDC approval.\\n4. Major grade changes that alter the property's appearance from the street require review.\\n5. Installing large water features or extensive lighting systems may need approval.\\nFor any major changes, it's best to consult with the HDC staff before proceeding.\"}], \"is_classification\": False},\n",
"# {\"id\": \"seed_task_6\", \"name\": \"garage_door_replacement\", \"instruction\": \"Can I replace my garage door without getting permission from the HDC?\", \"instances\": [{\"input\": \"\", \"output\": \"No, you cannot replace your garage door without permission from the HDC. Garage doors are considered a significant architectural feature, especially if visible from the street. You need to submit an application to the HDC for review and approval before replacing your garage door. The HDC will consider factors such as the style, material, and color of the proposed door to ensure it's compatible with the historic character of your property and the district.\"}], \"is_classification\": True},\n",
"# {\"id\": \"seed_task_7\", \"name\": \"storm_window_installation\", \"instruction\": \"What's the process for adding storm windows to my historic home?\", \"instances\": [{\"input\": \"\", \"output\": \"The process for adding storm windows to your historic home is as follows:\\n1. Submit an application to the HDC for review and approval.\\n2. Provide details on the proposed storm windows, including material, color, and style.\\n3. Ensure the storm windows will be installed on the exterior and match the size and shape of the existing windows.\\n4. Choose storm windows that are as unobtrusive as possible (e.g., with narrow frames that don't obscure original window details).\\n5. Consider interior storm windows as an alternative, which may not require HDC approval.\\n6. Wait for HDC approval before purchasing or installing the storm windows.\\n7. Once approved, install the storm windows according to the approved specifications.\"}], \"is_classification\": False},\n",
"# {\"id\": \"seed_task_8\", \"name\": \"gutter_replacement\", \"instruction\": \"Do I need HDC approval to replace my gutters?\", \"instances\": [{\"input\": \"\", \"output\": \"Yes, you typically need HDC approval to replace gutters in the historic district. While this might seem like a minor change, gutters can significantly impact the appearance of a historic building. Submit an application to the HDC including details about the proposed gutter material, style, and color. The HDC will review your application to ensure the new gutters are compatible with the historic character of your home and the district.\"}], \"is_classification\": True},\n",
"# {\"id\": \"seed_task_9\", \"name\": \"porch_restoration\", \"instruction\": \"I want to restore my historic front porch. What should I know before starting this project?\", \"instances\": [{\"input\": \"\", \"output\": \"Before starting a porch restoration project:\\n1. HDC approval is required. Submit a detailed application including plans and materials.\\n2. Research the original porch design if possible, using old photographs or similar houses in the district.\\n3. Aim to preserve as much original material as possible. Repair rather than replace when feasible.\\n4. If replacement is necessary, use materials that match the original in design, color, texture, and other visual qualities.\\n5. Maintain the porch's original dimensions, roof shape, and decorative details.\\n6. Consider hiring a contractor experienced in historic restoration.\\n7. Be prepared for the HDC to request specific materials or techniques to maintain historical accuracy.\\n8. After HDC approval, obtain necessary building permits before starting work.\\n9. Document the restoration process, as this information can be valuable for future maintenance or HDC records.\"}], \"is_classification\": False}\n",
"# ]\n",
"\n",
"seed_tasks = [\n",
" {\"input\": \"Can I replace my old windows with new energy-efficient ones without permission from the HDC?\"},\n",
" {\"input\": \"I want to repaint my house exterior. Do I need HDC approval for this?\"},\n",
" {\"input\": \"What's the process for installing solar panels on my roof in the historic district?\"},\n",
" {\"input\": \"Do I need permission to repair my existing fence?\"},\n",
" {\"input\": \"I need to replace my roof due to leaks. What are the guidelines for roof replacement in the historic district?\"},\n",
" {\"input\": \"Are there any restrictions on landscaping changes I can make to my front yard?\"},\n",
" {\"input\": \"Can I replace my garage door without getting permission from the HDC?\"},\n",
" {\"input\": \"What's the process for adding storm windows to my historic home?\"},\n",
" {\"input\": \"Do I need HDC approval to replace my gutters?\"},\n",
" {\"input\": \"I want to restore my historic front porch. What should I know before starting this project?\"},\n",
"]"
],
"metadata": {
"id": "KVahdAuRGg5Y"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from distilabel.steps.tasks import SelfInstruct\n",
"from distilabel.llms import AnthropicLLM\n",
"from google.colab import userdata\n",
"\n",
"# Set your API key\n",
"API_KEY = userdata.get('ANTHROPIC_API_KEY')\n",
"llm = AnthropicLLM(model=\"claude-3-opus-20240229\", api_key=API_KEY)\n",
"\n",
"self_instruct = SelfInstruct(\n",
" llm=llm,\n",
" num_instructions=5, # This is the default value\n",
")\n",
"\n",
"self_instruct.load()\n",
"\n",
"result = next(self_instruct.process(seed_tasks))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "kEbe-4R6GK1K",
"outputId": "3bf6a94a-97d9-47bb-f95a-ca11e61773ce"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"WARNING:distilabel.step.None:Step 'None' hasn't received a pipeline, and it hasn't been created within a `Pipeline` context. Please, use `with Pipeline() as pipeline:` and create the step within the context.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"result"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "FLkQy94-I70E",
"outputId": "07ca2898-5150-48b5-f233-ea0b48b54e96"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[{'input': 'Can I replace my old windows with new energy-efficient ones without permission from the HDC?',\n",
" 'instructions': ['What are the key benefits of installing energy-efficient windows in my home?',\n",
" 'Explain the process of obtaining approval from the HDC for window replacement.',\n",
" 'How do energy-efficient windows compare to traditional windows in terms of cost savings?',\n",
" 'Describe the typical features and technologies used in modern energy-efficient windows.',\n",
" 'Are there any specific requirements or guidelines set by the HDC for replacing old windows with energy-efficient ones?'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': 'What are the key benefits of installing energy-efficient windows in my home?\\n\\nExplain the process of obtaining approval from the HDC for window replacement.\\n\\nHow do energy-efficient windows compare to traditional windows in terms of cost savings?\\n\\nDescribe the typical features and technologies used in modern energy-efficient windows.\\n\\nAre there any specific requirements or guidelines set by the HDC for replacing old windows with energy-efficient ones?'},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': 'I want to repaint my house exterior. Do I need HDC approval for this?',\n",
" 'instructions': ['What factors determine if HDC approval is necessary for repainting a house exterior?',\n",
" 'Explain the process of obtaining HDC approval to repaint the outside of a home.',\n",
" 'Are there any specific paint colors or finishes that usually require HDC authorization?',\n",
" 'How can I find out if my house painting plans need to be approved by the HDC?',\n",
" 'Detail the potential consequences of repainting a house exterior without proper HDC approval.'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': 'What factors determine if HDC approval is necessary for repainting a house exterior?\\nExplain the process of obtaining HDC approval to repaint the outside of a home.\\nAre there any specific paint colors or finishes that usually require HDC authorization?\\nHow can I find out if my house painting plans need to be approved by the HDC?\\nDetail the potential consequences of repainting a house exterior without proper HDC approval.'},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': \"What's the process for installing solar panels on my roof in the historic district?\",\n",
" 'instructions': ['How do I determine if my roof is suitable for solar panel installation?',\n",
" 'Explain the steps required to obtain approval for installing solar panels in a historic district.',\n",
" 'What are the most important factors to consider when choosing solar panels for a historic home?',\n",
" 'Describe the typical timeframe and costs associated with a residential solar panel project in a protected neighborhood.',\n",
" 'Can you walk me through the key differences between installing solar on a modern home versus one in a historic district?'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': 'How do I determine if my roof is suitable for solar panel installation?\\nExplain the steps required to obtain approval for installing solar panels in a historic district.\\nWhat are the most important factors to consider when choosing solar panels for a historic home?\\nDescribe the typical timeframe and costs associated with a residential solar panel project in a protected neighborhood.\\nCan you walk me through the key differences between installing solar on a modern home versus one in a historic district?'},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': 'Do I need permission to repair my existing fence?',\n",
" 'instructions': ['Here are 5 diverse user queries related to the given context about fence repair permissions:',\n",
" 'Explain the legal requirements for fixing my current fence on my property.',\n",
" 'Who should I contact to determine if a permit is necessary before starting fence repairs?',\n",
" 'What factors influence whether permission is needed to mend an existing residential fence?',\n",
" 'Outline the typical process for obtaining approval to restore a damaged fence, if required.',\n",
" 'Under what circumstances can I proceed with fence repairs without seeking prior authorization?'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': 'Here are 5 diverse user queries related to the given context about fence repair permissions:\\n\\nExplain the legal requirements for fixing my current fence on my property.\\nWho should I contact to determine if a permit is necessary before starting fence repairs?\\nWhat factors influence whether permission is needed to mend an existing residential fence?\\nOutline the typical process for obtaining approval to restore a damaged fence, if required.\\nUnder what circumstances can I proceed with fence repairs without seeking prior authorization?'},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': 'I need to replace my roof due to leaks. What are the guidelines for roof replacement in the historic district?',\n",
" 'instructions': ['Here are 5 diverse user queries that could be asked of the AI assistant for the given context:',\n",
" 'What requirements must be met when replacing a roof in a designated historic district?',\n",
" 'Explain the key considerations for selecting roofing materials that comply with historic preservation guidelines.',\n",
" 'How does the roof replacement approval process differ for homes located within historic districts compared to those outside such areas?',\n",
" \"Describe the steps a homeowner should follow to ensure their roof replacement adheres to the historic district's regulations.\",\n",
" \"What are the potential consequences of failing to comply with the historic district's roof replacement guidelines?\"],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': \"Here are 5 diverse user queries that could be asked of the AI assistant for the given context:\\n\\nWhat requirements must be met when replacing a roof in a designated historic district?\\nExplain the key considerations for selecting roofing materials that comply with historic preservation guidelines.\\nHow does the roof replacement approval process differ for homes located within historic districts compared to those outside such areas?\\nDescribe the steps a homeowner should follow to ensure their roof replacement adheres to the historic district's regulations.\\nWhat are the potential consequences of failing to comply with the historic district's roof replacement guidelines?\"},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': 'Are there any restrictions on landscaping changes I can make to my front yard?',\n",
" 'instructions': ['Here are 5 diverse user queries related to front yard landscaping restrictions:',\n",
" 'What types of plants or trees are prohibited from being planted in front yards in my neighborhood?',\n",
" 'Explain the process for getting approval from the homeowners association to install a water feature.',\n",
" 'Am I allowed to remove the existing grass in my front yard and replace it with xeriscaping or rock gardens?',\n",
" 'Describe any setback requirements or height limitations that apply to building retaining walls in the front yard.',\n",
" 'What permits are necessary from the city before adding a paved parking pad next to my driveway?'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': 'Here are 5 diverse user queries related to front yard landscaping restrictions:\\n\\nWhat types of plants or trees are prohibited from being planted in front yards in my neighborhood?\\nExplain the process for getting approval from the homeowners association to install a water feature.\\nAm I allowed to remove the existing grass in my front yard and replace it with xeriscaping or rock gardens?\\nDescribe any setback requirements or height limitations that apply to building retaining walls in the front yard.\\nWhat permits are necessary from the city before adding a paved parking pad next to my driveway?'},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': 'Can I replace my garage door without getting permission from the HDC?',\n",
" 'instructions': ['Here are 5 diverse user queries related to replacing a garage door without HDC permission:',\n",
" 'Explain the potential consequences of changing my garage door without approval from the homeowners association.',\n",
" 'What steps should I take to try to get my new garage door design authorized by the HDC? ',\n",
" 'Are there any loopholes or exceptions that would allow me to install a new garage door without going through the HDC process?',\n",
" 'Describe the risks and downsides of proceeding with a garage door replacement without obtaining the required permissions first.',\n",
" 'How can I determine if my planned garage door replacement definitely requires HDC approval or'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': 'Here are 5 diverse user queries related to replacing a garage door without HDC permission:\\n\\nExplain the potential consequences of changing my garage door without approval from the homeowners association.\\nWhat steps should I take to try to get my new garage door design authorized by the HDC? \\nAre there any loopholes or exceptions that would allow me to install a new garage door without going through the HDC process?\\nDescribe the risks and downsides of proceeding with a garage door replacement without obtaining the required permissions first.\\nHow can I determine if my planned garage door replacement definitely requires HDC approval or'},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': \"What's the process for adding storm windows to my historic home?\",\n",
" 'instructions': ['Here are 5 diverse user queries related to adding storm windows to a historic home:',\n",
" 'Explain the benefits of installing storm windows on an older house.',\n",
" 'What factors should I consider when selecting storm windows for my historic property?',\n",
" 'Describe the typical installation process for exterior storm windows.',\n",
" 'How can storm windows improve the energy efficiency of my heritage home without compromising its character?',\n",
" 'What are some recommended storm window materials that complement the aesthetics of historic houses?'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': 'Here are 5 diverse user queries related to adding storm windows to a historic home:\\n\\nExplain the benefits of installing storm windows on an older house.\\nWhat factors should I consider when selecting storm windows for my historic property?\\nDescribe the typical installation process for exterior storm windows.\\nHow can storm windows improve the energy efficiency of my heritage home without compromising its character?\\nWhat are some recommended storm window materials that complement the aesthetics of historic houses?'},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': 'Do I need HDC approval to replace my gutters?',\n",
" 'instructions': ['Here are 5 diverse user queries related to the given context that an AI assistant could handle:',\n",
" 'Explain the process for obtaining HDC approval to replace gutters on my property.',\n",
" 'What factors does the HDC consider when reviewing gutter replacement applications? ',\n",
" 'Outline the steps I should take before submitting my gutter replacement request to the HDC.',\n",
" \"How do I determine if my gutter replacement project requires HDC approval or if it's exempt?\",\n",
" \"Walk me through filling out the HDC application forms for replacing my home's gutters.\"],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': \"Here are 5 diverse user queries related to the given context that an AI assistant could handle:\\n\\nExplain the process for obtaining HDC approval to replace gutters on my property.\\nWhat factors does the HDC consider when reviewing gutter replacement applications? \\nOutline the steps I should take before submitting my gutter replacement request to the HDC.\\nHow do I determine if my gutter replacement project requires HDC approval or if it's exempt?\\nWalk me through filling out the HDC application forms for replacing my home's gutters.\"},\n",
" 'model_name': 'claude-3-opus-20240229'},\n",
" {'input': 'I want to restore my historic front porch. What should I know before starting this project?',\n",
" 'instructions': ['Here are 5 diverse user queries related to restoring a historic front porch:',\n",
" 'Describe the key considerations when selecting materials for a historic porch restoration.',\n",
" 'What are the most important steps to take before beginning work on my historic front porch? ',\n",
" 'Explain the process of repairing and replacing damaged porch floorboards.',\n",
" \"How can I determine if my porch's current structure is sound enough to restore?\",\n",
" 'Suggest some ways to modernize my historic front porch while preserving its original character.'],\n",
" 'distilabel_metadata': {'raw_output_self_instruct_0': \"Here are 5 diverse user queries related to restoring a historic front porch:\\n\\nDescribe the key considerations when selecting materials for a historic porch restoration.\\nWhat are the most important steps to take before beginning work on my historic front porch? \\nExplain the process of repairing and replacing damaged porch floorboards.\\nHow can I determine if my porch's current structure is sound enough to restore?\\nSuggest some ways to modernize my historic front porch while preserving its original character.\"},\n",
" 'model_name': 'claude-3-opus-20240229'}]"
]
},
"metadata": {},
"execution_count": 14
}
]
},
{
"cell_type": "code",
"source": [
"import json\n",
"\n",
"def process_results(results):\n",
" processed_instructions = []\n",
"\n",
" for item in results:\n",
" # Add the original input\n",
" processed_instructions.append({\"instruction\": item['input']})\n",
"\n",
" # Process each instruction in the list\n",
" for instruction in item['instructions']:\n",
" # Skip instructions that start with \"Here are\"\n",
" if not instruction.lstrip().startswith(\"Here are\"):\n",
" processed_instructions.append({\"instruction\": instruction})\n",
"\n",
" return processed_instructions\n",
"\n",
"def save_to_jsonl(data, filename):\n",
" with open(filename, 'w') as f:\n",
" for item in data:\n",
" json.dump(item, f)\n",
" f.write('\\n')\n",
"\n",
"# Process the results\n",
"processed_data = process_results(results)\n",
"\n",
"# Save to a JSONL file\n",
"output_file = 'processed_instructions.jsonl'\n",
"save_to_jsonl(processed_data, output_file)\n",
"\n",
"print(f\"Processed instructions have been saved to {output_file}\")"
],
"metadata": {
"id": "pqJyFtW6NdTZ"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from distilabel.steps.tasks import TextGeneration\n",
"from distilabel.llms.huggingface import InferenceEndpointsLLM\n",
"\n",
"# Consider this as a placeholder for your actual LLM.\n",
"text_gen = TextGeneration(\n",
" llm=llm\n",
")\n",
"\n",
"text_gen.load()\n",
"\n",
"result = next(\n",
" text_gen.process(\n",
" processed_data\n",
" )"
],
"metadata": {
"id": "HArM-tW2MEWd"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment