By the end of this learning module, students will be able to:
Why does preprocessing need to know?
Steps of preprocessing.
Conversation way for Text to be Numeric.
Terms of Transformer model.
Why preprocessing is necessary?
Preprocessing is essential in NLP because raw text data is often noisy and unstructured, which can hinder the performance of machine learning models. This not only enhances the model's ability to understand the data but also improves its accuracy and efficiency in tasks like text analysis. Preprocessing ensures that the data is in a form that the model can effectively learn from and make accurate predictions.
Processing steps
NLP preprocessing refers to the series of steps taken to clean and prepare text data for natural language processing tasks. This typically involves removing noise (punctuation and special characters), converting text to lowercase, tokenization (splitting text into individual words), removing stopwords (common words like "and" or "the"), stemming or lemmatization (reducing words to their base V1 forms), and transforming text into numerical representations. Let's see the mentioned diagram for visual presentations of preprocessing outcomes.
Sentence Segmentation
Sentence segmentation is the process of dividing a text into individual sentences. This is a crucial step in NLP as it helps to understand the structure and meaning of the text. Furthermore, it helps for tokenization.
Tokenization
Tokenization is the process of breaking down text into smaller units called tokens, which can be words, phrases, or even characters. By splitting the text into tokens, it becomes easier to analyze and understand the structure, and meaning,
Without tokenization, it would be challenging to analyze or extract meaningful patterns from the text, as models require data to be in a consisten.
Stop words are words in any language that occur frequently. For some NLP tasks, they do not provide any additional or valuable information to the text containing them. Words like a, they, the, is, an, etc. are usually considered stop words. Figure 1 represents the flow chart of the following task.
NLTK, spaCy, and TextBlob are well-known libraries used for removing stop words in NLP tasks.
Figure 1: Removing stop words flow chart.
Stemming
Stemming is a technique used to reduce an inflected word down to its word stem. This process helps to standardize variations of a word, which can improve the performance of text analysis tasks by reducing dimensionality and ensuring that different forms of a word are treated as the same. The advantages of stemming are enhanced search and improved consistency in text processing.
Lemmatization
Lemmatization is another technique used to reduce inflected words to their root word. It describes the algorithmic process of identifying an inflected word’s “lemma” (dictionary form) based on its intended meaning. But compared to stemming, lemmatization is a slow and time-consuming process.
Text to Numeric
As our machine understands only numerical data, we need to transform our dataset into numerical form. There are several well-known methods to convert text data into numerical format, such as:
Bag of Words (BoW): It turns text into a fixed-length vector by counting how often each word appears, without considering grammar or word order.
TF-IDF: Measures how important a word is in a document by comparing its frequency in that document.
Word Embeddings: Represents words as dense vectors in a continuous vector space, capturing semantic relationships between words.
One-Hot Encoding: Represents words as binary vectors where each position indicates the presence or absence of a specific word in the text.
Mathematical concepts of the above transformers
Here are the mathematical operations involved for each text transformation process:
1. (BoW) Construct a term-document matrix where each entry (i, j) represents the frequency of term i in document j.
Formula: M (i j) = count of term i in document j
2. Term Frequency-Inverse Document Frequency (TF-IDF) follows the mentioned figure terms. 👉
Word Embeddings: Map each word to a continuous vector space using pre-trained embeddings.
3. One-Hot Encoding: Create a binary vector for each word. 👉
__________________________________________________________________________________________________________________________________________________