95+ Best Free Lightroom Presets 2025

Featured Imgs 23

Adobe Lightroom is one of the most useful tools you can use to optimize your photos and graphics. Whether you’re a beginner or a pro, it has features suitable for everyone.

What makes Lightroom more powerful is its ability to extend its features with third-party presets. These presets allow you to instantly apply effects, enhance photos, adjust tone and mood, and much with just a few clicks.

Finding amazing Lightroom presets is not difficult. There are plenty available on platforms like Envato Elements. But, for those of you who are on a tight budget and can’t afford premium presets, we made this list of best free Lightroom presets you can download and use to enhance all kinds of photos.

Just looking for a stylish free Lightroom preset? No problem. Let’s dive into our collection of the best free Lightroom presets of 2021!

What Type of Free Preset Do You Need?

We’ve broken our collection down into different categories, so you can quickly find just the right preset for your project! Almost of all of these Lightroom presets are free, but at the start of each section you’ll see one or two premium ones, just so you have that option to choose as well.

Portrait Lightroom Presets

Free Saturation Lightroom Preset

Free Saturation Lightroom Preset

This free Lightroom preset is a must-have for enhancing and improving your portrait photos. It’s especially a great option for adding a professional look to your smartphone selfies before uploading them to social media.

Free Matte Effect Lightroom Preset

Free Matte Effect Lightroom Preset

If you prefer matte-style effects, this free Lightroom preset is perfect for you. It features a subtle matte effect that adds a specific look to your portrait photos. You can use it with both indoor and outdoor photos.

Free Retro Effect Lightroom Preset

Free Retro Effect Lightroom Preset

This preset is for transforming your portrait photos with a classic and retro look. It works with all types of portrait photos and adds a subtle matte effect as well. The preset is easily customizable to your preference.

Free Old Style Lightroom Preset

Free Old Style Lightroom Preset

Another great free Lightroom preset for portrait photos. This free preset adds a vintage, old-school film look to your photos. It will also enhance colors and exposure to give your photos a professional look.

Free Wind Portrait Lightroom Preset

Free Wind Portrait Lightroom Preset

You can use this free Lightroom preset to fix and improve your outdoor portrait photos. It works especially well for photos shot in bright and sunny conditions by adjusting light and exposure to make the photo much more clearly visible.

14 Lightroom Presets for Portraits

14 Lightroom Presets for Portraits

This is a bundle of 14 unique Lightroom presets featuring optimizations and effects specifically made for improving portrait photos. Each preset works with different types of portraits including family, newborn, wedding portraits and more. The presets are non-destructive and work with Lightroom 4 and higher as well as the mobile version.

Slide Film – Free Lightroom Preset

Slide Film - Free Lightroom Preset

Make your photos and selfies look much more colorful and vibrant with this free Lightroom preset. It features a simple effect that enhances colors, highlights, and exposure to make your photos look much more attractive.

Trendy – Free Lightroom Preset

Trendy - Free Lightroom Preset

This Lightroom preset is ideal for improving Instagram photos as it comes with a trendy effect for portrait photos. It creates a subtle light and airy look for your photos to give them a modern aesthetic feel.

Drama Queen – Free Portrait Lightroom Preset

Drama Queen - Free Portrait Lightroom Preset

This free Lightroom preset is perfect for applying a subtle effect to make your portraits look more professional. It creates a smooth and moody effect that will make your Instagram selfies and portraits stand out from the crowd.

Magic Moments – Free Lightroom Preset for Portraits

Magic Moments - Free Lightroom Preset for Portraits

This Lightroom preset is a great choice for enhancing your family portraits and outdoor photos. It comes with a simple filter that gives a classic and nostalgic feel to your family vacation and trip photos.

Free Lightroom Presets for Portraits

Free Lightroom Presets for Portraits

This is a bundle of free Lightroom presets designed to improve portrait photos. It includes 10 different presets featuring various styles of effects, including vintage, black and white, toning, and more.

Vogue – Free Mobile & Desktop Lightroom Preset

Vogue - Free Mobile & Desktop Lightroom Preset

Vogue is a stylish free Lightroom preset designed for optimizing fashion and lifestyle photos. The preset is fully compatible with both desktop and mobile versions of the Lightroom app.

Free Retro Style Lightroom Preset

Free Retro Style Lightroom Preset

Instantly give a cool retro look and feel to your photos using this creative free Lightroom preset. This effect works well with outdoor portrait and landscape photos.

Vintage Vixen – Free Portrait Lightroom Preset

Vintage Vixen - Free Portrait Lightroom Preset

