ML-powered semantic search in eCommerceSerge Korzh
9 January 2020
Reading Time: 4 minutes
There are many crucial components to an eCommerce shop, but one is indispensable – product search. Unless you have only a handful of products to sell, you cannot run an eCommerce shop without it. Searching for a product is the key step to purchase – if a customer cannot find what they want, they will abandon the shop, even if it has relevant products on offer. Taking this into account, it seems like improving the search functionality should be one of the top priorities for an eCommerce website. Yet, it doesn't always receive the amount of attention it deserves.
Why is product search so hard?
eCommerce search is mapping user's intent to the best products that satisfy this intent. For example, if a user wants to buy a "beige cotton shirtdress without any stripes", then the search result should include one to three products that best represent the description of the desired clothes. So, what can go wrong with such a query in a typical search?
Getting the meaning of words
The most obvious problem is, well, the semantics of words. First of all, the system must identify that we are primarily interested in a "shirtdress". But what if there is no notion of a "shirtdress" in our knowledge base? Furthermore, can the system understand that, for instance, "beige" is a colour? And, even then, can it also take into account that it is similar to "khaki" or "bleached yellow"?
A simple lexical search is not capable of understanding the meaning of words, the concept behind them, and their relationship with each other. A straightforward way to deal with this problem is to categorise all terms that may be used by the user into categories (e.g. "green", "white", "yellow" – "colour"), and group synonyms within these categories ("lime", "mint" – "green"). This process is called Ontology Engineering. One of the largest English ontologies is WordNet, containing 155 000+ words organised in more than 175 000 synonym groups called sysnets. WordNet is published under an open-source licence and has interfaces to many major programming languages.
Dealing with negation
So, it seems that it is enough to extract the words, identify typos and normalise them to their base form. Then, we can match them with the categories and synonyms that we have in our database. But let's return to our query: you may notice that it ends on "without stripes". If we process it with our method, we would probably identify "stripes" as a feature or pattern. Here, we're running into a problem that many search engines have – returning the exact opposite of the desired results for a query with negation.
It is generally difficult to deal with negation for a computer. We can express it in many ways ("without stripes", "no stripes", "stripeless") each relating differently to other words ("no" might negate one or more consecutive terms, while "-less" cannot). To deal with negation, we have to take into account not only the meaning of words but also their order. This problem has recently seen tremendous progress due to the rise of Deep Learning and Recurrent Neural Networks in particular. While such systems achieve very high accuracy, they are usually too costly to be used in high throughput search engines as they require significantly more time and computational power to process a single query.
Okay, so we determined the meaning of all the words in a query, now what? How do we get the most relevant products while leaving out all of the irrelevant ones? Furthermore, how to rank them? The problem is usually called the precision-recall tradeoff. Precision tells how many of the presented products are relevant. Recall is a measure of how many of the relevant products from our catalogue we present to the user.
We want the right balance between the two, so how do we rank the products? One such method is called TF-IDF, which is a weighting scheme that allows us to determine how relevant a term (word) is in a document (product information) from a corpus (product catalogue). Many search engines use it as a core tool for ranking relevance based on a user query. More generally, the problem of ranking items is called Preference Learning, and it may employ much more sophisticated machine learning algorithms.
Those are just a few of the issues addressed by semantic search. It is easy to see why the task of providing relevant search results is so hard. If we add other factors, such as personal data of the user (i.e. personalised search), the problem becomes even more complex.
Are there other ways of smart search?
While typing a query with a keyboard is still the primary method people search for products, other ways are starting to emerge. According to Google, 20% of searches on Android Google app are done by voice, and voice search is getting used in eCommerce more and more. So, a natural question is: do the aforementioned considerations and solutions apply? They do! We can reduce a voice query to its written form by performing speech recognition and then use the same tools. Moreover, semantic search is even more critical when dealing with voice queries, since they tend to be put in a more "natural" language (as people would ask from a real person) and thus are longer and more complicated to process.
Another recent addition to the way people search is using their cameras – image search is starting to get used in many new exciting scenarios. For example, in 2017, Pinterest introduced Lens, a visual discovery tool that lets you take a photo and search for similar content available on Pinterest. Sure enough, eCommerce is not falling behind – the service Find It On eBay uses image search to find where to buy stuff displayed on a picture taken by a user. Such functionality is built on an entirely different set of machine learning tools, namely, object detection and convolutional neural networks. Constructing such systems requires a lot of data and compute power. Nevertheless, both are becoming more and more accessible, making it feasible for smaller companies to implement these systems as well. While the technology is still in its early stage, it has the potential to be hugely useful for the customers, so it's worth keeping an eye on it.
To sum up
Figuring out precisely what your users want to find is a complex problem, and in this day and age, it is not enough to perform simple word-matching filtering to make the customers happy. Semantic search tackles this problem by analysing the meaning of words and extracting the original intent of a user's query. Yet, to provide relevant results, we need to understand the user's intent but also the products in your catalogue. Using voice and pictures as an input for the search is getting used more and more among eCommerce shoppers. However, these types of search are yet to be adopted by the industry en masse.