Table of contents
NLP is a field of linguistics and machine learning for human language. Its motive is to understand the words and the context of words.
Key NLP tasks
Classification of sentences: categorizing the sentence into fixed classes. ex: email classification into spam or ham, sentiment analysis of the reviews
Classifying words in sentences:
POS (Part of Speech) tagging: Grammatical components of a sentence, identifying words as nouns, verbs, adjectives, etc
NER (named entities recognition) tagging: identifying named entities from a person, location, or organization.
Text Generation: Fill in the blanks in a text with masked words as per the sequence context or probability of the next word.
Question Answering: Given a question and a context, extract the answer for the question based on the information provided in the context.
Text Summarization: Summarizing a text passage with the given context.
Machine Translation: From source language to a target language conversion.
Transformer
Transformers are a type of neural network architecture that are used in natural language processing (NLP) tasks, as mentioned above. Transformers work by using a technique called self-attention, which allows them to learn relationships between different parts of a sequence. This is in contrast to recurrent neural networks (RNNs), which can only learn relationships between adjacent elements in a sequence.
Transformers were first introduced in the paper "Attention Is All You Need" by Vaswani et al. (2017)(will cover it later ๐). Since then, they have been shown to achieve state-of-the-art results on a variety of NLP tasks.
Here are some of the advantages of using transformers in NLP:
They are able to learn long-range dependencies in text.
They are parallelizable, which makes them faster to train.
They have been shown to achieve state-of-the-art results on a variety of NLP tasks.
Here are some of the disadvantages of using transformers in NLP:
They require a large amount of data to train.
They can be computationally expensive to train.
They are not as well-suited for tasks that require sequential reasoning.
Example transformer for sentiment analysis
Will be using transformer from Huggingface
Install the transformer library
!pip install transformers
Use the model for classification
from transformers import pipeline classifier = pipeline("sentiment-analysis") classifier("This is the worst possible product. Nothing works in this.")
Output
[{'label': 'NEGATIVE', 'score': 0.9998025298118591}]