Problem
Employees on Ramp have to code each expense with a general ledger (GL) category from their company's accounting system. Most are not accountants and must search through hundreds of codes with little explanation of what each means. Mistakes create extra work for finance teams when they close the books. Ramp wanted to group similar transactions and predict the GL category of a new one from codes already attached to similar transactions.
Example from the article: a new laptop purchase should land near other electronics purchases in the embedding space, so the suggested code is the one those neighbors carry.
Solution in brief
Ramp turns each transaction into a text string from its most relevant fields and fine-tunes a small pre-trained encoder on these strings with triplet loss, using GL categories as labels. Hard triplets are mined on the fly with a semi-hard batch loss, so the model learns to separate close categories. At query time, nearest already-coded transactions provide the suggestion.
Questions this case answers
- How to predict a label for a new structured record by retrieving similar already-labeled records when the label set is large and has near-duplicate classes
- How to train a compact embedding model for fast retrieval when randomly sampled training examples are too easy
- How to suggest the right accounting code for a new expense from already coded transactions?
- How to turn a transaction with mixed fields (merchant, category, memo, amount) into an embedding that clusters by accounting category?
Tools and methods
- Sentence Transformers — library for fine-tuning the encoder and computing embeddings
- Triplet loss — trains the encoder so same-GL transactions sit closer than different-GL ones, by a margin
- BatchSemiHardTripletLoss — on-the-fly mining of tricky triplets
Google or a one-time email code. No password.