Skip to content

Instantly share code, notes, and snippets.

@AyishaR
Created February 19, 2021 07:01
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/4b4d8f31e0ed97a7203ed06f98d8addd to your computer and use it in GitHub Desktop.
Save AyishaR/4b4d8f31e0ed97a7203ed06f98d8addd to your computer and use it in GitHub Desktop.
x = np.random.randint(0, Xval.shape[0] - 1)
headline = df['headline'].values[x]
print("Headline: ", headline)
cleaned_text = []
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_text.append(stemmed)
cleaned_text = [' '.join(cleaned_text)]
print("Cleaned text: ", cleaned_text[0])
cleaned_text = tokenizer.texts_to_sequences(cleaned_text)
cleaned_text = pad_sequences(cleaned_text, maxlen=mlen)
category = df['is_sarcastic'].values[x]
print("\nTrue category: ", class_names[category])
output = model.predict(cleaned_text)[0][0]
pred = (output>0.5).astype('int64')
print("\nPredicted category: ", class_names[pred], "(", output, "-->", pred, ")")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment