<jupyter_start><jupyter_text>Seq to Seq attention based neural network model for abstractive text summarization  Import the modules<jupyter_code>import re
import operator
import numpy as np
import pandas as pd
import tensorflow as tf
import matplotlib.image as img
import matplotlib.pyplot as plt
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer as stemmer
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer

# inline matplotlib
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Implement text analysis functions to validate the summaries later<jupyter_code>class text_analyze:
    # init function
    def __init__(self, sentence_a, sentence_b):
        self.s_a = sentence_a
        self.s_b = sentence_b
    
    # tokenizer
    def tokenize(self, text):
        return re.split(r'[^0-9A-Za-z\-"_]+', text)
    
    # remove the stopwords
    def remove_stopwords(self, text):
        stmr = stemmer()
        stop_words = stopwords.words('english')
        return [w for w in [stmr.stem(words) for words in self.tokenize(text)] if w.lower() not in stop_words]
    
    # cosine similairty
    def similarity(self):
        vectorizer = TfidfVectorizer()
        sentences = tuple([' '.join(self.remove_stopwords(self.s_a))]) + tuple([' '.join(self.remove_stopwords(self.s_b))])
        matrix = vectorizer.fit_transform(sentences)
        return cosine_similarity(matrix[0:1], matrix)[0][1]<jupyter_output><empty_output><jupyter_text>Example of the model **Input** $(x_1,..........x_8)$. First sentence of the article:*Novell inc. chief executive chief office <NAME> has been named chairman of the internet search-engine company google.***Output** $(y_1,.........y_8)$. Generated sentence:*Novell chief executive named to head internet company*  The NNLM encoder The full model is:$p(y_i+1 | y_c, x;\theta) \propto exp(Vh + Wenc(x, y_c))$where $y_c = [Ey_{i-C+1},.....Ey_i],         h = \tanh(Uy_c)$<jupyter_code>def encoder(s):
    return True<jupyter_output><empty_output><jupyter_text>The NNLM decoder<jupyter_code>i = img.imread('1.png')

# remove all unecessary stuff and display the image
plt.rcParams['figure.figsize'] = (13, 13)
plt.axis('off')
plt.imshow(i)
def decoder(s):
    return False<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11602209944751381, 'fraction_numerical': 0.007224819379515512, 'mean_word_length': 4.3744292237442925, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '534270', 'license': 'MIT', 'n_tokens_mistral': 797, 'n_tokens_neox': 773, 'n_words': 204, 'path': 'text-summarization/tf_textsum.ipynb', 'repo_name': 'akhilpandey95/experiments', 'size': '2359'}