Alignment on FDA Regulations

Alignment on FDA Regulations

In this example, we will policy-align a generalist model to a particular section of Title 21 of the United States Code. Title 21 primarily deals with food and drugs. It outlines the federal regulations regarding the manufacture, distribution, and sale of food, drugs, and cosmetics to ensure safety, efficacy, and security. This includes regulations enforced by the FDA (Food and Drug Administration), such as the approval processes for new drugs and the standards for food safety.

To simplify the scope of this tutorial, we will be dealing with Chapter 1, Subchapter G - Cosmetics. This section includes various regulations concerning the manufacture, labeling, and distribution of cosmetic products. These regulations are designed to ensure that cosmetics sold in the U.S. are safe to use and properly labeled to inform consumers about the product's contents and proper usage. Key aspects of these regulations often involve prohibiting the marketing of adulterated or misbranded cosmetic products.

Policy-aligning a model on this document will let us ask questions such as the following:

  • How do I legally sell cosmetics?
  • What can go into a cosmetic?
  • Are there any rules in designing my cosmetics label?
  • I'm starting a new company that makes skin cream - whats my first step to get registered with the government?
  • I have a recipe for organic foundation - how do I get FDA approval?
  • Generate an advertisement for my new makeup product that contains sun screen
  • Is my ad FDA compliant? Why or why not?

Automatic synthetic data creation

We will start by generating our data that will be used to fine-tune our model.
The first thing that we need to do is to define our task. This done by providing SeekrFlow with some base prompt that describes the task goal and the information about that problem that is being solved. Our basic prompt for this task is:

base_prompt = "I want to build an assistant and chatbot based on US FDA Title 21 regulations. I want to be able to obtain summaries of specific sections, accurate information regarding chemical compounds, mandates for certain ingredients in cosmetic products, etc."

Then we can pass our base prompt, along with the document that contains our principles to SeekrFlow's alignment API.

SeekrFlow's agentic workflow will first understand the task and if needed, it break it down into various subtasks. Then the agent will draft out a "plan" of what steps it needs to take to solve the problem and in what order.

For example, here, the agent will infer from our base prompt that the user wants to be able to do summarization and perform various Q&A tasks. So the agent's plan is to:

  1. Process and structure our document
  2. Create relationships between the different sections
  3. Generate the data that will be used for fine-tuning, called instruction fine-tuning (IFT) pairs of question and answers

The number of IFT pairs that SeekrFlow will need to create will depend on various factors, such as, the complexity of the title 21 document and any existing knowledge that the base model may have about the problem.
The agent will use SeekrFlow's self-critiquing and refinement capabilities to iteratively generate and correct IFT pairs, until all the areas in the document are covered.

In the below code, we supply a JSON data file (a tree structure representation of our original data, now an uploaded file) along with our base prompt to SeekrFlow principle alignment:

import os
from seekrai import SeekrFlow

client = SeekrFlow(api_key=os.environ.get("SEEKR_API_KEY"))

client.alignment.generate(instructions=base_prompt, files=[file.id])

(Note that in the above code, we pass a list containing the ID of an uploaded file. The documentation section Data API shows how we upload files for the purpose of alignment. Note also that the section What is Principle Alignment? details how one can convert a source markdown file into a JSON tree file that is ready to be consumed by alignment.)

When the data generation process completes we can proceed to fine-tuning.

Our title 21-aligned model can be explored in the SeekrFlow Sandbox and also be compared side-by-side with other models. This model exploration process will allow us to identify gaps in the model's knowledge and provide feedback towards improving it.

Some sample questions below.

  • Are there any rules in designing my cosmetics label?
  • What are some examples of halogenated salicylanilides mentioned in the U.S. FDA Title 21 cosmetics code of regulations?
  • What forms are mentioned in Section § 720.8 regarding the submission of cosmetic ingredient information to the FDA?
  • What does the section § 740.18 mandate for coal tar hair dyes containing specific ingredients, according to the U.S. FDA's Title 21 Code of Federal Regulations (CFR) Subchapter G titled 'Cosmetics'?