This free Lightroom preset can be used to enhance and optimize your selfies and portraits. It’s especially more suitable for improving photos for social media.

Contrast Darks – Free Portrait Lightroom Preset

Contrast Darks - Free Portrait Lightroom Preset

As the name suggests, this preset optimizes the contrast of your portrait photos to highlight the colors and brighten up the overall look. It’s ideal for optimizing outdoor portrait photos.

Wonderland Pro – Free Portrait Lightroom Preset

Wonderland Pro - Free Portrait Photoshop Action

This free preset features a unique filter that enhances exposure and lighting to bring the best features out of your portrait photos. It’s free to download and comes in Photoshop actions format too.

Hollywood – Free Portrait Lightroom Preset

Hollywood - Free Portrait Lightroom Preset

This free preset allows you to enhance your portrait photos by giving them a Hollywood look. Basically, your portraits will look like a scene from a movie after using this preset.

Lips of Wine – Free Portrait Lightroom Preset

Lips of Wine - Free Portrait Lightroom Preset

Another great free Lightroom presets that’s most suitable for improving outdoor photos. The preset adds a warm color toning effect to your photos make them look more attractive.

Fantasy – Free Mobile & Desktop Lightroom Preset

Fantasy - Free Mobile & Desktop Lightroom Preset

This free Lightroom preset will instantly make your ordinary portrait photos look more like a scene from a fantasy movie. It features a professional color toning effect that gives photos a fantasy-like look and feel. The preset works with both desktop and mobile Lightroom apps as well.

Orange And Teal – Free Lightroom Preset

Orange And Teal - Free Lightroom Preset

Another professional Lightroom preset that allows you to easily enhance the colors of your photos to make them look more vibrant and beautiful. This preset is free to download and use with your personal projects.

Vibrant – Mobile & Desktop Lightroom Preset

Vibrant Mobile & Desktop Lightroom Preset

If you’re looking for a professional Lightroom preset to enhance our portrait photos for social media, this free Lightroom preset will come in handy. It will allow you to easily optimize all kinds of portrait photos, including indoor, outdoor, and fashion photos.

Night Life – Free Mobile & Desktop Lightroom Preset

Night Life - Free Mobile & Desktop Lightroom Preset

You can use this free Lightroom preset to optimize your portraits and landscape photos taken during night time. The preset will help enhance photos taken in low-light conditions while adding a warm color tone.

Film Look Free Lightroom Presets

Film Look Free Lightroom Presets

Film look is a set of free Lightroom presets that allows you to apply a unique effect to your photos to make them look more attractive. It includes 3 different effects that are compatible with Lightroom and Photoshop Camera Raw.

20 Free Glowing Summer Lightroom Presets

20 Free Glowing Summer Lightroom Presets

This bundle of Lightroom presets includes 20 different effects for giving a stylish summer-like look and feel to your photos. All of the effects work with both JPEG and RAW file formats.

Free Lomo Effect Lightroom Presets

Free Lomo Effect Lightroom Presets

If you’re looking for a effect to make your photos more bright and vibrant with colors, this Lightroom preset will come in handy. The bundle includes 20 different effects with various styles. It’s perfect for portraits and landscape photos.

30 Free Duotone Lightroom Presets

30 Free Duotone Lightroom Presets

The duotone effect is quite useful in giving your ordinary photos a more artistic look. This bundle comes with 30 different Lightroom presets with different styles of duotone effects you can use to enhance all kinds of photos.

Moody – Free Lightroom Preset

Moody - Free Lightroom Preset

This is a unique low contrast Lightroom preset that allows you to instantly optimize the tone and mood of your photos with a matte effect. The effect is perfect for outdoor portrait photos.

20 Free Matte Lightroom Presets

20 Free Matte Lightroom Presets

A collection of 20 different Lightroom presets featuring matte color effects. These Lightroom presets can be used to improve your portrait photos, including wedding photography.

Outdoor Lightroom Presets

50 Outdoor Lightroom Presets

50 Wanderlust Landscape Lightroom Presets

This is a collection of 50 different Lightroom presets that features various effects and filters you can use with your outdoor landscape photography. The pack includes vintage-themed effects as well as filters that will make the colors pop. They are compatible with both desktop and mobile versions of the app.

Wildlife – Free Lightroom Preset

Wildlife - Free Lightroom Preset

You can use this free Lightroom preset to easily enhance your outdoor wildlife photography. It has a sophisticated effect that improves colors and lighting to give a professional look to your photos.

Autumn Vintage – Free Lightroom Preset

Autumn Vintage - Free Lightroom Preset

