Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Optional Text Preprocessing Steps #267

Open
ertugrul-dmr opened this issue Apr 28, 2021 · 4 comments
Open

Adding Optional Text Preprocessing Steps #267

ertugrul-dmr opened this issue Apr 28, 2021 · 4 comments
Assignees
Labels
cleanup-stay Issues that won't be removed as part of cleanup enhancement New feature or request

Comments

@ertugrul-dmr
Copy link
Collaborator

Adding extra text pre-processing options might come in handy for different use cases and might improve our model performances on some datasets. These options can be implemented:

  • Removal of Emojis,
  • Removal of URLs,
  • Removal of HTML Tags,
  • Removal of Digits

Since these steps applied on raw strings before tokenization comes with another question, where shall we implement them? bblock.util.py maybe?

@ertugrul-dmr ertugrul-dmr added the enhancement New feature or request label Apr 28, 2021
@husnusensoy
Copy link
Contributor

Can you send the snippet used for each. I believe they can be added as tokenizer exception rules

@ertugrul-dmr
Copy link
Collaborator Author

Emoji Removal:

import re
def remove_emoji(string):
    emoji_pattern = re.compile("["
                           u"\U0001F600-\U0001F64F"  # emoticons
                           u"\U0001F300-\U0001F5FF"  # symbols & pictographs
                           u"\U0001F680-\U0001F6FF"  # transport & map symbols
                           u"\U0001F1E0-\U0001F1FF"  # flags (iOS)
                           u"\U00002702-\U000027B0"
                           u"\U000024C2-\U0001F251"
                           "]+", flags=re.UNICODE)
    return emoji_pattern.sub(r'', string)

Text:
remove_emoji("bugün forvetler 🔥🔥")
Output:
bugün forvetler

Text:
remove_emoji("Komedi😂")
Output:
Komedi

URL Removal:

import re
def remove_urls(string):
    url_pattern = re.compile(r'https?://\S+|www\.\S+')
    return url_pattern.sub(r'', string)

Text:
remove_urls('Şu adresten bulabilirsin: https://www.imdb.com/title/tt0050083/')
Output:
Şu adresten bulabilirsin:

HTML Tags Removal:

import re

def remove_html(string):
    html_pattern = re.compile('<.*?>')
    return html_pattern.sub(r'', string)

text = """                </span>
            </div>
        </div>                                   
    </div>
      </div>              
  <script>
    if ('csm' in window) {
      csm.measure('csm_TitleReviewsAndPopularityWidget_finished');
    }
  </script>
    </div>"""

remove_html(text)
Output:

                
            
                                           
    
                    
  
    if ('csm' in window) {
      csm.measure('csm_TitleReviewsAndPopularityWidget_finished');
    }


Digit Removal:

import re

def remove_digit(string):    
    return re.sub(r'\d+', '', string)

Text:
remove_digit('20 kişi saat 12 gibi geldi')
Output:
kişi saat gibi geldi

@dafajon
Copy link
Contributor

dafajon commented Dec 7, 2021

@ertugrul-dmr Is there any work or PR on this? If not, let's prioritize this for the release after the next one.

@askarbozcan askarbozcan added the cleanup-stay Issues that won't be removed as part of cleanup label Aug 14, 2022
@askarbozcan
Copy link
Member

Note to self: Should be done in a general way, allowing users to add their own custom preprocessing steps if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup-stay Issues that won't be removed as part of cleanup enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants