text_html_output_1.png
from nltk.corpus import stopwords

from nltk.stem import PorterStemmer

from tensorflow.keras.preprocessing.sequence import pad_sequences

from tensorflow.keras.preprocessing.text import one_hot

import pandas as pd

import re

df = pd.read_csv('/kaggle/input/covid19-india-news-headlines-for-nlp/raw_data.csv', usecols=['Headline', 'Sentiment', 'Description'])

df.shape

X = df.drop('Sentiment', axis=1)
Y = df['Sentiment']

messages = X.copy()

import re
import nltk
from nltk.stem import PorterStemmer
from nltk.corpus import stopwords
ps = PorterStemmer()
corpus = []
for i in range(len(messages)):
    review = re.sub('[^a-zA-Z]', ' ', messages['Headline'][i])
    review = review.lower()
    review = review.split()
    review = [ps.stem(word) for word in review if not word in stopwords.words('english')]
    review = ' '.join(review)
    corpus.append(review)

voc_size = 5000

onehot_repr = [one_hot(words, voc_size) for words in corpus]

sent_length = 20
embedded_docs = pad_sequences(onehot_repr, padding='pre', maxlen=sent_length)

embedded_docs