Skip to content

thushv89/packt_nlp_tensorflow_2

Repository files navigation

Natural Language Processing with TensorFlow-2nd-Edition

Copyright © 2022 Packt Publishing, Thushan Ganegedara


This project is the code repository for Natural Language Processing with TensorFlow, Second Edition.

Getting Started

You can run these notebooks on cloud platforms like Google Colab or your local machine. Note that some chapters require a GPU to run in a reasonable amount of time, so we recommend one of the cloud platforms as they come pre-installed with CUDA.

Chapters Colab Kaggle Gradient StudioLab
Understanding TensorFlow 2
  • tensorflow_introduction.ipynb
Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Word2vec – Learning Word Embeddings
  • ch3_word2vec.ipynb
  • ch3_wordnet.ipynb
Open In Colab Open In Colab Kaggle Kaggle Gradient Gradient Open In SageMaker Studio Lab Open In SageMaker Studio Lab
Advanced Word Vector Algorithms
  • ch4_document_classification.ipynb
  • ch4_elmo_embeddings.ipynb
  • ch4_glove.ipynb
Open In Colab Open In Colab Open In Colab Kaggle Kaggle Kaggle Gradient Gradient Gradient Open In SageMaker Studio Lab Open In SageMaker Studio Lab Open In SageMaker Studio Lab
Sentence Classification with Convolution Neural Networks
  • ch5_cnn_sentence_classification.ipynb
  • ch5_image_classification_fashion_mnist.ipynb
Open In Colab Open In Colab Kaggle Kaggle Gradient Gradient Open In SageMaker Studio Lab Open In SageMaker Studio Lab
Recurrent Neural Networks
  • ch06_rnns_for_named_entity_recognition.ipynb
Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Applications of LSTM – Generating Text
  • ch08_lstms_for_text_generation.ipynb
Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Sequence-to-Sequence Learning – Neural Machine Translation
  • ch09_seq2seq.ipynb
Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Transformers
  • ch10_transformers.ipynb
Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Image captioning with Transformers
  • ch11_image_captions.ipynb
Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Appendix
  • tensorboard_word_embeddings.ipynb
Open In Colab Kaggle Gradient Open In SageMaker Studio Lab

Prerequisites for running the notebooks on your local machine(GPU support)

  • Install the latest NVIDIA driver for your GPU from this page
  • Install CUDA 10.2 (TensorFlow 2.3)
  • Setup CuDNN
  • Make sure your $PATH variable contains the path to the bin folder of cuda (e.g. On Windows - C:\CUDA\v10.2\bin)
    • On UNIX - Set LD_LIBRARY_PATH to lib64 folder (e.g. /usr/local/cuda-10.2/lib64)

Creating a Virtual Environment (Anaconda) (Recommended)

  • Install Anaconda
  • Open up Anaconda Prompt
  • Setup a conda virtual environment with conda create -n packt.nlp.2 python=3.6
  • Activate the environment with conda activate packt.nlp.tf2
  • Install the required libraries using pip install -r requirements.txt

Important notes

  • For some plotting capability provided in TensorFlow/Keras, you have installed a Python package called graphviz. You might need to add the path to this library (e.g. <path to Anaconda>\envs\packt.nlp.tf2\Library\bin\graphviz if you used Anaconda installation)

Getting Jupyter Notebook server up

Now you are ready to run the Jupyter notebook server, allowing you to run the notebooks provided in the code repository.

  • Open up the command line terminal and activate the virtual environment packt.nlp.tf2 if you haven't already
  • Go in to the directory you downloaded code to using cd in the CLI (e.g. cd C:\Users\<user>\Documents\code\packt_nlp_tensorflow_2)
  • Run jupyter notebook in the CLI
  • This should open up the jupyter notebook server's landing page on your default browser
  • Now you can navigate the folder structure within that directory, open any notebook and run it.