Natural Language Processing
How machines read: the stages of NLP, chatbots, text normalisation, Bag of Words, TF-IDF and sentiment analysis.
1What is NLP?
Natural Language Processing (NLP) is the domain of AI that helps computers understand, process and respond to human language, both written and spoken.
2Stages of NLP
To understand text, an NLP system works through five stages: lexical analysis, syntactic analysis, semantic analysis, discourse integration and pragmatic analysis. Step through them with each example sentence.
3Chatbots: script bot and smart bot
A chatbot is a program that talks with people in natural language. A script bot follows a fixed script with set options. A smart bot uses AI to understand many ways of asking, learns from data and remembers the conversation.
Two chatbots for a school helpdesk. Send the same message to both and compare their replies. Tap a suggestion or type your own.
4Text normalisation
Before a machine can work with text, we clean and simplify it. Text normalisation reduces the text to its basic form in steps: sentence segmentation, tokenisation, removing stopwords, special characters and numbers, converting to a common case, and stemming or lemmatisation.
5Bag of Words and TF-IDF
Bag of Words turns each document into numbers: how often each vocabulary word appears in it, ignoring word order. TF-IDF improves on this by giving more weight to words that are frequent in one document but rare across the corpus.
6Use case: sentiment analysis
Sentiment analysis finds the feeling in a piece of text. A simple model gives each word a score, flips the score after 'not' and boosts it after 'very', then adds everything up. In Orange, the Sentiment Analysis widget does this for thousands of texts at once.
A shop collected 12 reviews of its new school bag. The model labels them all at once.