Thursday, July 9, 2026
banner
Top Selling Multipurpose WP Theme

On this article, you’ll discover ways to use a pre-trained massive language mannequin to extract structured options from textual content and mix them with numeric columns to coach a supervised classifier.

Subjects we are going to cowl embrace:

  • Making a toy dataset with combined textual content and numeric fields for classification
  • Utilizing a Groq-hosted LLaMA mannequin to extract JSON options from ticket textual content with a Pydantic schema
  • Coaching and evaluating a scikit-learn classifier on the engineered tabular dataset

Let’s not waste any extra time.

From Textual content to Tables: Characteristic Engineering with LLMs for Tabular Information
Picture by Editor

Introduction

Whereas massive language fashions (LLMs) are sometimes used for conversational functions in use circumstances that revolve round pure language interactions, they’ll additionally help with duties like characteristic engineering on complicated datasets. Particularly, you may leverage pre-trained LLMs from suppliers like Groq (for instance, fashions from the Llama household) to undertake knowledge transformation and preprocessing duties, together with turning unstructured knowledge like textual content into totally structured, tabular knowledge that can be utilized to gas predictive machine studying fashions.

On this article, I’ll information you thru the total technique of making use of characteristic engineering to structured textual content, turning it into tabular knowledge appropriate for a machine studying mannequin — specifically, a classifier educated on options created from textual content by utilizing an LLM.

Setup and Imports

First, we are going to make all the required imports for this sensible instance:

Be aware that in addition to frequent libraries for machine studying and knowledge preprocessing like scikit-learn, we import the OpenAI class — not as a result of we are going to instantly use an OpenAI mannequin, however as a result of many LLM APIs (together with Groq’s) have adopted the identical interface type and specs as OpenAI. This class due to this fact helps you work together with a wide range of suppliers and entry a variety of LLMs via a single consumer, together with Llama fashions through Groq, as we are going to see shortly.

Subsequent, we arrange a Groq consumer to allow entry to a pre-trained LLM that we are able to name through API for inference throughout execution:

Necessary observe: for the above code to work, you’ll want to outline an API secret key for Groq. In Google Colab, you are able to do this via the “Secrets and techniques” icon on the left-hand facet bar (this icon seems like a key). Right here, give your key the identify 'GROQ_API_KEY', then register on the Groq website to get an precise key, and paste it into the worth area.

Making a Toy Ticket Dataset

The subsequent step generates an artificial, partly random toy dataset for illustrative functions. When you have your personal textual content dataset, be at liberty to adapt the code accordingly and use your personal.

The dataset generated comprises buyer assist tickets, combining textual content descriptions with structured numeric options like account age and variety of prior tickets, in addition to a category label spanning a number of ticket classes. These labels will later be used for coaching and evaluating a classification mannequin on the finish of the method.

Extracting LLM Options

Subsequent, we outline the specified tabular options we need to extract from the textual content. The selection of options is domain-dependent and totally customizable, however you’ll use the LLM in a while to extract these fields in a constant, structured format:

For instance, urgency and frustration usually correlate with particular ticket sorts (e.g. entry lockouts and outages are usually extra pressing and emotionally charged than common inquiries), so these alerts may also help a downstream classifier separate classes extra successfully than uncooked textual content alone.

The subsequent operate is a key ingredient of the method, because it encapsulates the LLM integration wanted to rework a ticket’s textual content right into a JSON object that matches our schema.

Why does the operate return JSON objects? First, JSON is a dependable technique to ask an LLM to supply structured outputs. Second, JSON objects might be simply transformed into Pandas Sequence objects, which might then be seamlessly merged with different columns of an current DataFrame to develop into new ones. The next directions do the trick and append the brand new options, saved in engineered_features, to the remainder of the unique dataset:

Here’s what the ensuing tabular knowledge seems like:

Sensible observe on price and latency: Calling an LLM as soon as per row can develop into sluggish and costly on bigger datasets. In manufacturing, you’ll normally need to (1) batch requests (course of many tickets per name, in case your supplier and immediate design permit it), (2) cache outcomes keyed by a secure identifier (or a hash of the ticket textual content) so re-runs don’t re-bill the identical examples, and (3) implement retries with backoff to deal with transient charge limits and community errors. These three practices sometimes make the pipeline sooner, cheaper, and way more dependable.

Coaching and Evaluating the Mannequin

Lastly, right here comes the machine studying pipeline, the place the up to date, totally tabular dataset is scaled, break up into coaching and take a look at subsets, and used to coach and consider a random forest classifier.

Listed below are the classifier outcomes:

When you used the code for producing an artificial toy dataset, chances are you’ll get a somewhat disappointing classifier end result when it comes to accuracy, precision, recall, and so forth. That is regular: for the sake of effectivity and ease, we used a small, partly random set of 100 cases — which is usually too small (and arguably too random) to carry out effectively. The important thing right here is the method of turning uncooked textual content into significant options via the usage of a pre-trained LLM through API, which ought to work reliably.

Abstract

This text takes a mild tour via the method of turning uncooked textual content into totally tabular options for downstream machine studying modeling. The important thing trick proven alongside the best way is utilizing a pre-trained LLM to carry out inference and return structured outputs through efficient prompting.

banner
Top Selling Multipurpose WP Theme

Converter

Top Selling Multipurpose WP Theme

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

banner
Top Selling Multipurpose WP Theme

Leave a Comment

banner
Top Selling Multipurpose WP Theme

Latest

Best selling

22000,00 $
16000,00 $
6500,00 $
5999,00 $

Top rated

6500,00 $
22000,00 $
900000,00 $

Products

Knowledge Unleashed
Knowledge Unleashed

Welcome to Ivugangingo!

At Ivugangingo, we're passionate about delivering insightful content that empowers and informs our readers across a spectrum of crucial topics. Whether you're delving into the world of insurance, navigating the complexities of cryptocurrency, or seeking wellness tips in health and fitness, we've got you covered.