Skip to content

Instantly share code, notes, and snippets.

@AyishaR
Created February 19, 2021 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyishaR/1a9b3e4e3032ce1381da2089b6332681 to your computer and use it in GitHub Desktop.
Save AyishaR/1a9b3e4e3032ce1381da2089b6332681 to your computer and use it in GitHub Desktop.
sno = nltk.stem.SnowballStemmer('english') # Initializing stemmer
wordcloud = [[], []]
all_sentences = [] # All cleaned sentences
for x in range(len(df['headline'].values)):
headline = df['headline'].values[x]
sarcasm = df['is_sarcastic'].values[x]
cleaned_sentence = []
sentence = removeURL(headline)
sentence = removeHTML(sentence)
sentence = onlyAlphabets(sentence)
sentence = sentence.lower()
for word in sentence.split():
#if word not in stop:
stemmed = sno.stem(word)
cleaned_sentence.append(stemmed)
wordcloud[sarcasm].append(word)
all_sentences.append(' '.join(cleaned_sentence))
# add as column in dataframe
X = all_sentences
y = df['is_sarcastic']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment