Android Pie, the newest version of Google’s mobile operating system, launched earlier this week, and one of its niftiest features is Smart Linkify. It’s an API that adds clickable links when addresses, phone numbers, and other such entities are detected in text. While that might sound like the result of some witchcraft or voodoo magic, it all boils down to artificial intelligence.
“Looking for phone numbers and postal addresses in text is a difficult problem,” Lukas Zilka, a software engineer at Google AI, wrote in a blog post. “Not only are there many variations in how people write them, but it’s also often ambiguous what type of entity is being represented (e.g. ‘Confirmation number: 857-555-3556′ is not a phone number even though it takes a similar form to one).”
Smart Linkify is an evolution of the existing Android Linkify API, Zilka explained, and under the hood consists of two compact, low-latency feedforward neural networks — machine learning algorithms comprising layers of simple processing units called nodes — that borrow from the technology underlying Android Oreo’s Smart Text Selection feature.
Both networks train on data generated by a third model that scrapes phone numbers, addresses, products, places, and business names from the web and adds random “textual contexts” and phrases to them (e.g., “Confirmation number” and “ID”). The Google AI team uses one algorithm for Latin-script languages (English, German, Polish, and Czech) and individual models for Japanese, Korean, Thai, Arabic and Russian.
Here’s how the whole thing works: the text to be analyzed is split into words, and from those words, all possible subsequences of a certain maximum length are generated. Then, the first neural network in the system assigns each subsequence a value (between 0 and 1) indicating its confidence in its identity (e.g., whether a given string of numbers is a passcode or a phone number.)
The entities with the lowest score are discarded from the list, and then the second neural network steps in, classifying the entities by type — i.e., phone number, address, or non-entity.
“[The] networks need to know the context surrounding the entity (in addition to the text string of the entity itself). In machine learning this is done by representing these parts as separate features,” Zilka wrote. “Effectively, the input text is split into several parts that are fed to the network separately.”
To that end, words are converted into character n-grams, a technique that “represents [them] as a set of all character subsequences of a certain length.” And a neural network feature indicates whether those words start with a capital letter — a distinctive feature of postal addresses.
In practice, given the sentence “John should call 1-800-944-9494 on Tuesday,” Smart Linkify would (1) separate “John should call” from “1-800-944-9494,” (2) classify “John should call” and “1-800-944-9494” as a non-entity and phone number, and (3) create a clickable link from the phone number in a web browser or app.
Working within the constraints of smartphone hardware was an added challenge for the team. They addressed it with quantization — a compression technique that converts a continuous range of values into a finite range of discrete values — and by sharing certain numerical representations between the system’s two neural networks, among other techniques.
In the near future, the team hopes to create machine learning models for date and time — particularly for recognizing informal phrases like “next Thursday” or “in 3 weeks.”
“We believe that the architecture could extend to other on-device text annotation problems and we look forward to seeing new use cases,” Zilka wrote.