Comptes de mots avec le sac de mots

Introduction au traitement du langage naturel en Python

Katharine Jarmul

Founder, kjamistan

Sac de mots

  • Méthode de base pour trouver des thèmes dans un texte
  • D'abord créer des jetons par tokenisation
  • ... puis compter tous les jetons
  • Plus un mot est fréquent, plus il peut être important
  • Utile pour repérer les mots significatifs d'un texte
Introduction au traitement du langage naturel en Python

Exemple de sac de mots

  • Texte : « The cat is in the box. The cat likes the box. The box is over the cat. »

  • Sac de mots (ponctuation retirée) :

    • « The » : 3, « box » : 3
    • « cat » : 3, « the » : 3
    • « is » : 2
    • « in » : 1, « likes » : 1, « over » : 1
Introduction au traitement du langage naturel en Python

Sac de mots en Python

from nltk.tokenize import word_tokenize

from collections import Counter
Counter(word_tokenize("""The cat is in the box. The cat likes the box. The box is over the cat."""))
Counter({'.': 3,
         'The': 3,
         'box': 3,
         'cat': 3,
         'in': 1,
         ...
         'the': 3})
counter.most_common(2)
[('The', 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...