<jupyter_start><jupyter_text>***GRU - Gated Recurrent Unit***<jupyter_code>!wget --no-check-certificate \
    https://storage.googleapis.com/laurencemoroney-blog.appspot.com/sarcasm.json 
   
  
import json
import tensorflow as tf
import numpy as np

with open("sarcasm.json", 'r') as f:
    datastore = json.load(f)


sentences = [] 
labels = []
urls = []
for item in datastore:
    sentences.append(item['headline'])
    labels.append(item['is_sarcastic'])
    urls.append(item['article_link'])

traning_labels=np.array(labels)

from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
tokenizer = Tokenizer(oov_token="<OOV>")
tokenizer.fit_on_texts(sentences)

word_index = tokenizer.word_index
print(len(word_index))
print(word_index)
sequences = tokenizer.texts_to_sequences(sentences)
padded = pad_sequences(sequences, padding='post')
print(padded[0])
print(padded.shape)<jupyter_output><empty_output><jupyter_text>**Using TF 2 version**<jupyter_code>model = tf.keras.Sequential([
    tf.keras.layers.Embedding(30000, 64, input_length=40),
    tf.keras.layers.Bidirectional(tf.keras.layers.GRU(32)),
    #tf.keras.layers.Dense(6, activation='relu'),
    tf.keras.layers.Dense(1, activation='sigmoid')
])
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
history = model.fit(padded, traning_labels, epochs=1,batch_size =100)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14354395604395603, 'fraction_numerical': 0.01304945054945055, 'mean_word_length': 6.588541666666667, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '659457', 'license': 'MIT', 'n_tokens_mistral': 548, 'n_tokens_neox': 524, 'n_words': 74, 'path': 'NLP/GRU_NLP.ipynb', 'repo_name': 'devaraj01/deep_learning', 'size': '1456'}