University topic explanations and practice

University › Artificial Intelligence and Data Science › Natural Language Processing

Text Preprocessing

Split raw text into meaningful units, decide on stop words by task, and compare stemming with lemmatization. Check the output of preprocessing.

Save your circuit

Learning Outcomes

Topic Explanation

Purpose and place of text preprocessing

In natural language processing systems, raw text cannot be processed directly; It is first brought into a regular and predictable form. This step reduces noise and ensures that subsequent steps use the same representation. The quality of preprocessing directly determines the success of higher tasks such as classification or information extraction. A well-designed pipeline eliminates unnecessary differences while preserving the meaning of the data.

The process usually consists of cleaning the text, dividing it into units, normalizing it, and reducing the words to the basic form. Not every step is reversible; Therefore, it should be decided in advance what information will be protected. While punctuation carries meaning in some tasks, it is just noise in others. That's why preprocessing is not a recipe, but a series of decisions made based on the task.

Cleaning and normalization

Cleaning removes unnecessary characters and formatting differences. Lowercase reduction combines different spellings of the same word into a single form. For Turkish, special letters must be preserved correctly; If the distinction between dotted and undotted i is ignored, words will be matched incorrectly. A stable normalization also ensures that the same text gives the same result every run.

During the normalization phase, numbers, dates, and abbreviations are converted into a consistent format. The meaning of numerical expressions is preserved by preserving units of measurement. Excessive spaces and line breaks are simplified; However, if paragraph boundaries are preserved, context information is also preserved. This step ensures that texts from different sources are comparable.

Tokenization: splitting text into units

Tokenization is the process of dividing the text into meaningful units such as words, subwords or sentences. The simple approach splits by spaces; However, punctuation and compound words render this method inadequate. It is necessary to distinguish between the period at the end of the sentence and the abbreviation point. The boundaries of the resulting units determine the data that all subsequent layers can see.

Subword splitting alleviates the problem of non-lexical words by splitting infrequent words into smaller parts. This approach works especially well in additive languages. Sentence-level division is the first step in tasks such as summarization and question and answer. When the splitting strategy changes, the attributes also change; so the entire pipeline is evaluated together.

Stop words and meaningful words

Stop words are function words that occur frequently and have low discrimination power. Removing these reduces the number of features and strengthens the signal. However, if negative words are removed, the meaning may be reversed. Therefore, list results should always be reviewed on sample texts.

The stop words list should be adapted to the task. Negative words are retained in sentiment analysis; It can often be omitted if the subject is in classification. In question and answer tasks, question words must be preserved. The decision should be made by considering the data at hand and the target task together.

Stemming and lemmatization

Root finding is the method of reaching the common root by removing suffixes from the word. Stemming transforms the word into its basic form in the dictionary. Both of them aim to gather the same forms of inflection or derivation into a single attribute. This reduces data sparsity and matches similar texts better.

Rooting is faster but can erode meaning. Stemming is more accurate but requires a reliable dictionary. In agglutinative languages ​​such as Turkish, incorrect root extraction can confuse two different concepts. So the output of both methods should be checked on a small set of samples.

Noise and the fail-closed approach

Actual texts contain typos, truncated words, and coding differences. This noise leads to the same concept being represented in multiple ways. Preprocessing detects errors to reduce uncertainty. However, not everything detected should be fixed automatically.

An unverifiable correction adds non-existent information to the data. Therefore, in doubtful cases, the word is left as is or marked with a special symbol. The fail-closed principle chooses the risk of omission over incorrect addition. This attitude is especially critical in the production of content that requires copyright and accuracy.

Checking the preprocessing output

The output should be examined on a small sample after each preprocessing step. The number of tokens, dictionary size, and the rate of function words extracted are the key indicators to monitor. Sudden changes usually indicate an error. Quality claims should not be made without measurement.

Inspection should not be limited to first samples only. Texts of different lengths and from different sources should also be tried. This way the consistency of the pipeline can be measured. A well-controlled preprocessing layer significantly improves the performance of subtasks.

Hands-on work and lessons learned

"Very nice!" in a product review. How is the expression broken down into a token? question is a concrete application of this subject. The solution is set up with these steps: Treat the punctuation mark as a separate unit. Reduce letters to lowercase. Separate words by dividing by spaces. The result is two meaningful words and one punctuation unit. Each step uses the output of the previous one as input; thus the decision is not based on a single intuition but on a traceable chain. Thus, a very, beautiful and exclamation point result is achieved. This example shows the importance of the order of steps and verification.

How to match the word "Good" in two different encodings of the same text? question is a concrete application of this subject. The solution is installed with these steps: First, apply encoding normalization. Then reduce it to lowercase according to Turkish rules. Verify that the two formats produce the same basic sequence of letters. Thus, different spellings are collected in a single attribute. Writing intermediate results allows you to see later at which stage the error occurred. Thus, it is concluded that both forms turn into the same normalized word. This example shows the importance of the order of steps and verification.

How to decide whether a frequently occurring function word should be removed? question is a concrete application of this subject. The solution is set up with these steps: Determine the task to which the text belongs. Examine in the example whether the word has meaning or not. Keep the word if it has a negative or interrogative function. Remove from the list only if the discriminative power is low. Clearly stating the assumptions makes it easier to safely apply the same method to another example. Thus, the decision is made according to the task, and the conclusion is reached that the rule is not applied blindly. This example shows the importance of the order of steps and verification.

