Devoir de Surveillance - Natural Language Processing

1/3
100%

DEVOIR DE SURVEILLANCE

MODULE : NATURAL LANGUAGE

PROCESSING

NIVEAU : MASTER BADS 2

DURÉE : 1H30

RESPONSABLE : WAEL OUARDA DOCUMENTS AUTORISÉS

Partie I – Web Scraping des données (3 points)

1) scrapy – requests – beautiful soup - selenium

2) Les paramètres à vérifier après la collecte de la base de données pour valider

L’échantillon :

Data.info() : pour vérifier le nombre des colonnes et leurs types , les colonnes non nul c’est-à-dire la description des data pour savoir comment faire le nettoyage des données après, on peut utiliser data.head() pour afficher le début de données et sa représentation

Partie II- Prétraitement des données (7 points)

1) Les problèmes qu’on peut rencontrer :1- avoir des caractères spéciaux, 2-des ponctuations, 3-des majuscules , 4-des problèmes d’orthographe 5- des verbes conjugués 6- types de données

2) On peut utiliser les fonctions de la bibliothèque NTLK pour corriger ces problèmes et NLTK et re(regular expression).

3)

a- features=["Hello ? are you here my freind ! I am looking for help pleeeeeeeease ϑ ϑ",

"Urgent ! We are in very serious problem",

"Tunisie is the most beautiful cpuntry hahaha",

"Lets work together for more benefits my dear colleague"]

Publicité

for sentence in range(0, len(features)):

Remove all the special characters

tidy\_feature = re.sub(r'\W', ' ', str(features[sentence]))

print(tidy\_feature)

remove all single characters: espace + Charcater + Espace Bonjour a my

tidy\_feature= re.sub(r'\s+[a-zA-Z]\s+', ' ', tidy\_feature)

print(tidy\_feature)

remove all single characters: espace + Charcater + Espace Bonjour a my

tidy\_feature= re.sub(r'\s+[^0-9]\s+', ' ', tidy\_feature)

print(tidy\_feature)

Substituting multiple spaces with single space

tidy\_feature = re.sub(r'\s+', ' ', tidy\_feature, flags=re.I)

print(tidy\_feature)

Subtituting a prefexied @ with ''

tidy\_feature = re.sub(r'^@\s+', '', tidy\_feature)

print(tidy\_feature)

Subtituting a prefexied @ with ''

tidy\_feature = re.sub(r'\d+', '', tidy\_feature)

print(tidy\_feature)

Publicité

tidy\_feature = tidy\_feature.lower()

print(tidy\_feature)

tidy\_features.append(tidy\_feature)

print(tidy\_feature)

print ("\\\\\\ Tidy Features \\\\\\\\")

print(tidy\_features)

resultat :

Hello are you here my freind I am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

hello are you here my freind am looking for help pleeeeeeeease

hello are you here my freind am looking for help pleeeeeeeease

Urgent We are in very serious problem

Urgent We are in very serious problem

Urgent We are in very serious problem

Urgent We are in very serious problem

Publicité

Urgent We are in very serious problem

Urgent We are in very serious problem

urgent we are in very serious problem

urgent we are in very serious problem

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

tunisie is the most beautiful cpuntry hahaha

tunisie is the most beautiful cpuntry hahaha

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

lets work together for more benefits my dear colleague

Publicité

lets work together for more benefits my dear colleague

\\\\\\ Tidy Features \\\\\\\\

['hello are you here my freind am looking for help pleeeeeeeease ', 'urgent we are in very serious problem', 'tunisie is the most beautiful cpuntry hahaha', 'lets work together for more benefits my dear colleague']

b- des mots sans aucune signification

Partie III- Représentation des données (7 points)

Le TF-IDF est une méthode d’analyse qui peut être utilisée dans une stratégie de référencement pour déterminer les mots-clés et les termes qui augmentent la pertinence des textes publiés et donc du projet Web dans son ensemble. C'est une formule dans laquelle les deux valeurs TF (Term Frequency) et IDF (Inverse Document Frequency) sont multipliées entre elles. Le résultat est la fréquence relative des termes (ou « pondération des termes ») d’un document par rapport à tous les autres documents Web qui contiennent également le mot-clé en question lors de l’analyse. Avant de pouvoir effectuer l’analyse TF-IDF, les deux facteurs mentionnés doivent d’abord être déterminés.

id1- Friend , look , help, pleeeeeeeease

id2- Urgent , Serious , problem

id3- Tunisie , beautiful ,cpuntry

id4- Work, together, benefits ,dear,colleague

N=15:nombre des mots distinct

TF-IDF(Friend,id1)=tf(friend,id1)\log(15/1+1)=1\log(15/2)

TF-IDF(look,id1)=tf(look,id1)\log(15/1+1)=1\log(15/2)

TF-IDF(help,id1)=tf(help,id1)\log(15/1+1)=1\log(15/2)

TF-IDF(Urgent,id2)=tf(Urgent,id2)\log(15/1+1)=1\log(15/2)

TF-IDF(Serious,id2)=tf(Serious,id2)\log(15/1+1)=1\log(15/2)

TF-IDF(Tunisie,id3)=tf(Tunisie,id3)\log(15/1+1)=1\log(15/2)

Partie IV- Classification des annonces textuelles (3 points)

Devoir de Surveillance - Natural Language Processing

Natural Language Processing · exam

Voir tous les documents en intelligence artificielle et données