This free Lightroom preset instantly adds a moody Autumn look to your outdoor photography. It combines the fall Autumn vibe with a vintage filter to create a unique look unlike any other on our list.

SX-7000 – Free Outdoor Lightroom Preset

SX-7000 - Free Outdoor Lightroom Preset

If you want to add a dark and moody look to your outdoor photos, this Lightroom preset will come in handy. It features a strong effect inspired by analog film cameras that gives a polaroid look to your photos.

Ektar 100 – Free Outdoor Lightroom Preset

Ektar 100 - Free Outdoor Lightroom Preset

This preset is perfect for optimizing the colors of your outdoor photos. It enhances saturation and temperature to make photos look more colorful while giving a film look.

Old Gloomy Film – Free Outdoor Lightroom Preset

Old Gloomy Film - Free Outdoor Lightroom Preset

Give your outdoor photos an old-school vintage film look and feel using this free preset. It features a vintage effect that mimics the look of old lomo cameras.

Scenic Color – Free Outdoor Lightroom Preset

Scenic Color - Free Outdoor Lightroom Preset

This free preset will come in handy for brightening up those outdoor photos you take under gloomy light conditions. The preset can be easily adjusted to your preference as well.

Free Outdoor Lightroom Preset

Free Outdoor Lightroom Presets

This free Lightroom preset is perfect for making your photos look more colorful and vibrant. The effect enhances colors to give a summer-like feel and you can easily customize it to your preference as well. The preset works with Lightroom 4 and higher.

Aqua – Free Outdoor Lightroom Preset

Aqua - Free Outdoor Lightroom Preset

Aqua is a free Lightroom preset that’s ideal for enhancing your outdoor photography. This preset will enhance and improve the colors of your photos to make them more vibrant.

Fuji Provia – Free Outdoor Lightroom Preset

Fuji Provia - Free Outdoor Lightroom Preset

Fuji Provia is a simple Lightroom preset you can use to improve outdoor photos. It’s especially great for adjusting the lighting of photos shot in low-light conditions.

FilmStreet – Free Outdoor Lightroom Presets

Free FilmStreet Lightroom Presets

While this set of Lightroom presets are designed for night time photography, they are also perfect for improving outdoor and landscape photos as well, especially cityscape photos.

Bali – Free Mobile & Desktop Lightroom Preset

Bali Mobile & Desktop Lightroom Preset

This amazing free Lightroom preset is designed inspired by the warm and beautiful beaches of Bali. It is fully optimized to enhance the colors and the contrast of your travel photos.

Free Vibrant Colors HDR Lightroom Preset

Free Vibrant Colors HDR Lightroom Preset

This is a premium quality Lightroom preset that allows you to give an HDR look and feel to your ordinary photos. The preset is easily customizable and works with most outdoor landscape photos.

Free Beach Lightroom Presets

Free Beach Lightroom Presets

This Lightroom preset is specially designed for optimizing and enhancing your beach photography. They will also work well with landscape photos and outdoor travel photos taken in bright light conditions.

Popper – Free Lightroom Preset & Action

Popper - Free Lightroom Preset & Action

Popper is a Lightroom preset you can use to optimize your portrait and landscape photos taken in outdoor light conditions. It includes both a Lightroom preset and a Photoshop action.

NY Skyline – Free Outdoor Lightroom Presets

NY Skyline - Free Outdoor Lightroom Presets

Improve your night-time outdoor photos using this free Lightroom preset. It comes with an easily editable effect you can customize to match different types of landscape photos.

Free Outdoor Portrait Effect Lightroom Presets

Free Outdoor Portrait Effect Lightroom Presets

This is a collection of Lightroom presets featuring various kinds of effects you can use with your outdoor portrait photos. The bundle comes with 30 different presets with various effects.

Landscape Lightroom Presets

100 Landscape Lightroom Presets Pack

100 Landscape Lightroom Presets Pack

A massive bundle of 100 creative Lightroom presets for optimizing your landscape photos. This pack comes with various styles of filters and effects for enhancing nature and outdoor photos. The presets are compatible with Lightroom 4 and higher.

Birds Eye – Free Lightroom Landscape Preset

Birds Eye - Free Lightroom Landscape Preset

Enhance your landscape and birds-eye photos with this free Lightroom preset. It features a colorful and smooth effect that will make your photos more vibrant and attractive.

Abstract Landscape Lightroom Presets

lightroom presets

Inside the pack, you’ll receive a range of Lightroom presets and LUT’s that will convert your pictures into something truly ethereal. With the help of this collection, you can make lush green jungles appear blue, pink, yellow, or red in just a few easy clicks.

