Close Menu
MyAppsPlus

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Google confirms something was draining Pixel Watch batteries, fix rolling out

    November 3, 2026

    Save $120 on the Ceramic Midnight Oura Ring 4 in record-low deal

    November 3, 2026

    MacBook Neo, AirPods, Apple Watch, Beats 360, more 9to5Mac

    November 3, 2026
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    MyAppsPlusMyAppsPlus
    Tuesday, November 3
    • Home
    • Breaking Tech
    • Apps & Software
    • AI & Automation
    • Android
    • iPhone & iOS
    • More
      • Reviews
      • How-To Guides
      • Deals & Discounts
      • Shop
    MyAppsPlus
    Home»AI & Automation»Using LLM Summarization in Your Scikit-Learn Pipelines with Scikit-LLM
    AI & Automation

    Using LLM Summarization in Your Scikit-Learn Pipelines with Scikit-LLM

    myappsplusBy myappsplusNovember 3, 2026008 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    Using LLM Summarization in Your Scikit-Learn Pipelines with Scikit-LLM
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link

    Introduction

    Using traditional, lightweight machine learning classifiers on text frequently requires condensing lengthy, often noisy raw text into clean signals to succeed. Therefore, it wouldn’t be crazy to think of using a large language model (LLM) for text summarization as a preprocessing stage before feeding cleaner texts to the downstream classification model. What if we could do this seamlessly as part of a traditional, scikit-learn-based pipeline where LLM-driven summarization can coexist with traditional data preprocessing, training, and inference? And what if we could do all of this using exclusively free tools? Look no further.

    In this article, we will learn how to build an architecture that blends Scikit-LLM estimators for text summarization with traditional scikit-learn methods into a single, unified pipeline for summarizing and classifying raw, messy text, bringing together the best of both worlds: LLMs and classical machine learning models.

    Integrating LLM-Driven Summarization in a Machine Learning Pipeline

    This example can be run entirely in a Google Colab notebook. It uses Groq‘s LLM API to fully rely on free models. A prerequisite is to access the Groq website, register, and generate your own API key. Once it’s generated, carefully copy your API key (it is shown only once) and paste it as a new “Secret” variable in Google Colab, found at the key icon on the left-hand side of Colab. Name the secret variable GROQ_API_KEY.

    After that, we start our notebook by installing Scikit-LLM:

    !pip install scikit-llm -q

    Now, into the Python code. The first step is to configure the environment surrounding Scikit-LLM, routing our requests through Groq’s API instead of the default OpenAI API. This will help us leverage Groq’s free, friendly, and efficient pre-trained models, bypassing per-token costs.

    from google.colab import userdata
    from skllm.config import SKLLMConfig
    
    # Retrieving API key and routing to Groq's free-tier OpenAI-compatible endpoint
    groq_key = userdata.get('GROQ_API_KEY')
    SKLLMConfig.set_gpt_url("https://api.groq.com/openai/v1")
    SKLLMConfig.set_openai_key(groq_key)

    Next, we define the “training” data. It consists of a small set of initial documents along with their corresponding labels. The documents are intentionally lengthy, somewhat noisy, and verbose, just like in many real-world scenarios. Without a prior summarization to extract relevant signals from the text, directly obtaining numerical, machine learning-friendly representations from these texts would inevitably propagate the noise:

    # Raw, lengthy documents and their corresponding class labels
    X_long_texts = [
        "The new solar panel technology efficiency has increased by 15% due to the novel perovskite layer, significantly lowering the barrier to entry for residential use and driving green energy adoption by making installations cheaper and faster than ever before.",
        "Financial markets saw a sharp downturn today following the central bank's unexpected interest rate hike, leading to massive sell-offs in the tech sector and triggering volatility indices to reach their highest points in over three years.",
        "The clinical trial for the new arthritis medication showed promising results, reducing joint swelling by 40% in the control group without severe side effects, awaiting FDA approval which could bring relief to millions suffering from autoimmune disorders."
    ]
    
    y_labels = ["Energy", "Finance", "Healthcare"]

    Similar to few-shot classification, we only need a small, representative set of training examples to let the LLM we will load later know how to reason. No actual training of the LLM takes place.

    The next step is arguably the most critical: we are defining our three-step pipeline for machine learning-driven classification preceded by LLM-driven summarization, thereby integrating Scikit-LLM capabilities to accommodate specific tasks on pre-trained LLMs into a broader machine learning pipeline. The code below uses a GPTSummarizer object to encapsulate a compatible Groq model for summarization, namely openai/gpt-oss-20b. It then embeds the summarization step into the scikit-learn pipeline, followed by term frequency-inverse document frequency (TF-IDF) to obtain text representations of summarized texts rather than the original, lengthy ones. Finally, it defines and trains a logistic regression classifier using the label set defined before.

    from sklearn.pipeline import Pipeline
    from sklearn.feature_extraction.text import TfidfVectorizer
    from sklearn.linear_model import LogisticRegression
    from skllm.models.gpt.text2text.summarization import GPTSummarizer
    
    # THREE-STEP MACHINE LEARNING PIPELINE FOR TEXT CLASSIFICATION, PRECEDED BY SUMMARIZATION
    # 1. Summarizer: Condenses long documents using the compatible model on Groq
    # 2. Vectorizer: Converts the concise summaries into numerical TF-IDF vectors
    # 3. Classifier: Learns to classify the TF-IDF vectors using standard Logistic Regression
    text_pipeline = Pipeline([
        ('summarizer', GPTSummarizer(
            model="custom_url::openai/gpt-oss-20b",
            max_words=20
        )),
        ('vectorizer', TfidfVectorizer()),
        ('classifier', LogisticRegression())
    ])
    
    # Fitting the entire pipeline end-to-end
    text_pipeline.fit(X_long_texts, y_labels)

    You might be wondering why just three training instances in X_long_texts could be enough to train the last-stage logistic regression classifier. It’s not because the classifier has truly learned the broad concepts of ‘Energy’, ‘Finance’, and ‘Healthcare’. Instead, it succeeds due to two pipeline mechanics working in tandem: the LLM first acts as a precise filter that condenses noisy text into “canonical” keywords. After that, the downstream vectorizer naturally limits its whole vocabulary to those few remaining words, turning the classification task into a pretty easy, largely trivial keyword-matching game.

    Next, we take a look at the summaries produced for the three training examples to verify they make sense:

    # Inspecting the summaries of "training" examples, accessing the 'summarizer' object
    train_summaries = text_pipeline.named_steps['summarizer'].transform(X_long_texts)
    
    print("--- TRAINING DATA SUMMARIES ---")
    for label, original, summary in zip(y_labels, X_long_texts, train_summaries):
        print(f"[{label.upper()}]nOriginal: {original}nSummary:  {summary}n")
    --- TRAINING DATA SUMMARIES ---
    [ENERGY]
    Original: The new solar panel technology efficiency has increased by 15% due to the novel perovskite layer, significantly lowering the barrier to entry for residential use and driving green energy adoption...
    Summary:  New perovskite solar panels boost efficiency by 15%, reducing costs and accelerating residential green energy adoption.
    
    [FINANCE]
    Original: Financial markets saw a sharp downturn today following the central bank's unexpected interest rate hike, leading to massive sell-offs in the tech sector and triggering volatility indices...
    Summary:  Markets plunged after unexpected rate hike, causing tech sell‑offs and high volatility.
    
    [HEALTHCARE]
    Original: The clinical trial for the new arthritis medication showed promising results, reducing joint swelling by 40% in the control group without severe side effects, awaiting FDA approval...
    Summary:  New arthritis drug trial reduces swelling by 40% with no severe side effects, pending FDA approval.

    Since these summaries seem quite sensible, we can now finalize by creating some test examples and passing them entirely to the pipeline for classification

    X_new = [
        "A breakthrough mRNA vaccine targeting seasonal flu strains showed 85% efficacy across diverse patient demographics in stage 3 clinical trials, paving the way for a more robust global immune defense next winter.",
        "Researchers have developed a grid-scale sodium-ion battery that promises to store surplus wind and solar power at a fraction of lithium's cost, potentially resolving the intermittency issue of renewables.",
        "Stocks rallied in late trading as technology shares recovered from yesterday's losses, driven by strong earnings reports from major semiconductor manufacturers and optimistic GDP growth forecasts."
    ]
    
    # The pipeline automatically summarizes, vectorizes, and classifies the unseen text
    predictions = text_pipeline.predict(X_new)
    
    # Access the intermediate summaries for the unseen data to display them
    new_summaries = text_pipeline.named_steps['summarizer'].transform(X_new)
    
    print("n--- UNSEEN DATA PREDICTIONS ---")
    for text, summary, prediction in zip(X_new, new_summaries, predictions):
        print(f"Original Document: '{text}'")
        print(f"Intermediate Summary: '{summary}'")
        print(f"Final Predicted Category: {prediction}n" + "-" * 70)

    And these are the final results we obtain — not bad at all!

    --- UNSEEN DATA PREDICTIONS ---
    Original Document: 'A breakthrough mRNA vaccine targeting seasonal flu strains showed 85% efficacy across diverse patient demographics in stage 3 clinical trials, paving the way for a more robust global immune defense next winter.'
    Intermediate Summary: 'New mRNA flu vaccine achieved 85% efficacy in diverse patients, promising stronger global immunity next winter.'
    Final Predicted Category: Healthcare
    ----------------------------------------------------------------------
    Original Document: 'Researchers have developed a grid-scale sodium-ion battery that promises to store surplus wind and solar power at a fraction of lithium's cost, potentially resolving the intermittency issue of renewables.'
    Intermediate Summary: 'New grid‑scale sodium‑ion battery can store excess wind/solar power cheaply, easing renewable intermittency.'
    Final Predicted Category: Energy
    ----------------------------------------------------------------------
    Original Document: 'Stocks rallied in late trading as technology shares recovered from yesterday's losses, driven by strong earnings reports from major semiconductor manufacturers and optimistic GDP growth forecasts.'
    Intermediate Summary: 'Tech stocks rebound late, fueled by strong semiconductor earnings and hopeful GDP growth, boosting overall market rally.'
    Final Predicted Category: Finance
    ----------------------------------------------------------------------

    Wrapping Up

    With the aid of Scikit-LLM, we have learned how to embed a free, pre-trained LLM for summarization directly into a native machine learning pipeline based on scikit-learn. In particular, we combined modern prompt-based text distillation with classical, lightweight TF-IDF vectorizers and linear models like logistic regression for classification, making the overall task lightweight and surprisingly effective.

    Iván Palomares Carrascosa is a leader, writer, speaker, and adviser in AI, machine learning, deep learning & LLMs. He trains and guides others in harnessing AI in the real world.

    Pipelines ScikitLearn Summarization using Your
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    myappsplus
    • Website

    Related Posts

    Startup Athena raises $2.5M in pre-seed funding to revamp the revenue model for legal AI

    November 3, 2026

    If I Could Only Buy and Hold One of These Artificial Intelligence (AI) Chip Stocks for the Next 5 Years, It Would Be This One

    November 3, 2026

    What’s the meaning of the “C” on your USB-C ports?

    November 3, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Cathay Pacific tests Google AI that dramatically cuts airplane contrails — tiny altitude shifts slash environmental impact by 40% in early trials

    September 8, 2026137 Views

    Liene PixCut S1 Photo Printer and Sticker Cutter Review

    October 31, 202617 Views

    Apple is making Creator Studio an even better deal with new AI features and creative tools

    October 28, 202617 Views
    Latest Reviews

    OpenAI warns about how good Astra model is at cracking cybersecurity, releases it anyway because it took ‘years of research and big bets’

    myappsplusSeptember 4, 2026

    Hands-on with Baseus’ tiny PicoGo Pro – a sleek 100W smart display charger for your new Dark Cherry iPhone 18 Pro [Deal]

    myappsplusSeptember 4, 2026

    Judge blocks X rival from using Twitter name, but allows ‘Tweet’ for now

    myappsplusSeptember 4, 2026
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram

    Subscribe to Updates

    Get the latest tech news from FooBar about tech, design and biz.

    Most Popular

    This week’s Apple deals for Labor Day: AirPods Pro 3, Studio Display, AirTag 2, Mac mini, more from $5.50

    September 4, 20260 Views

    Beatbot’s Labor Day Sale drops 2026 Sora 70 5-in-1 robotic pool cleaner to $1,099 ($400 off), more from $339

    September 4, 20260 Views

    iPhone Ultra, iPhone 18 Pro, and More: Apple’s September 9 Event Preview

    September 4, 20260 Views
    Our Picks

    Google confirms something was draining Pixel Watch batteries, fix rolling out

    November 3, 2026

    Save $120 on the Ceramic Midnight Oura Ring 4 in record-low deal

    November 3, 2026

    MacBook Neo, AirPods, Apple Watch, Beats 360, more 9to5Mac

    November 3, 2026

    Subscribe to Updates

    Subscribe to our newsletter and get the latest tech news, app updates, AI trends, smartphone reviews, and exclusive deals delivered straight to your inbox.

    Facebook X (Twitter) Instagram Pinterest
    • About Us
    • Get In Touch
    • Disclaimer
    • Privacy Policy
    • Terms & Conditions
    © 2026 MyAppsPlus. All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.