Prétraitement simple du texte

Introduction au traitement du langage naturel en Python

Katharine Jarmul

Founder, kjamistan

Pourquoi prétraiter ?

  • Améliore la qualité des données d'entrée
    • Pour le Machine Learning ou d'autres méthodes statistiques
  • Exemples :
    • Tokenisation pour créer un sac de mots
    • Mettre les mots en minuscules
  • Lemmatisation/Racinisation
    • Réduire les mots à leur racine
  • Retirer les mots vides, la ponctuation ou les jetons indésirables
  • Utile d'essayer différentes approches
Introduction au traitement du langage naturel en Python

Exemple de prétraitement

  • Texte d'entrée : Cats, dogs and birds are common pets. So are fish.

  • Jetons en sortie : cat, dog, bird, common, pet, fish

Introduction au traitement du langage naturel en Python

Prétraiter du texte avec Python

from nltk.corpus import stopwords
text = """The cat is in the box. The cat likes the box. 
                  The box is over the cat."""

tokens = [w for w in word_tokenize(text.lower()) if w.isalpha()]
no_stops = [t for t in tokens if t not in stopwords.words('english')]
Counter(no_stops).most_common(2)
[('cat', 3), ('box', 3)]
Introduction au traitement du langage naturel en Python

Passons à la pratique !

Introduction au traitement du langage naturel en Python

Preparing Video For Download...