Adventure – Free Landscape Lightroom Preset

Adventure - Free Landscape Lightroom Preset

This preset allows you to give a clean and washed-out look to your landscape photos. It gives a moody look to your photos by suppressing colors.

Gypsy Soul – Free Landscape Lightroom Preset

Gypsy Soul - Free Landscape Lightroom Preset

A must-have Lightroom preset for travel photographers. This preset lets you apply a colorful effect to give a tropical look to your landscape photos.

Guava Jelly – Free Landscape Lightroom Preset

Guava Jelly - Free Landscape Lightroom Preset

Add a stylish pastel color effect to give a nostalgic and retro feel to your landscape photos using this free Lightroom preset.

Downtown Alley – Free Landscape Lightroom Preset

Downtown Alley - Free Landscape Lightroom Preset

Another professional free Lightroom presets most suitable for enhancing outdoor landscape and cityscape photos.

Moscow – Travel Mobile & Desktop Lightroom Preset

Moscow Travel Mobile & Desktop Lightroom Preset

This free Lightroom preset is designed to optimize travel and outdoor photos. The preset is perfect for enhancing photos for Instagram and social media. You can also adjust the effect to your preference.

Landscape Photography Free Lightroom Preset

Landscape Photography Free Lightroom Preset

Another free Lightroom preset for enhancing your landscape photos. It will enhance colors and shapen the photos to make more professional. The preset works with Lightroom 4 and higher.

Vast Landscapes – Free Lightroom Preset 

Vast Landscapes - Free Lightroom Preset

This landscape Lightroom preset is perfect for optimizing your nature, outdoor, and landscape photos. The preset features color optimization effects to give your photos a professional look.

Dawning – Free Landscape Lightroom Preset

Dawning - Free Landscape Lightroom Preset

Dawning is a free Lightroom preset you can use to enhance outdoor landscape photos. The preset is ideal for photos taken under natural sunlight and it helps enhance saturation as well.

Cinematic Landscape Lightroom Preset

Cinematic Landscape Lightroom Preset

Add a creative cinematic effect to your landscape photos using this free Lightroom preset. The free preset can be easily adjusted to your preference as well.

Free Matte Lightroom Preset

Free Matte Lightroom Preset

This free Lightroom preset is designed for improving your outdoor landscape photos. It features a light matte color effect. The preset works with Lightroom 4 or higher.

Free Cinema Lightroom Preset

Free Cinema Lightroom Preset

Another Lightroom preset for optimizing the tone and mood of your landscape photos. This preset features a stylish film-inspired effect.

Free Light Leak Lightroom Preset

Free Light Leak Lightroom Preset

Adding light leaks to outdoor landscape photos can instantly make your photos more attractive. Use this free Lightroom preset to add light leaks without a hassle.

Free Color Pop Lightroom Preset

Free Color Pop Lightroom Preset

This free Lightroom preset allows you to adjust the brightness and colors of your photos to make it look more vibrant and attractive. It’s most suitable for photos taken in low light and weather conditions.

Wedding Lightroom Presets

Rustic Wedding – 50 Lightroom Wedding Presets

Rustic Wedding - 50 Lightroom Wedding Presets

Wedding photos come in many different styles and themes. This is a massive bundle of Lightroom presets designed to handle all types of wedding photos. This pack includes 50 different Lightroom presets optimized to improve wedding photos shot in all kinds of lighting conditions and designed to add natural toning effects.

Honeymoon – Free Wedding Lightroom Wedding Preset

Honeymoon - Free Wedding Lightroom Wedding Preset

This free Lightroom preset is ideal for enhancing outdoor wedding photos. It features a simple effect that fixes lighting and improves photos with proper color correction.

Provence – Lightroom Wedding Presets

lightroom presets

If you are wanting to transform your wedding, honeymoon, romantic, or engagement photos into a magical dream, look no further than this bundle of twenty Lightroom presets. It’s one of our most favorite options on this list, and for a good reason.

Retro Wedding – Free Wedding Lightroom Preset

Retro Wedding - Free Wedding Lightroom Preset

A creative Lightroom preset that’s ideal for giving an old-school and vintage look to your wedding photos. The sepia look of this preset is fully customizable as well.

Caramel Wedding – Free Lightroom Preset

Free Caramel Wedding Mobile & Desktop Lightroom Preset

This beautiful free Lightroom preset is perfect for improving your wedding and fashion photos. The effect is easily adjustable to your preference and it’s also available in Photoshop action format.

