Tracer la longueur des mots avec nltk

Introduction au traitement du langage naturel en Python

Katharine Jarmul

Founder, kjamistan

Premiers pas avec matplotlib

  • Bibliothèque de graphiques utilisée par de nombreux projets Python libres
  • Fonctionnalités simples avec de nombreuses options
    • Histogrammes
    • Diagrammes à barres
    • Graphiques linéaires
    • Nuages de points
  • ... et aussi des fonctions avancées comme les graphes 3D et les animations !
Introduction au traitement du langage naturel en Python

Tracer un histogramme avec matplotlib

from matplotlib import pyplot as plt

plt.hist([1, 5, 5, 7, 7, 7, 9])
(array([ 1., 0., 0., 0., 0., 2., 0., 3., 0., 1.]),
 array([ 1., 1.8, 2.6, 3.4, 4.2, 5., 5.8, 6.6, 7.4, 8.2, 9.]),
        <a list of 10 Patch objects>)
plt.show()
Introduction au traitement du langage naturel en Python

Histogramme généré

histogramme

Introduction au traitement du langage naturel en Python

Combiner l'extraction de données NLP et le tracé

from matplotlib import pyplot as plt
from nltk.tokenize import word_tokenize

words = word_tokenize("This is a pretty cool tool!")
word_lengths = [len(w) for w in words]
plt.hist(word_lengths)
(array([ 2., 0., 1., 0., 0., 0., 3., 0., 0., 1.]),
 array([ 1., 1.5, 2., 2.5, 3., 3.5, 4., 4.5, 5., 5.5, 6.]),
        <a list of 10 Patch objects>)
plt.show()
Introduction au traitement du langage naturel en Python

Histogramme de longueur de mots

histogramme de longueur de mots

Introduction au traitement du langage naturel en Python

Passons à la pratique !

Introduction au traitement du langage naturel en Python

Preparing Video For Download...