Assisting Accountants with Similarity-based Machine Learning

Hannes Hapke, Cole Howard14 Feb 2023

Problem

Digits is accounting software. Its Boost feature checks every transaction in a client ledger, flags transactions in unexpected categories and suggests categories for uncategorised ones. A plain classifier gives the same category for the same input. Accountants disagree, though, and the right category depends on the client's context. String matching such as Levenshtein distance fails in several scenarios that the post shows in an animation.

Example from the article: one accountant files a transaction as Meals & Entertainment, another as Travel because it happened during a trip, and both can be valid.

Solution in brief

Instead of predicting a category, train an encoder that maps transactions to embeddings, so related transactions land close together. For a new transaction, search the index of historical transactions for neighbors and read the categories off them. An approximate nearest neighbors (ANN) index keeps the search fast at millions of vectors.

Questions this case answers
  • How to predict a label that depends on each expert's subjective context, when a single fixed classifier would give every expert the same answer
  • How to retrieve semantically related records from millions of items within streaming latency when string distance misses related items
  • How to suggest a category for a bank transaction when different accountants categorise the same transaction differently?
  • How to find related historical transactions when text matching (edit distance) fails?

Tools and methods

  • Triplet-style similarity training — teaches the encoder with anchor, positive and negative transactions
  • TensorFlow Similarity — loss implementations the authors recommend, used with their TFX setup
  • Cosine distance — compares embeddings; on normalized vectors it is a dot product
  • Approximate nearest neighbors (ANN) — fast neighbor lookup with a precomputed index or graph
  • Vertex AI Matching Engine — managed ANN service with automatic sharding and autoscaling
Continue reading — it's free

Google or a one-time email code. No password.