How to do it...

  1. We start by loading all the necessary libraries, as follows:
 import numpy as np import tensorflow as tf
  1. First, we load the text data:
article_filename = 'Data/summary/"Data/sumdata/train/train.article.txt'title_filename = 'Data/summary/"Data/sumdata/train/train.title.txt'with open(article_filename) as article_file: articles = article_file.readlines()with open(title_filename) as title_file: titles = title_file.readlines()
  1. To make our data readable for our model, we need to define a function that creates lookup tables for integers to vocabulary and vice versa:
def create_lookup_tables(text):    vocab = set(text.split())    vocab_to_int = {'<S>': 0, '<E>': 1, '<UNK>': 2, '<PAD>': 3 } for i, v in enumerate(vocab, len(vocab_to_int)): ...

Get Python Deep Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.