Cluster and Describe Transactional Data
OpenAI cookbook notebook clustering unlabeled transactions via embeddings and K-Means, then using GPT-3 to label the clusters.
Why it matters
Leverage unsupervised learning to cluster unlabeled transactional data based on embeddings. Use LLM to generate human-readable descriptions for each cluster, enabling effective labeling of previously unclassified transactions.
Outcomes
What it gets done
Generate embeddings for transactional data.
Apply K-Means clustering to group similar transactions.
Utilize LLM to create descriptive labels for identified clusters.
Visualize and refine cluster effectiveness for improved classification.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/oai-clusteringfortransactionclassification | bash Steps
Steps in the chain
Overview
Clustering for Transaction Classification
An OpenAI cookbook notebook that clusters unlabelled transaction embeddings with K-Means and uses GPT-3 to generate human-readable cluster labels. Use when transaction data has no labels but embeddings can meaningfully separate it into categories; not for already-labelled datasets.
What it does
Clustering for Transaction Classification is an OpenAI cookbook notebook for cases where transaction data is unlabelled but has features that can be clustered into meaningful categories. It uses GPT-3 to turn the raw clustering features into human-readable cluster descriptions, which can then be applied as labels to the previously unlabelled dataset. It builds on embeddings generated the same way as the companion Multiclass Classification for Transactions notebook, applied here to the full 359-transaction dataset for a larger learning pool.
When to use - and when NOT to
Use it when transaction (or similarly structured tabular) data has no ground-truth labels but embeddings can capture meaningful structure - the notebook's job is turning opaque clusters into usable, named categories. It reuses the K-Means clustering approach from the companion Clustering notebook rather than introducing a new clustering method. It is not suited to already-labelled datasets, or to data where embeddings wouldn't meaningfully separate categories.
Inputs and outputs
Input is feature embeddings for each transaction, generated per the referenced Multiclass Classification for Transactions notebook. The pipeline clusters these embeddings with K-Means, then calls the Completions endpoint to generate a natural-language description for each cluster and judges how effective those descriptions are. Output is five new clusters with GPT-3-generated descriptions usable as labels.
Integrations
Builds directly on two companion cookbook notebooks: Clustering (for the K-Means approach) and Multiclass Classification for Transactions (for the embedding generation).
Who it's for
Data scientists working with unlabelled transactional data who want automatically generated, human-readable cluster labels as a starting point for a multiclass classifier - the notebook's own result showed GPT-3 correctly inferring that legal-deposit transactions related to literature archival without being told, though some cluster overlap still needed manual tuning.
Source README
Clustering for Transaction Classification
This notebook covers use cases where your data is unlabelled but has features that can be used to cluster them into meaningful categories. The challenge with clustering is making the features that make those clusters stand out human-readable, and that is where we'll look to use GPT-3 to generate meaningful cluster descriptions for us. We can then use these to apply labels to a previously unlabelled dataset.
To feed the model we use embeddings created using the approach displayed in the notebook Multiclass classification for transactions Notebook, applied to the full 359 transactions in the dataset to give us a bigger pool for learning
Setup
Clustering
We'll reuse the approach from the Clustering Notebook, using K-Means to cluster our dataset using the feature embeddings we created previously. We'll then use the Completions endpoint to generate cluster descriptions for us and judge their effectiveness
Conclusion
We now have five new clusters that we can use to describe our data. Looking at the visualisation some of our clusters have some overlap and we'll need some tuning to get to the right place, but already we can see that GPT-3 has made some effective inferences. In particular, it picked up that items including legal deposits were related to literature archival, which is true but the model was given no clues on. Very cool, and with some tuning we can create a base set of clusters that we can then use with a multiclass classifier to generalise to other transactional datasets we might use.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.