Tech

« The solution comes from the right problem formulation »

This article was written by Jérôme Bovay as part of the development of intelligent algorithms for invoice processing with the Sway Finance team.

Sway Finance offers an efficient solution to manage all your bank accounts into a single app. In short, they are a smart layer processing your bank and invoice data, to power cash management features and accounting automations.

My first project with them was to bring intelligence into the app to automatically match invoices and respective transactions together.

You ask why?

I’m not a professional accountant, but when you manage your company, you need to track and justify each transaction for legal reasons. More importantly, as an entrepreneur, you need to know how much money you owe to your suppliers and how much your clients owe you. Phone costs, monthly rent, expenses, on one side, and all service or product invoices sent on the other. The best way to answer both needs, is to look at each transaction, and search for the corresponding invoices. When you have a few dozen per year, it’s okay, you can do it manually. When you have hundreds or thousands, it’s a completely different story.

Here comes Sway Finance AI!

AI approach

Problem formulation

Data matching arises in many contexts. From a generic perspective, the goal is to match pairs of elements in a database when both elements represent the same real-world entity.

In Sway Finance context, the goal is to match financial transactions with corresponding invoice(s). The real-world entity is the payment from a debtor to a creditor, where the transaction is the actual trace of the payment within the banking system, and the invoice is the rationale about why such a payment took place.

Note that the invoice is usually a pdf and in some bad cases, a poor-quality picture. A pre-processing step is required to have tabular data to work with. We’ll deep-dive into this topic in a separate article.

Common dimensional space

An intuitive approach would be to bring data of those two separate dimensional spaces into a common one and find pairs by putting close points together.

But which common space to select? How to project data points into this new space? Once you’re done, how do you measure distance between points? Rather easy in two dimensions, but do not forget that in high dimensional spaces, all data points appear equidistant...

All those“not-so-easy-to-answer” questions indicate that we should put our effort elsewhere.

Can LLMs achieve anything?

QUESTION: “Let’s assume you are a faithful administrative assistant. You are given this set of invoices, represented by a list of .json files. You are also given a set of banking transactions in this .csv file. Please find me matches.”

If you’re familiar with LLMs, this could have been a simplified version of the prompt you would have sent to your familiar Gen AI tool such as ChatGPT or Gemini.

ANSWER: “With the data you provided, I think invoice n°3 matches with transaction A, invoice n°7 with transaction B, […]”

And now what...?

How do you know the kind of features that have been used to do the matching? How do you control the number of false positives? How do you manage the costs of such a huge machinery?

LLMs can help and achieve excellent results. But they are not well suited when you want to understand and control your machine learning pipeline and offer quality guarantees to your clients such as strict levels of accuracy and sensitivity.

The solution: translate to a well-known problem statement

The approach I took is to make sure we can reformulate the problem into a classical machine learning workflow, making possible to apply standard algorithm that are proven to work.

Pairing

The first step is to create a set of all meaningful theoretical pairs. We must be careful because if we blindly compute those pairs for 1’000 invoices and 1’000transactions, we end up with one million items.

To reduce complexity, we can use the invoice and transaction dates to create sub-groups, check the invoice direction with respect to debit or credit transactions, etc.

Features

Every good machine learning workflow comes with a good set of features. Is the amount close? Are the beneficiary names close? Can we use the payment reference? There are plenty of clever features that will greatly help the work of the classifying algorithm. We’ll deep dive into features in a separate article.

Binary classifier

With the two previous steps, we can now feed a binary classifier with target being “do the invoice and transaction match?”. This allows us to use the traditional set of optimization algorithms, and to control every aspect of the workflow. We can set the threshold to achieve the regime we want, i.e. have a dedicate false positive rate or true positive rate, depending if we focus on recall or precision.

How does it look like in practice?

After a successful project, the Sway Finance mobile app now leverages the first version of the invoice-matching algorithm. Initial results show a True positive rate of >98% for less than 1% False positive rate. Make sure to download the Sway app to try it out for yourself and start matching your invoices and transactions effortlessly with their AI!