Preprocessing
Performing text cleaning using clean_amharic function and preprocessing module:
- it provides a solid pipeline to clean and represent text data.
1. Text Cleaning using clean_amharic function
from etltk.lang.am import clean_amharic
sample_text = """
ሚያዝያ 14፣ 2014 ዓ.ም 🤗 በአገር ደረጃ የሰው ሰራሽ አስተውሎት /Artificial Intelligence/ አሁን ካለበት ዝቅተኛ ደረጃ ወደ ላቀ ደረጃ ለማድረስ፣ ሃገርኛ ቋንቋዎችን ለዓለም ተደራሽ ለማድረግ፣ አገራዊ አቅምን ለማሳደግ እና ተጠቃሚ ለመሆን በጋራ አብሮ መስራቱ እጅግ ጠቃሚ ነው፡፡
በማሽን ዓስተምሮ (Machine Learning) አማካኝነት የጽሁፍ ናሙናዎች በአርቲፊሻል ኢንተለጀንስ ሥርዓት ለማሰልጠን፣ የጽሁፍ ዳታን መሰብሰብ እና ማደራጀት፤ የናቹራል ላንጉዌጅ ፕሮሰሲንግ ቱሎችን /Natural Language Processing Tools/ በመጠቀም የጽሁፍ ዳታን ፕሮሰስ ማድረግ ተቀዳሚ እና መሰረታዊ ጉዳይ ነው።
"""
# `clean_amharic` function uses the default pipeline to clean text
cleaned = clean_amharic(input_text)
# print the `clean` text:
print(cleaned)
# output: ሚያዝያ ዓመተ ምህረት በአገር ደረጃ የሰው ሰራሽ አስተውሎት አሁን ካለበት ዝቅተኛ ደረጃ ወደ ላቀ ደረጃ ለማድረስ ሀገርኛ ቋንቋዎችን ለአለም ተደራሽ ለማድረግ አገራዊ አቅምን ለማሳደግ እና ተጠቃሚ ለመሆን በጋራ አብሮ መስራቱ እጅግ ጠቃሚ ነው በማሽን አስተምሮ አማካኝነት የፅሁፍ ናሙናዎች በአርቲፊሻል ኢንተለጀንስ ስርአት ለማሰልጠን የፅሁፍ ዳታን መሰብሰብ እና ማደራጀት የናቹራል ላንጉዌጅ ፕሮሰሲንግ ቱሎችን በመጠቀም የፅሁፍ ዳታን ፕሮሰስ ማድረግ ተቀዳሚ እና መሰረታዊ ጉዳይ ነው
The default pipeline for the clean_amharic method is the following:
remove_links()Replace all URLs.remove_tags()Lowercase all HTML tags.remove_emojis()Remove all emojis.remove_special_characters()Remove all special characters (弫¥ª°©ð±§µæ¹¢³¿®ä£"”“`‘´’‚,„»«「」『』()〔〕【】《》〈〉).remove_digits()Remove all blocks of digits.remove_ethiopic_digits()Remove ethiopic number.remove_english_chars()Remove all english characters.remove_arabic_chars()Remove all arabic characters.remove_chinese_chars()Remove all chinese characters.normalize_punct()Normalizes ethiopic punctuations.normalize_shortened()Expands all short form.remove_punct()Remove all string.punctuation and ethiopic punctuations (፠ ፡ ። ፣ ፤ ፥ ፦ ፧ ፨).remove_whitespaces()Remove all white space between words.
2. Text Cleaning using a custom pipeline as argument to clean
- We can also pass a custom pipeline as argument to
clean_amharicfunction
from etltk.lang.am import (
preprocessing,
clean_amharic
)
sample_text = """
ሚያዝያ 14፣ 2014 ዓ.ም 🤗 በአገር ደረጃ የሰው ሰራሽ አስተውሎት /Artificial Intelligence/ አሁን ካለበት ዝቅተኛ ደረጃ ወደ ላቀ ደረጃ ለማድረስ፣ ሃገርኛ ቋንቋዎችን ለዓለም ተደራሽ ለማድረግ፣ አገራዊ አቅምን ለማሳደግ እና ተጠቃሚ ለመሆን በጋራ አብሮ መስራቱ እጅግ ጠቃሚ ነው፡፡
በማሽን ዓስተምሮ (Machine Learning) አማካኝነት የጽሁፍ ናሙናዎች በአርቲፊሻል ኢንተለጀንስ ሥርዓት ለማሰልጠን፣ የጽሁፍ ዳታን መሰብሰብ እና ማደራጀት፤ የናቹራል ላንጉዌጅ ፕሮሰሲንግ ቱሎችን /Natural Language Processing Tools/ በመጠቀም የጽሁፍ ዳታን ፕሮሰስ ማድረግ ተቀዳሚ እና መሰረታዊ ጉዳይ ነው።
"""
# Define a custom preprocessor pipeline
custom_pipeline = [
preprocessing.remove_emojis,
preprocessing.remove_digits,
preprocessing.remove_ethiopic_punct,
preprocessing.remove_english_chars,
preprocessing.remove_punct
]
# `clean_amharic` function takes a custom pipeline, if not uses the default pipeline
cleaned = clean_amharic(input_text, abbrev=False, pipeline=custom_pipeline)
# print the `clean` text:
print(cleaned)
# output: ሚያዝያ ዓመተ ምህረት በአገር ደረጃ የሰው ሰራሽ አስተውሎት አሁን ካለበት ዝቅተኛ ደረጃ ወደ ላቀ ደረጃ ለማድረስ ሀገርኛ ቋንቋዎችን ለአለም ተደራሽ ለማድረግ አገራዊ አቅምን ለማሳደግ እና ተጠቃሚ ለመሆን በጋራ አብሮ መስራቱ እጅግ ጠቃሚ ነው በማሽን አስተምሮ አማካኝነት የፅሁፍ ናሙናዎች በአርቲፊሻል ኢንተለጀንስ ስርአት ለማሰልጠን የፅሁፍ ዳታን መሰብሰብ እና ማደራጀት የናቹራል ላንጉዌጅ ፕሮሰሲንግ ቱሎችን በመጠቀም የፅሁፍ ዳታን ፕሮሰስ ማድረግ ተቀዳሚ እና መሰረታዊ ጉዳይ ነው
Preprocessing API
The complete preprocessing API can be found at the following address: preprocessing functions