Matte Film – Free Wedding Lightroom Preset

Free Lightroom Preset Matte Film Presetpro.com

Add a beautiful rustic look and feel to your wedding photography with this free Lightroom preset. It features a minimalist effect that will make your photos look much more professional and elegant.

10 Free Beautiful Wedding Lightroom Presets

10 Free Beautiful Wedding Lightroom Presets

This is a collection of free Lightroom presets you can use to enhance wedding photos. There are 10 different presets in this pack that are suitable for both indoor and outdoor photos.

Anniversary – Free Mobile & Desktop Lightroom Preset

Anniversary - Free Mobile & Desktop Lightroom Preset

Optimizing your various wedding and anniversary photos will get so much easier with this professional and free Lightroom preset. This preset optimizes the contrast and adds beautiful color tones to your photos to make them look even more professional.

Summer Wedding – Free Lightroom Preset

Summer Wedding - Free Lightroom Preset

This free Lightroom preset is perfect for enhancing your wedding photos taken in outdoors. The preset allows you to optimize color and contrast as the effect can be easily customized to your preference.

Pastel Free Wedding Lightroom Preset

Pastel Free Wedding Lightroom Preset

Adding pastel color tones is a popular trend in wedding photography. This Lightroom preset features an easily customizable effect you can use to add color tones and various adjustments to your wedding photos.

Free Wedding Photography Lightroom Preset

Free Wedding Photography Lightroom Preset

This free Lightroom preset includes a beautiful effect that will give a dreamy look and feel to your wedding photos. It also includes all the necessary adjustments and improvements for enhancing the mood of the photos as well.

The Bouquet – Free Wedding Lightroom Preset

The Bouquet - Free Wedding Lightroom Preset

The Bouquet is a free Lightroom preset specially designed for enhancing wedding photos. This preset will work better with photos taken outdoors and in natural light conditions.

Free Lightroom Preset Elegant Wedding

Free Lightroom Preset Elegant Wedding

Another free Lightroom preset you can use to instantly adjust the lighting and colors of your wedding photos taken in low light conditions.

Cold Wind – Free Wedding Lightroom Preset

Cold Wind - Free Wedding Lightroom Preset

Cold Wind is a free Lightroom preset designed to optimize the contrast and the toning of your wedding photos to make them more vibrant and attractive.

Sweet Tones Free Lightroom Presets

Sweet Tones Free Lightroom Presets

This is a collection of free Lightroom presets that features matte color effects for improving all kinds of portrait and landscape photos, especially including wedding photos. These presets work with both the Lightroom desktop and mobile apps as well.

Black and White Lightroom Presets

Blacktone Black & White Lightroom Presets

Blacktone Black & White Lightroom Presets

Speed up your workflow with this collection of ten black and white Lightroom presets, each working to give a unique effect to your pictures, and make them stand out in the daily flood of photos we see on various social media platforms.

Free Lightroom Presets For Black & White Landscapes

free lightroom presets

Check out this collection of free Lightroom presets that will transform your dull, and boring pictures into high-contrast, appealing monochrome masterpieces in no time at all. It’s a great resource perfectly suited for coastal, forest, and mountain landscape shots with a cloudy, smoky, or foggy backdrop.

Free B & W Lightroom Presets

free lightroom presets

If you are looking for a massive collection of free Lightroom presets that convert your pictures into a monochromatic dream, this option featuring 100 plus non-destructive, high-quality conversions is right up your alley.

Dark Desire – Free Monochrome Lightroom Preset

Dark Desire - Free Monochrome Lightroom Preset

This is a unique Lightroom preset that features a creative monochromatic look. It creates a black-and-white effect mixed with small amounts of colors. You can download it for free to experiment with the effect.

B&W Infrared – Free Black & White Lightroom Preset

B&W Infrared - Free Black & White Lightroom Preset

This free preset allows you to give the popular black and white infrared look to your ordinary photos. The preset lets you create a deep toning effect to make your B&W photography stand out.

Detailed Matte – Free Black & White Lightroom Preset

Detailed Matte - Free Black & White Lightroom Preset

This is unique Lightroom preset that combines the monochromatic look with the matte effect to create a very attractive look for abstract photos. The preset is easily customizable as well.

Silver Surfer – Free B&W Lightroom Preset

Silver Surfer - Free B&W Lightroom Preset

This free black and white Lightroom presets works well with all types of photos, including outdoor, portraits, and landscape photos.

Free High Contrast Black & White Lightroom Preset

Free High Contrast Black & White Lightroom Preset

