Hey Siri, How Can You Understand Me?

Exploring natural language processing algorithms in AI

Freeman Jiang
Nov 5 · 7 min read

Nowadays, anyone can pick up their phone, ask it a question, and obtain a relevant (and usually accurate) response — all in seconds. We often don’t question how this is done or how that is even possible.

The fact is that the idea that computers could understand human language directly much less give a response back was unheard of until very recently. Human language is incredibly complex, with a myriad of nuances, exceptions, and rules. We often take for granted the amount of work that has gone into building the digital assistants we use every day.

This article will explain how computer algorithms can understand human language on a higher-level. Buckle your seatbelts, everyone, because we’re going back to English class.

But First — Natural Language Processing: What is it?

Natural Language Processing or NLP is a subfield of artificial intelligence combining computer science, linguistics, and information engineering. It has allowed computers to read, decipher, understand, and make sense of human languages as a real person would.

However, don’t think it’s easy. The hardest thing about understanding human language is that it’s very different from the clear, direct code that a computer is used to reading. Human languages are incredibly complex, and many are heavily context-based. This means that words which mean one thing in one context have a completely different meaning in another. Just look at how many different senses the word “set” has — it’s in the hundreds. So how does it do it? How can a computer understand an abstract concept which took millions of years of evolution for humans to achieve? Let’s find out.

Part 1: Morphology

At the most basic level, a computer has to understand the morphology of the language it’s trying to communicate in — that is, the structure and function of individual words.

The image to the left shows a morphology tree, a visual representation of each word divided into more and more specific parts.

Thanks to the painstaking work of many human classifiers, there are classified libraries that contain the divided parts of most words in English.

The traditional way of training NLP algorithms is to have them learn through these manually sorted libraries — text corpora — like this one here. This is called supervised learning, where the data has already been tagged. However, since language is always evolving and changing (just think of how different Old English is to Modern English), the preset rules in these text corpora aren’t always the best way to train NLP algorithms.

Modern NLP algorithms are self-learning, and they define rules for the text corpora as they read, coming up with their own rules. This method of training uses semi-supervised learning, where some of the data is already classified, but it is up to the computer to decide which rules it will use to classify the rest.

Part 2: Syntax

If morphology was about understanding the structure and makeup of words, an understanding of syntax is needed to comprehend the structure of whole sentences. When most humans look at a sentence, they can just intuitively understand it. Computers, on the other hand, need to break that sentence into phrases. In doing so, they create tree diagrams called parse trees.

A parse tree
A parse tree

It’s important to note here that each language has its own grammar rules, and phrases are put together differently in each one.

Like with the morphology trees, rules for the sentence structure of a particular language can be programmed into a computer program by hand, or learned by using a text corpus. Parse trees can be very simple like the one in the left, or very complicated depending on length.

Part 3: Semantics

The next part in developing an NLP algorithm is having it to recognize the semantics or the intended meaning of the word. The problem with this is that the same word (with thus the same morphology) can have different meanings even though their syntactical function is the same.

“Chop the apples on the board

“The chairman of the board just walked in”

Take these two example sentences — the meaning of the word “board” is completely different even though they are both nouns spelt the same way. For us, the difference is immediately obvious, but for a computer, it can be quite hard.

One way computers can be trained to recognize the difference is to look at the context in which the word is used — or simply put, the words before and after the word in question. If “apples” precedes the word “board”, it’s likely that the board is a chopping board. On the contrary, if “chairman” precedes the word “board”, it’s most probable that we’re talking about a board of directors.

Again, it’s important to note that none of this is possible without huge amounts of data. This is where we turn back to our ever-helpful friend — the text corpora. By analyzing how the same word is used in a multitude of examples and contexts, a computer can eventually learn the different meanings of that word. This means that even if you give it a completely new sentence, it can still understand the meaning of the word in that sentence.

Part 4: Pragmatics

By now, our algorithm can understand the meaning of individual words and even the function of those words in different sentences. Typically, this is good enough to understand language at a basic level and it’s here where most NLP algorithms nowadays are at. However, to take it to the next level, a computer has to understand pragmatics, the context which surrounds entire sentences. At this point, our NLP algorithm would know the exact meaning of each sentence as a whole (think macro-semantics).

This is an area where even humans struggle. For people who are not native English speakers, this can become apparent. Linguistic devices like irony, sarcasm, and humour (like puns) often go unnoticed unless the listener or reader is fluent in that language.

If you want to read more about how computers can understand pragmatics, I definitely recommend this study from the University of Valencia in Spain.

Back to Siri

Okay, so now we have a basic understanding of how our computer can understand language — great! Once NLP algorithms have been sufficiently trained, they can understand language like any experienced speaker. When you ask Siri what the weather is going to be like tomorrow, your audio is converted into text (a super cool process that will be explained in a future article!). Then, once it’s in a form the computer is used to seeing (text), it’s there where all the NLP training comes in.

All those hours (or days… or weeks 👀) of training will pay off because once it has understood the meaning of what you’re trying to ask it, it gives a pre-programmed response — a relevant answer to your question or statement. For now, most responses that digital assistants give are already coded into the system. This means that if you ask it to set an alarm for 7 AM tomorrow, it will do that but if you ask it for the meaning of life, it’ll most likely just search the web for another answer.

In the future, as AI chatbots evolve to create new and relevant answers, we will soon no longer be able to tell the difference between human and machine. As we browse the internet, who knows whether we will be talking to a person or a computer? It’s definitely something to think about.

Key Takeaways

  • Natural Language Processing (NLP) is a now-ubiquitous, largely unappreciated AI subfield that has allowed computers to understand human languages like a real person
  • Human languages are incredibly complex and understanding them requires computers to have access to huge amounts of data
  • To fully understand a language, a computer must understand its unique morphology, syntax, semantics, and pragmatics
  • Modern digital assistants like Siri, Alexa, and Google Home all rely on NLP to understand and give relevant answers to user questions
  • In the future, AI has the potential to generate new and relevant responses that are indistinguishable from those of humans. At this point, we will no longer be able to know just through conversation who is human and who is not.

Towards AI

Towards AI, is the world’s fastest-growing AI community for learning, programming, building and implementing AI.

Freeman Jiang

Written by

Emerging Technologies Enthusiast and Innovator at TKS

Towards AI

Towards AI, is the world’s fastest-growing AI community for learning, programming, building and implementing AI.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade