Giter Site home page Giter Site logo

e-hossam96 / nlp-spam-classification Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 14.21 MB

End to End NLP Pipeline for Spam Emails Classification

Jupyter Notebook 92.35% Python 4.23% CSS 1.78% HTML 1.64%
artificial-intelligence deep-learning deployment html5 machine-learning nlp nltk python tensorflow flask

nlp-spam-classification's Introduction

NLP Spam Classification

End to End NLP Pipeline for Spam Emails Classification

Introduction

Spam emails classification accounts for a a great deal of tasks in internet security. This raises the need for a perfect classifier to protect agents from malware attacks.
In this project we will be processing the email raw text and get insights about the key words that most spam emails share. For the sake of maximum security, we will use two frameworks to solve the problem, TensorFlow and NLTK, and average to combine the results.

NLP Techniques

NLTK Processes

Processing

In this section I have proceesed the data using the NLTK framework. First, I tokenized the messages using RegexpTokenizer. Then, I lemmatized them using WordNetLemmatizer. Lastly, I removed the stop words and produced the tokens in its useful form.

Feature Selection and Modeling

To select the most important tokens, I generated a token counter to count the frequencies of each token in the training dataset. Then, I kept only the tokens that was repeated more than 1000 times. Now that I have the features set, I defined a counts vector to store the frequencies of the features tokens in each message. Lastly, I trained a RandomForestClassifier and achieved 98% accuracy on the test set.

This section is found in the nltk_processing notebook.

TensorFlow Processes

Processing

The work is pretty much easier here. First, I fitted the Keras.preprocessing.text.Tokenizer on the training dataset and then padded the sequences using the keras.preprocessing.sequence.pad_sequences to produce inputs with equal lengths.

Modeling

I have constructed a simple DNN and fitted it on the data. The model achieved 99% accuracy on the validation datset.

This section is found in the tensorflow_processing notebook.

Models Deployment


webpage photo


Lastly, we used a simple webpage to deploy the models. We used the flask API to render the HTML webpage and provided the the index file with the data field result storing the results from the models and the probability for each model from the predict_spam function in the app file. For the sake of better visualization, we used a CSS style file to produce the webpage in its final version as seen above.

nlp-spam-classification's People

Contributors

e-hossam96 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.