How to reduce the risk of finding incorrect roots in an agglutinative language? question is a concrete application of this subject. The solution is installed with these steps: Compare the stemming and stemming outputs side by side. Examine the different words in example sentences. Undo transformations that cause semantic shifts. Reflect audit results in the dictionary. If the checking step is skipped, even a result that appears correct may be due to incorrect input. Thus, it is concluded that semantic drift is prevented by example control. This example shows the importance of the order of steps and verification.

Which method should be followed for a word that is not in the dictionary? question is a concrete application of this subject. The solution is installed with these steps: Check the word for spelling errors. Break it into parts with subword splitting. Evaluate whether the pieces make sense. If it cannot be verified, mark it with a special icon. Changing the order of the steps changes the output; so the sequence is stored as a whole. Thus, the result is achieved by dividing the pseudonym into subwords without making any corrections. This example shows the importance of the order of steps and verification.

How to tell if the preprocessing pipeline is broken? question is a concrete application of this subject. The solution is set up with these steps: Record the number of tokens for the same sample text. Remeasure the dictionary size and function word ratio. If there is a sudden change in values, review the last step. Repeat the test with texts of different lengths. Writing the conclusion with its justification enables the learned method to be carried to new situations. Thus, it is concluded that the sudden change in the indicators is a sign of error. This example shows the importance of the order of steps and verification.

Key Points

Worked Examples

Worked Example

Worked Example

Worked Example

Worked Example

Worked Example

Worked Example

Common Mistakes

Tips

Practice Questions

  1. 1. Which of the following options is the definition of the concept of «Tokenization»?
  2. 2. Which of the following options is the definition of the concept of "Normalization"?
  3. 3. Which of the following options is the definition of the concept «Function word»?
  4. 4. Which of the following options is the definition of the concept of "Root finding"?
  5. 5. Which of the following options is the definition of the concept of "Bodying"?
  6. 6. Which of the following options is the definition of the concept of «Subword division»?
  7. 7. Which of the following options is the definition of the concept of "Sentence division"?
  8. 8. Which of the following options is the definition of the concept of "reduction to lowercase"?
  9. 9. Which of the following options is the definition of the concept of «Coding normalization»?
  10. 10. Which of the following options is the definition of the concept of «Noise cleaning»?
  11. 11. Which of the following options is the definition of the concept of «Token»?
  12. 12. Which of the following options is the definition of the concept of "non-dictionary word"?
  13. 13. Which of the following options is the definition of the concept of «Fail-closed»?
  14. 14. Which of the following options is the definition of the concept of "Attribute control"?
  15. 15. "It is the process of dividing the text into meaningful units such as words or subwords." Which of the following concepts does the definition correspond to?
  16. 16. «It is the process of bringing different forms of writing into a single and coherent form.» Which of the following concepts does the definition correspond to?
  17. VOLUME 17 «It is an auxiliary word that occurs frequently and has low distinguishing power.» Which of the following concepts does the definition correspond to?
  18. 18. "It is a method of reaching the common root by removing the suffixes from the word." Which of the following concepts does the definition correspond to?
  19. 19. «It is the process of converting the word into its basic form in the dictionary.» Which of the following concepts does the definition correspond to?
  20. 20. «It meets non-dictionary words by dividing rare words into small parts.» Which of the following concepts does the definition correspond to?
  21. 21. «It creates boundaries for subsequent tasks by breaking the text into sentences.» Which of the following concepts does the definition correspond to?
  22. 22. «Matches words by removing the difference between uppercase and lowercase letters.» Which of the following concepts does the definition correspond to?
  23. 23. «It brings different coding forms of the same character into a single form.» Which of the following concepts does the definition correspond to?
  24. 24. «Removes unnecessary characters and formatting from the text.» Which of the following concepts does the definition correspond to?
  25. 25. «The result of division is a single text unit.» Which of the following concepts does the definition correspond to?
  26. 26 «It is a word that is not included in the predefined dictionary and requires special processing.» Which of the following concepts does the definition correspond to?
  27. 27 «In cases where it cannot be verified, it chooses to leave incomplete data instead of adding it.» Which of the following concepts does the definition correspond to?
  28. 28 «It is the review of preprocessing output on samples.» Which of the following concepts does the definition correspond to?
  29. 29 At which stage below is the «Tokenization» study carried out?
  30. 30 At which stage below is the «Normalization» study carried out?
  31. 31 At which stage below is the «function word» study carried out?
  32. 32 At which stage below is the «Root finding» study carried out?
  33. 33 At which stage below is the «Bodying» work carried out?
  34. 34 At which stage below is the «Subword division» study carried out?
  35. 35 At which stage below is the «Sentence division» exercise carried out?
  36. 36 At which stage below is the «reduction to lowercase letter» work carried out?
  37. 37 At which stage below is the «Coding normalization» study carried out?
  38. 38 At which stage below is the «Noise cleaning» work carried out?
  39. 39 At which stage below is the «Token» study carried out?
  40. 40 At which stage below is the «non-dictionary word» study carried out?

Source: Inspired by open curricula of Turkish universities; the explanation is written originally.

Kaynak: Türkiye üniversitelerinin açık ders planlarından esinlenilmiştir; anlatım özgün olarak yazılmıştır.