DEVOIR DE SURVEILLANCE

MODULE : NATURAL LANGUAGE

PROCESSING

NIVEAU : MASTER BADS 2

DURÉE : 1H30

RESPONSABLE : WAEL OUARDA DOCUMENTS AUTORISÉS

Partie I – Web Scraping des données (3 points)

1) scrapy – requests – beautiful soup - selenium

2) Les paramètres à vérifier après la collecte de la base de données pour valider

L’échantillon :

Data.info() : pour vérifier le nombre des colonnes et leurs types , les colonnes non nul c’est-à-dire la description des data pour savoir comment faire le nettoyage des données après, on peut utiliser data.head() pour afficher le début de données et sa représentation

Partie II- Prétraitement des données (7 points)

1) Les problèmes qu’on peut rencontrer :1- avoir des caractères spéciaux, 2-des ponctuations, 3-des majuscules , 4-des problèmes d’orthographe 5- des verbes conjugués 6- types de données

2) On peut utiliser les fonctions de la bibliothèque NTLK pour corriger ces problèmes et NLTK et re(regular expression).

3)

a- features=["Hello ? are you here my freind ! I am looking for help pleeeeeeeease ϑ ϑ",

"Urgent ! We are in very serious problem",

"Tunisie is the most beautiful cpuntry hahaha",

"Lets work together for more benefits my dear colleague"]

Publicité

for sentence in range(0, len(features)):

Remove all the special characters

tidy\_feature = re.sub(r'\W', ' ', str(features[sentence]))

print(tidy\_feature)

remove all single characters: espace + Charcater + Espace Bonjour a my

tidy\_feature= re.sub(r'\s+[a-zA-Z]\s+', ' ', tidy\_feature)

print(tidy\_feature)

remove all single characters: espace + Charcater + Espace Bonjour a my

tidy\_feature= re.sub(r'\s+[^0-9]\s+', ' ', tidy\_feature)

print(tidy\_feature)

Substituting multiple spaces with single space

tidy\_feature = re.sub(r'\s+', ' ', tidy\_feature, flags=re.I)

print(tidy\_feature)

Subtituting a prefexied @ with ''

tidy\_feature = re.sub(r'^@\s+', '', tidy\_feature)

print(tidy\_feature)

Subtituting a prefexied @ with ''

tidy\_feature = re.sub(r'\d+', '', tidy\_feature)

print(tidy\_feature)

Publicité

tidy\_feature = tidy\_feature.lower()

print(tidy\_feature)

tidy\_features.append(tidy\_feature)

print(tidy\_feature)

print ("\\\\\\ Tidy Features \\\\\\\\")

print(tidy\_features)

resultat :

Hello are you here my freind I am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

Hello are you here my freind am looking for help pleeeeeeeease

hello are you here my freind am looking for help pleeeeeeeease

hello are you here my freind am looking for help pleeeeeeeease

Urgent We are in very serious problem

Urgent We are in very serious problem

Urgent We are in very serious problem

Urgent We are in very serious problem

Publicité

Urgent We are in very serious problem

Urgent We are in very serious problem

urgent we are in very serious problem

urgent we are in very serious problem

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

Tunisie is the most beautiful cpuntry hahaha

tunisie is the most beautiful cpuntry hahaha

tunisie is the most beautiful cpuntry hahaha

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

Lets work together for more benefits my dear colleague

lets work together for more benefits my dear colleague

Publicité

lets work together for more benefits my dear colleague

\\\\\\ Tidy Features \\\\\\\\

['hello are you here my freind am looking for help pleeeeeeeease ', 'urgent we are in very serious problem', 'tunisie is the most beautiful cpuntry hahaha', 'lets work together for more benefits my dear colleague']

b- des mots sans aucune signification

Partie III- Représentation des données (7 points)

Le TF-IDF est une méthode d’analyse qui peut être utilisée dans une stratégie de référencement pour déterminer les mots-clés et les termes qui augmentent la pertinence des textes publiés et donc du projet Web dans son ensemble. C'est une formule dans laquelle les deux valeurs TF (Term Frequency) et IDF (Inverse Document Frequency) sont multipliées entre elles. Le résultat est la fréquence relative des termes (ou « pondération des termes ») d’un document par rapport à tous les autres documents Web qui contiennent également le mot-clé en question lors de l’analyse. Avant de pouvoir effectuer l’analyse TF-IDF, les deux facteurs mentionnés doivent d’abord être déterminés.

id1- Friend , look , help, pleeeeeeeease

id2- Urgent , Serious , problem

id3- Tunisie , beautiful ,cpuntry

id4- Work, together, benefits ,dear,colleague

N=15:nombre des mots distinct

TF-IDF(Friend,id1)=tf(friend,id1)\log(15/1+1)=1\log(15/2)

TF-IDF(look,id1)=tf(look,id1)\log(15/1+1)=1\log(15/2)

TF-IDF(help,id1)=tf(help,id1)\log(15/1+1)=1\log(15/2)

TF-IDF(Urgent,id2)=tf(Urgent,id2)\log(15/1+1)=1\log(15/2)

TF-IDF(Serious,id2)=tf(Serious,id2)\log(15/1+1)=1\log(15/2)

TF-IDF(Tunisie,id3)=tf(Tunisie,id3)\log(15/1+1)=1\log(15/2)

Partie IV- Classification des annonces textuelles (3 points)