Not everyone can create a perfect black and white effect. It takes more work than just applying a greyscale filter. But with this Lightroom preset, you’ll be able to apply an authentic B&W effect without an effort.

B&W Berkeley – Vintage Lightroom Preset

B&W Berkeley - Vintage Lightroom Preset

This is a free Lightroom preset that lets you create a vintage-themed black and white effect to give an old-school look and feel to your photos.

Black & White HDR Lightroom Preset

Black & White HDR Lightroom Preset

Another high-quality black and white Lightroom preset. This preset will not only transform your photos into work of art with a B&W effect but it will also add a stylish HDR effect to make the photo look more attractive.

Free Monochrome Lightroom Preset

Free Monochrome Lightroom Preset

Newborn Lightroom Presets

Free Newborn Lightroom Presets For Photographers

free lightroom presets

This newborn baby Lightroom preset works on enhancing and smoothening the harsh tones making your baby pictures as soft as your little bundle of joy. It’s very easy to use and customize letting you focus more on shooting and less on editing.

Free Newborn Baby Lightroom Preset

Free Newborn Baby Lightroom Preset

Make the adorable photos of your baby look even cuter with this free Lightroom preset. It can be applied to your photos with just one-click to make them look warm and colorful. The preset works with Lightroom 4 and higher.

New Life – Free Newborn Lightroom Preset

New Life - Free Newborn Lightroom Preset

This free Lightroom preset is designed to highlight and improve the smooth baby skin with a subtle pink color tone. It’s perfect for improving photos taken in bad lighting conditions.

Newborn – Free Lightroom Preset

Newborn - Free Lightroom Preset

You can use this free Lightroom preset to enhance the lighting and contrast of your cute baby photos. The preset only does subtle improvements to preserve the original look of the photo. And you can easily adjust its settings as well.

Free Vibrant Lightroom Presets

free lightroom presets

If you want to make your photos more vibrant and colorful, this pack of free Lightroom presets is a must-have for you. It includes a set of simple presets that instantly enhance and improve the colors of photos.

Free Cinematic Lightroom Presets

free lightroom presets

This collection includes 8 amazing Lightroom presets that add a stylish cinematic look and feel to your photos. It works well with both portrait and landscape photography. You can completely transform your photos with these effects.

Free Food Photography Lightroom Preset

free lightroom presets

Want to make your Instagram food photos look tastier? Then be sure to download this free Lightroom preset. It quickly enhances your food photos to make them look more colorful and delicious.

Free FujiColor 400 N Lightroom Preset

free lightroom presets

This Lightroom preset comes with an effect inspired by the FujiColor 400 photography. It simply adds a classic film look to your photos to give them a retro nostalgic feel.

Free Travel Lightroom Presets

free lightroom presets

Be sure to download this Lightroom presets pack as it comes with 14 different effects. They are perfect for enhancing your travel and outdoor photos. The effects will especially help add a moody look to your nature photos.

This free Lightroom preset creates a professional black and white effect by optimizing the contrast of your images. The effect will work with most portrait and landscape photos.

Fine-tuning OpenAI GPT-4o for Multi-label Text Classification

Featured Imgs 23

In my previous article, I presented a comparison of GPT-4o and Claude 3.5 Sonnet for multi-label text classification. The accuracies achieved by both models were relatively low.

Fine-tuning is one solution to overcome the low performance of large-language models. With fine-tuning, you can incorporate custom domain knowledge into an LLM's weights, leading to better performance on your custom dataset.

This article will show how to fine-tune the OpenAI GPT-4o model on the multi-label research paper classification dataset. It is the same dataset I used for zero-shot multi-label classification in my previous article. You will see significantly better results with the fine-tuned GPT-4o model.

So, let's begin without ado.

Importing and Installing Required Libraries

We will fine-tune the OpenAI GPT-4o model using the OpenAI API in Python. The following script installs the OpenAI Python library.


!pip install openai

The script below imports the required libraries into your Python application.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from itertools import combinations
from collections import Counter
from sklearn.metrics import hamming_loss, accuracy_score
import json
import os
from openai import OpenAI
Importing and Preprocessing the Dataset

We will fine-tune the GPT-4o model using the same multi-label research paper classification dataset we used in the last article.

The following script imports the dataset into a Pandas dataframe and displays the dataset header.

## dataset download link
## https://www.kaggle.com/datasets/shivanandmn/multilabel-classification-dataset?select=train.csv

dataset = pd.read_csv(r"D:\Datasets\Multilabel Research Paper Classification\train.csv")
print(f"Dataset Shape: {dataset.shape}")
dataset.head()

Output:

img1.png

