Predict Hatred tweets from twitter using the dataset Twitter Sentiment Analysis.
This model uses deep convolutional layers with multichannel input layers.
- Load data as dataframe.
- Drop unrequired columns.
- Remove usernames from tweets.
- Remove #s.
- Remove emojies as it will not be recognisable by normal character.
- Fit the train data on a tokeniser to convert all the strings into numbers.
- Encode the strings in the dataset into numbers.
The ends of the sentences are padded with 0 (zero) to indicate the end of the string.
We use 1DConvolution layers for text classification.
- The first channel has a kernal size of 2.
- The second channel has a kernal size of 3.
- The third channel has a kernal size of 4.
- All outputs are concatenated.
- Dense layer is added.
- Dropout layer is added.
- Final output dense layer with one output class is added.
import pandas as pd
import numpy as np
import re
import tensorflow_datasets as tfds
import tensorflow as tf
from keras.preprocessing.sequence import pad_sequences as pad_seq
from keras.models import Model
from keras.layers import Input
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers import Dropout
from keras.layers import Embedding
from keras.layers.convolutional import Conv1D
from keras.layers.convolutional import MaxPooling1D
from keras.layers.merge import concatenate
import statistics
- Clone the repository
- Install dependencies
- Run the sentimentAnalysis.py
- Run predict.py to test results