Fine-Tuning LLM: Crafting Personalized Ad Copy with Tuned-Gemini Model

In this proof of concept, we fine-tuned Google’s Gemini-1.0-pro-002 model using 2,363 Facebook ads from Planned Parenthood Action. The result? A specialized AI capable of generating ad copy that closely mimics the organization’s unique style and messaging, demonstrating the power of tailored language models in digital marketing.

Introduction

In today’s fast-paced digital marketing landscape, creating compelling and consistent ad copy is crucial. While large language models offer impressive capabilities, they often lack the nuanced understanding of a brand’s specific voice and style. This is where fine-tuning comes into play. By adapting pre-trained models to specific datasets, we can create AI assistants that not only generate high-quality content but do so in a way that aligns perfectly with a brand’s unique identity and messaging strategy.

Dataset & Model Introduction

For this proof of concept, we turned to the “Political Advertisements from Facebook” dataset available on Kaggle. This rich database, compiled by ProPublica, contains ads run on Facebook, submitted by thousands of users worldwide. The dataset is particularly valuable as it represents real-world, professionally crafted ad copy, making it ideal for our fine-tuning experiment.

From this broader dataset, we focused our efforts on a single advertiser: Planned Parenthood Action. This choice was deliberate, aiming to simulate the text style of an independent entity. By selecting a single advertiser with a suitable number of ads, we could work with a consistent voice and messaging style, crucial for effective fine-tuning. We extracted 2,363 ads from this organization, providing a substantial yet focused dataset for our model to learn from.

A bar chart showing the number of advertisements in the “Political Advertisements from Facebook” dataset.

Training Data Requirements

For fine-tuning a Gemini model, the training dataset must meet specific criteria:

  • Minimum of 16 examples, with 100 to 500 examples recommended for best results.
  • JSON Lines (JSONL) format, where each line contains a single tuning example.
  • Each example consists of a “messages” field with role-content pairs.
  • Roles can be “system” (optional, first element only), “user”, or “model”.
  • Maximum combined token length of 32,768 for context and messages per example.
  • Each “model” content field should not exceed 8,192 tokens.

Here’s a simplified JSON example of our training data structure:

{
"messages": [
{
"role": "system",
"content": "You are a social media copywriter for Planned Parenthood Action. Create ad copy based on the given topic and context."
},
{
"role": "user",
"content": "Topic: Reproductive Rights March\nPolitical Sensitivity: 21 upvotes, 2 downvotes\nCreation Date: 2017-09-08\nCreate an ad based on this information."
},
{
"role": "model",
"content": "Pence, Ryan, and other anti-women's health extremists want to defund Planned Parenthood. We can't let this happen. Help us stop them with a gift to the PP Action Fund Now!"
}
]
}

ref: https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini-supervised-tuning-about

Our base model for this experiment was Google’s Gemini-1.0-pro-002, a powerful language model known for its versatility and performance across various natural language processing tasks.

Model Tuning

Before initiating the fine-tuning process, we first prepared our dataset by filtering and formatting it appropriately. Here’s a simplified version of the Python code used for data preparation:

# Filter rows with the title "Planned Parenthood Action"
pp_action_df = df[df['title'] == 'Planned Parenthood Action']

# Confirm the number of filtered rows
print(f"Number of Planned Parenthood Action ads: {len(pp_action_df)}")

# Save the filtered data to a new CSV file
output_file = 'planned_parenthood_action_ads.csv'
pp_action_df.to_csv(output_file, index=False)

print(f"Filtered data saved to {output_file}")

# Display the first few rows of data
print(pp_action_df.head())

# Show basic statistical information about the data
print(pp_action_df.describe())

This code filters the dataset, saves the relevant ads, and provides a summary of the data we’ll use for fine-tuning.

Next, we prepared the data in the required JSON format and uploaded it to Google Cloud Storage (GCS). With our data ready, we proceeded to the fine-tuning process using Google Cloud Platform’s Vertex AI. Here’s a simplified version of the Python code used to initiate the tuning job:

import vertexai
from vertexai.preview.tuning import sft

vertexai.init(project="<your_project_id>", location="us-central1")

sft_tuning_job = sft.train(
source_model="gemini-1.0-pro-002",
train_dataset="gs://<your_bucket_name>/finetuning/planned_parenthood_action_training_data.jsonl",
epochs=4,
adapter_size=4,
learning_rate_multiplier=1.0,
tuned_model_display_name="planned_parenthood_action_tuned_model",
)

This code initializes the Vertex AI client, specifies the source model (gemini-1.0-pro-002), points to our training data in GCS, and sets various training parameters such as the number of epochs and learning rate multiplier.

It’s important to note that while we initiated the tuning job from our notebook, the actual training process was executed on GCP’s infrastructure, leveraging its powerful computational resources.

Training Summary

The fine-tuning process for our model was both efficient and cost-effective. The entire tuning job took approximately 1 hour and 23 minutes, running from 11:43:17 AM to 1:06:33 PM on September 23, 2024. This relatively short training time, combined with GCP’s competitive pricing for AI/ML workloads.

Model Output Comparison

To evaluate the effectiveness of our fine-tuned model, we utilized the Vertex AI GUI interface to compare its output with that of the original, non-tuned Gemini-1.0-pro-002 model. This approach allowed us to directly assess both models in the same environment, ensuring a fair comparison.

We used identical settings for both models and provided them with the same prompt to create an ad for a reproductive rights march. The GUI interface provided a straightforward way to input our prompt and view the outputs side by side.

Prompt:

You are a member of the Planned Parenthood Action social media team. Create a Facebook ad calling on supporters to participate in an upcoming march for reproductive rights. The ad should:
1. Emphasize the importance of participation
2. Mention current challenges to reproductive rights
3. Include a short, powerful slogan
4. Provide brief information on how to participate
Ensure the tone is firm but not overly confrontational, and reflect the values of Planned Parenthood Action.

Fine tuned model outputs:

Un-tuned Gemini-1.0-pro-002

The fine-tuned model demonstrated several key improvements:

  1. Greater specificity in details (e.g., exact date and location)
  2. More organization-specific language and calls to action
  3. Improved structure and formatting typical of Planned Parenthood Action’s ads
  4. Better alignment with the organization’s tone and messaging priorities

These differences highlight the success of our fine-tuning process in capturing the unique characteristics of Planned Parenthood Action’s advertising style.

Deploy the Model

After the fine-tuning process, our customized model was automatically stored in the Vertex AI Model Registry. This centralized repository ensures easy access and management of our fine-tuned model for future use.

For those looking to utilize this model in production environments, Vertex AI offers the capability to deploy the fine-tuned model as an endpoint. This deployment allows for seamless integration into various applications and workflows, enabling real-time inference and scalable usage of the model.

By deploying the model as an endpoint, users can make API calls to generate ad copy that aligns with Planned Parenthood Action’s style, streamlining the content creation process while maintaining brand consistency.

Conclusion

This proof of concept demonstrates the powerful potential of fine-tuning large language models for specific marketing needs. By training Gemini-1.0-pro-002 on a focused dataset of Planned Parenthood Action ads, we created a specialized AI capable of generating ad copy that closely mimics the organization’s style and messaging.

The results show that fine-tuned models can offer significant advantages in maintaining brand consistency and capturing nuanced communication styles. This approach opens up exciting possibilities for marketers looking to leverage AI while preserving their brand’s unique voice.

However, it’s important to note that while fine-tuning improves specificity, it may also introduce some limitations in flexibility. Future work could explore balancing specialized knowledge with broader capabilities to create even more versatile marketing AI assistants.

--

--