Natural language processing (NLP) is the area of artificial intelligence that teaches computers to understand, interpret and produce human language, written or spoken.
When you chat with a chatbot, use your phone's autocorrect or request an automatic translation, NLP is working in the background.
How it works
The computer does not read words, it reads numbers. So NLP transforms text into numerical representations and uses models to find patterns.
The classic steps are:
- Tokenization: break the text into pieces, such as words or subwords.
- Representation: convert each piece into vectors, the embeddings.
- Analysis: identify part of speech, entities, sentiment or intent.
- Generation: produce a response or new text.
Today, most NLP tasks are done by LLMs, which are neural networks trained on a lot of text. Before them, hand written rules and simpler statistical models were used.
Practical example
You have a store and receive hundreds of customer reviews. You want to know which are positive and which are complaints. This is called sentiment analysis.
With Python and the Transformers library, the skeleton is:
pip install transformersfrom transformers import pipeline
classificador = pipeline("sentiment-analysis")
print(classificador("A entrega atrasou e ninguém respondeu."))The result indicates whether the text is positive or negative and with what confidence. Test with real sentences in Portuguese and choose a model suitable for the language.
What it's used for
NLP is used for chatbots and assistants, translation, document summarization, intelligent search, email classification, data extraction from contracts and opinion analysis on social networks.
For programmers, it is also behind the AI agents, which need to understand requests in plain language and turn them into actions.
Caveats
Language is full of ambiguity, irony and slang. Models can make mistakes in these cases and reflect biases from the training texts. See also algorithmic bias. Always validate results on real samples.