The dataset has nine columns. The ID column holds the paper ID, while the TITLE and ABSTRACT columns store the titles and abstracts of the research papers. In the remaining columns, a one indicates that the paper falls under that category, while a zero shows it does not.

We will filter the papers that belong to at least two categories, as our goal is to conduct multi-label classification.


subjects = ["Computer Science", "Physics", "Mathematics", "Statistics", "Quantitative Biology", "Quantitative Finance"]
filtered_dataset = dataset[(dataset[subjects] == 1).sum(axis=1) >= 2]
print(f"Filtered Dataset Shape: {filtered_dataset.shape}")
filtered_dataset.head()

Output:

img2.png

We will fine-tune the GPT-4o model on the first 100 records in our dataset. At the same time, the test set will contain 100 randomly selected records with the random_state = 42 so that we have the same test dataset as in the previous article.


train_dataset = filtered_dataset.iloc[:100]  # First 100 records for training
test_dataset = filtered_dataset.sample(n=100, random_state=42)  # randomly selecting 100 records for testing

# Display the shapes of the resulting datasets
print(f"Training Dataset Shape: {train_dataset.shape}")
print(f"Testing Dataset Shape: {test_dataset.shape}")

Output:

Training Dataset Shape: (100, 9)
Testing Dataset Shape: (100, 9)
Creating a Training File for OpenAI Fine Tuning

You must convert your dataset into multi-line JSON format for OpenAI model fine-tuning. Each line should contain data like this as per the OpenAI official documentation.

{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "How far is the Moon from Earth?"}, {"role": "assistant", "content": "Around 384,400 kilometers. Give or take a few, like that really matters."}]}

We will convert our dataset into the above format. The system content will contain the system instructions. We will use the same instructions as we used in the previous article. The user content will contain the research paper title and abstract. Finally we store the desired output i.e. the research paper categories in a comma-separated list in the assistant content.

The following script converts our training dataframe into the JSON file we will use for model fine-tuning.



# Initialize list to hold JSON-like strings
json_lines = []

# Template for system role content
system_content = (
    "You are an expert in various scientific domains.\n"
    "Given the following research paper title and abstract, classify the research paper into at least two or more of the following categories:\n"
    "- Computer Science\n"
    "- Physics\n"
    "- Mathematics\n"
    "- Statistics\n"
    "- Quantitative Biology\n"
    "- Quantitative Finance\n\n"
    "Return only a comma-separated list of the categories (e.g., [Computer Science,Physics] or [Computer Science,Physics,Mathematics]).\n"
    "Use the exact case sensitivity and spelling of the categories provided above."
)

# Loop through each row in the DataFrame
for _, row in train_dataset.iterrows():
    # Identify the categories with a value of 1 and reverse the list
    categories = [
        subject for subject in ["Computer Science", "Physics", "Mathematics", "Statistics", "Quantitative Biology", "Quantitative Finance"]
        if row[subject] == 1
    ][::-1]  # Reverse the order of categories

    # Create JSON structure for each row
    json_record = {
        "messages": [
            {"role": "system", "content": system_content},
            {"role": "user", "content": f"Title: {row['TITLE']}\nAbstract: {row['ABSTRACT']}"},
            {"role": "assistant", "content": f"[{','.join(categories)}]"}
        ]
    }
    # Convert to JSON string and add to list
    json_lines.append(json.dumps(json_record))

# Join all JSON strings with newline separators for the final output
final_output = "\n".join(json_lines)

The following script saves the JSON file.


# Save the JSON records to 'train.json'

training_file_path = r"D:\Datasets\Multilabel Research Paper Classification\train.json"

with open(training_file_path, 'w') as file:
    file.write(final_output)

print("Data successfully saved to 'train.json'")

We need to upload the JSON training file to OpenAI servers for fine-tuning. The following script uploads the file.


client = OpenAI(
    # This is the default and can be omitted
    api_key = os.environ.get('OPENAI_API_KEY'),
)


training_file = client.files.create(
  file=open(training_file_path, "rb"),
  purpose="fine-tune"
)

print(training_file.id)
Fine-tuning GPT-4o Model

We are now ready to fine-tune the GPT-4o model on our training file.
To do so, call the fine_tuning.jobs.create() method and pass it the training file ID and the model ID of the model you want to fine-tune.


fine_tuning_job_gpt4o = client.fine_tuning.jobs.create(
  training_file=training_file.id,
  model="gpt-4o-2024-08-06"
)

You can see the model fine-tuning events using the script below:


# List up to 10 events from a fine-tuning job
print(client.fine_tuning.jobs.list_events(fine_tuning_job_id = fine_tuning_job_gpt4o.id,
                                    limit=10))

Once the model is fine-tuned, you will receive an email from OpenAI containing your fine-tuned model ID. Alternatively, you can use the following script to retrieve the ID of your fine-tuned model.


ft_model_id = client.fine_tuning.jobs.retrieve(fine_tuning_job_gpt4o.id).fine_tuned_model
Predicting Research Paper Category with Fine-tuned GPT-4o

The rest of the same as explained in the previous article.

We will define the find_research_category() function, which accepts the OpenAI API client, the fine-tuned model ID, and the test dataset as parameters.

Within this function, we iterate through each row, extracting the title and abstract of each paper. Then, we will define the same system prompt as we used for training to instruct the fine-tuned models to classify each paper into two or more of the predefined subject categories.


def find_research_category(client, model, dataset):

    outputs = []
    i = 0

    for _, row in dataset.iterrows():
        title = row['TITLE']
        abstract = row['ABSTRACT']

        content = """You are an expert in various scientific domains.
                     Given the following research paper title and abstract, classify the research paper into at least two or more of the following categories:
                    - Computer Science
                    - Physics
                    - Mathematics
                    - Statistics
                    - Quantitative Biology
                    - Quantitative Finance

                    Return only a comma-separated list of the categories (e.g., [Computer Science,Physics] or [Computer Science,Physics,Mathematics]).
                    Use the exact case sensitivity and spelling of the categories provided above.

                    text: Title: {}\nAbstract: {}""".format(title, abstract)


        research_category = client.chat.completions.create(
                                model= model,
                                temperature = 0,
                                max_tokens = 100,
                                messages=[
                                      {"role": "user", "content": content}
                                  ]
                              ).choices[0].message.content


        outputs.append(research_category)
        print(i + 1, research_category)
        i += 1

    return outputs

The find_research_category() function returns a list of lists, with each internal list containing a comma-separated list of predicted categories for a paper. We will convert these subject categories into a Pandas dataframe using the parse_outputs_to_dataframe() function, allowing us to compare the model outputs against the target labels.


def parse_outputs_to_dataframe(outputs):

    subjects = ["Computer Science", "Physics", "Mathematics", "Statistics", "Quantitative Biology", "Quantitative Finance"]
    # Remove square brackets and split the subjects for each entry in outputs
    parsed_data = [item.strip('[]').split(',') for item in outputs]

    # Create an empty DataFrame with columns for each subject, initializing with 0s
    df = pd.DataFrame(0, index=range(len(parsed_data)), columns=subjects)

    # Populate the DataFrame with 1s based on the presence of each subject in each row
    for i, subjects_list in enumerate(parsed_data):
        for subject in subjects_list:
            if subject in subjects:
                df.loc[i, subject] = 1

    return df

Next, we call the find_research_category() function with the OpenAI client object, the fine-tuned model ID, and the test dataset.


model = ft_model_id
outputs = find_research_category(client,
                                 model,
                                 test_dataset)

Output:

img3.png

We will convert model predictions into Pandas dataframe using the parse_outputs_to_dataframe() function.

Finally, we calculate the hamming loss and the model accuracy for the predictions on the test set.


predictions = parse_outputs_to_dataframe(outputs)
targets = test_dataset[subjects]

# Calculate Hamming Loss
hamming = hamming_loss(targets, predictions)
print(f"Hamming Loss: {hamming}")

# Calculate Subset Accuracy (Exact Match Ratio)
subset_accuracy = accuracy_score(targets, predictions)
print(f"Subset Accuracy: {subset_accuracy}")

Output:


Hamming Loss: 0.09333333333333334
Subset Accuracy: 0.69

These results were achieved in the previous article using the default GPT-4o model.

Hamming Loss: 0.16
Subset Accuracy: 0.4

The above output shows that the fine-tuned GPT-4o model performs significantly better than the default model. The hamming loss score of 0.09 shows that only 9% of the labels for each record were incorrectly predicted, compared to 16% of incorrect labels predicted by the default GPT-4o.

Similarly, fine-tuned GPT-4o achieves a subset accuracy of 69% compared to 40% achieved by the default GPT-4o model.

Conclusion

In this article, you saw how to fine-tune the GPT-4o model for multi-label text classification. The results show that with just 100 training examples, fine-tuned GPT-4o achieves 29% higher accuracy compared to the default GPT-4o model.

If you are receiving poor results on your dataset with default GPT-4o, I suggest fine-tuning it with around 100 examples. You will see a clear improvement in model performance.