text_processing_and_machine_learning_tal
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteDernière révisionLes deux révisions suivantes | ||
text_processing_and_machine_learning [2020/05/27 08:29] – [Text Processing and Machine Learning] serge | text_processing_and_machine_learning_tal [2020/12/27 15:02] – serge | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ======Text Processing and Machine Learning====== | + | ======Text Processing and Machine Learning |
- | + | <WRAP center round box 60% centeralign> | |
- | <WRAP center round box 80% centeralign> | + | **{{tagpage> |
- | **{{tagpage> | + | </ |
+ | <WRAP center round box 60% centeralign> | ||
+ | **[[les_pages_intelligence_artificielle_en_details|Les Pages Intelligence Artificielle en détails]]** | ||
</ | </ | ||
<WRAP center round box 80% centeralign> | <WRAP center round box 80% centeralign> | ||
- | **[[https:// | + | **{{tagpage> |
- | **[[https:// | + | |
</ | </ | ||
- | =====Définition===== | + | =====Définitions |
+ | === Text processing === | ||
+ | * **[[https:// | ||
+ | In computing, the term text processing refers to the theory and practice of automating the creation or manipulation of electronic text. | ||
+ | |||
+ | === TAL === | ||
+ | * **[[https:// | ||
Le traitement automatique du langage naturel (abr. TALN), ou traitement automatique de la langue naturelle1, ou encore traitement automatique des langues (abr. TAL) est un domaine multidisciplinaire impliquant la linguistique, | Le traitement automatique du langage naturel (abr. TALN), ou traitement automatique de la langue naturelle1, ou encore traitement automatique des langues (abr. TAL) est un domaine multidisciplinaire impliquant la linguistique, | ||
+ | ===== Ressources ===== | ||
+ | * [[https:// | ||
+ | En anglais, beaucoup de ressources, en particulier: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | |||
+ | https:// | ||
+ | ===== NLTK Natural Language Toolkit===== | ||
+ | **NLTK is a leading platform for building Python programs to work with human language data.** | ||
+ | |||
+ | ==== Ressources ==== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ==== Installation ==== | ||
+ | |||
+ | sudo pip3 install nltk | ||
+ | python3 | ||
+ | import nltk | ||
+ | nltk.download(' | ||
+ | nltk.download(' | ||
+ | nltk.download(' | ||
+ | nltk.download(' | ||
+ | nltk.download(' | ||
+ | nltk.download(' | ||
+ | |||
+ | =====Analyse du corpus avec NLTK sur un text simple===== | ||
+ | ====Récupérération de textes et exploration du corpus==== | ||
+ | |||
+ | ===En général=== | ||
+ | Le corpus sera soit une liste, un dictionnaire, | ||
+ | |||
+ | ===Exemple d' | ||
+ | * Chargement d'un html | ||
+ | * Récupération du texte voulu avec Beautifullsoup | ||
+ | |||
+ | <code python nltk_example.py> | ||
+ | # | ||
+ | |||
+ | import nltk | ||
+ | from nltk.corpus import treebank | ||
+ | |||
+ | raw = """ | ||
+ | Prince, l’unique objet du soin des Immortels, | ||
+ | Souffrez que mon encens parfume vos Autels. | ||
+ | Je vous offre un peu tard ces présents de ma Muse ; | ||
+ | """ | ||
+ | |||
+ | # ### Récupération d'un texte | ||
+ | # Tokenize the text | ||
+ | tokens = nltk.wordpunct_tokenize(raw) | ||
+ | print(f' | ||
+ | |||
+ | # Je ne garde que du 2ème mot au 30ème | ||
+ | tokens =tokens[2: | ||
+ | print(f' | ||
+ | |||
+ | # ### Normalizing 1 | ||
+ | # Création d'un NLTK Text | ||
+ | text = nltk.Text(tokens) | ||
+ | print(f' | ||
+ | # <Text: Bourgogne Prince , l ’ unique objet du...> | ||
+ | |||
+ | # Normalize the words | ||
+ | words = [w.lower() for w in text] | ||
+ | print(f' | ||
+ | |||
+ | # Build vocabulary (les mots sans la ponctuation, | ||
+ | vocab = sorted(set(words)) | ||
+ | print(f' | ||
+ | |||
+ | # ### Normalizing 2 | ||
+ | # Tous les mots sans exception | ||
+ | mots_brut = nltk.word_tokenize(raw) | ||
+ | print(f' | ||
+ | print(f' | ||
+ | |||
+ | # Sans la ponctuation et apostrophes | ||
+ | tokenizer = nltk.RegexpTokenizer(r' | ||
+ | bons_mots = tokenizer.tokenize(raw.lower()) | ||
+ | print(f' | ||
+ | print(f' | ||
+ | |||
+ | # Fréquence des mots, sans la ponctuation et apostrophes | ||
+ | tokenizer = nltk.RegexpTokenizer(r' | ||
+ | corpora = tokenizer.tokenize(raw.lower()) | ||
+ | freq = nltk.FreqDist(corpora) | ||
+ | print(f' | ||
+ | for k, v in freq.items(): | ||
+ | print(f' | ||
+ | |||
+ | # ### Some simple things you can do with NLTK | ||
+ | tokens = nltk.word_tokenize(raw) | ||
+ | tagged = nltk.pos_tag(tokens) | ||
+ | print(f' | ||
+ | |||
+ | # Identify named entities | ||
+ | entities = nltk.chunk.ne_chunk(tagged) | ||
+ | print(f' | ||
+ | |||
+ | # Display a parse tree: | ||
+ | t = treebank.parsed_sents(' | ||
+ | t.draw() | ||
+ | </ | ||
+ | |||
+ | <code text> | ||
+ | tokens: | ||
+ | [' | ||
+ | Texte: | ||
+ | [' | ||
+ | Texte: | ||
+ | <Text: Le Duc de Bourgogne Prince , l ’...> | ||
+ | words: nombre=28 | ||
+ | [' | ||
+ | vocab: nombre=27 | ||
+ | [',', | ||
+ | |||
+ | Tous les mots bruts = [' | ||
+ | Nombre de mots brut = 37 | ||
+ | |||
+ | Tous les bons mots = [' | ||
+ | Nombre de bons mots = 32 | ||
+ | |||
+ | Fréquence des mots dans le désordre: | ||
+ | à 1 | ||
+ | monseigneur 1 | ||
+ | le 1 | ||
+ | duc 1 | ||
+ | de 2 | ||
+ | bourgogne 1 | ||
+ | prince 1 | ||
+ | l 1 | ||
+ | etc ... | ||
+ | tagged[0:6] = [(' | ||
+ | entities = (S | ||
+ | À/JJ | ||
+ | (ORGANIZATION Monseigneur/ | ||
+ | de/IN | ||
+ | (PERSON Bourgogne/ | ||
+ | ,/, | ||
+ | l/NN | ||
+ | ’/NNP | ||
+ | unique/NN | ||
+ | objet/NN | ||
+ | du/NN | ||
+ | soin/NN | ||
+ | des/NNS | ||
+ | (PERSON Immortels/ | ||
+ | ,/, | ||
+ | (GPE Souffrez/ | ||
+ | que/NN | ||
+ | mon/NN | ||
+ | encens/VBZ | ||
+ | parfume/JJ | ||
+ | vos/NN | ||
+ | (PERSON Autels/NNP) | ||
+ | ./. | ||
+ | Je/NNP | ||
+ | vous/JJ | ||
+ | offre/NN | ||
+ | un/JJ | ||
+ | peu/NN | ||
+ | tard/NN | ||
+ | ces/VBZ | ||
+ | présents/ | ||
+ | de/IN | ||
+ | ma/NN | ||
+ | (ORGANIZATION Muse/NNP) | ||
+ | ;/:) | ||
+ | </ | ||
+ | {{ : | ||
+ | |||
+ | |||
+ | |||
+ | =====Apprentissage avec des Fables de La Fontaine===== | ||
+ | [[TAL Traitement Automatique du Langage avec des Fables de La Fontaine]] | ||
- | {{tag> | + | {{tag> ia python |
text_processing_and_machine_learning_tal.txt · Dernière modification : 2022/02/08 16:00 de serge