O'Reilly logo

Python Deep Learning Cookbook by Indra den Bakker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)): ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required