Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Natural Language Processing with TensorFlow - Second Edition

You're reading from  Natural Language Processing with TensorFlow - Second Edition

Product type Book
Published in Jul 2022
Publisher Packt
ISBN-13 9781838641351
Pages 514 pages
Edition 2nd Edition
Languages
Author (1):
Thushan Ganegedara Thushan Ganegedara
Profile icon Thushan Ganegedara

Table of Contents (15) Chapters

Preface 1. Introduction to Natural Language Processing 2. Understanding TensorFlow 2 3. Word2vec – Learning Word Embeddings 4. Advanced Word Vector Algorithms 5. Sentence Classification with Convolutional Neural Networks 6. Recurrent Neural Networks 7. Understanding Long Short-Term Memory Networks 8. Applications of LSTM – Generating Text 9. Sequence-to-Sequence Learning – Neural Machine Translation 10. Transformers 11. Image Captioning with Transformers 12. Other Books You May Enjoy
13. Index
Appendix A: Mathematical Foundations and Advanced TensorFlow

Introduction to the technical tools

In this section, you will be introduced to the technical tools that will be used in the exercises of the following chapters. First, we will present a brief introduction to the main tools provided. Next, we will present a rough guide on how to install each tool along with hyperlinks to detailed guides provided by the official websites. Additionally, we will share tips on how to make sure that the tools were installed properly.

Description of the tools

We will use Python as the coding/scripting language. Python is a very versatile, easy-to-set-up coding language that is heavily used by the scientific and machine learning communities.

Additionally, there are numerous scientific libraries built for Python, catering to areas ranging from deep learning to probabilistic inference to data visualization. TensorFlow is one such library that is well known among the deep learning community, providing many basic and advanced operations that are useful for deep learning. Next, we will use Jupyter Notebook in all our exercises as it provides a rich and interactive environment for coding compared to using Python scripts. We will also use pandas, NumPy and scikit-learn — three popular — two popular libraries for Python—for various miscellaneous purposes such as data preprocessing. Another library we will be using for various text-related operations is NLTK—the Python Natural Language Toolkit. Finally, we will use Matplotlib for data visualization.

Installing Anaconda and Python

Python is hassle-free to install in any of the commonly used operating systems, such as Windows, macOS, or Linux. We will use Anaconda to set up Python, as it does all the laborious work for setting up Python as well as the essential libraries.

To install Anaconda, follow these steps:

  1. Download Anaconda from https://www.continuum.io/downloads
  2. Select the appropriate OS and download Python 3.7
  3. Install Anaconda by following the instructions at https://docs.continuum.io/anaconda/install/

To check whether Anaconda was properly installed, open a Terminal window (Command Prompt in Windows), and then run the following command:

conda --version

If installed properly, the version of the current Anaconda distribution should be shown in the Terminal.

Creating a Conda environment

One of the attractive features of Anaconda is that it allows you to create multiple Conda, or virtual, environments. Each Conda environment can have its own environment variables and Python libraries. For example, one Conda environment can be created to run TensorFlow 1.x, whereas another can run TensorFlow 2.x. This is great because it allows you to separate your development environments from any changes taking place in the host’s Python installation. Then, you can activate or deactivate Conda environments depending on which environment you want to use.

To create a Conda environment, follow these instructions:

  1. Run Conda and create -n packt.nlp.2 python=3.7 in the terminal window using the command conda create -n packt.nlp.2 python=3.7.
  2. Change directory (cd) to the project directory.
  3. Activate the new Conda environment by entering activate packt.nlp.2 in the terminal. If successfully activated, you should see (packt.nlp.2) appearing before the user prompt in the terminal.
  4. Install the required libraries using one of the following options.
  5. If you have a GPU, use pip install -r requirements-base.txt -r requirements-tf-gpu.txt
  6. If you do not have a GPU, use pip install -r requirements-base.txt -r requirements-tf.txt

Next, we’ll discuss some prerequisites for GPU support for TensorFlow.

TensorFlow (GPU) software requirements

If you are using the TensorFlow GPU version, you will need to satisfy certain software requirements such as installing CUDA 11.0. An exhaustive list is available at https://www.tensorflow.org/install/gpu#software_requirements.

Accessing Jupyter Notebook

After running the pip install command, you should have Jupyter Notebook available in the Conda environment. To check whether Jupyter Notebook is properly installed and can be accessed, follow these steps:

  1. Open a Terminal window.
  2. Activate the packt.nlp.2 Conda environment if it is not already by running activate packt.nlp.2
  3. Run the command: jupyter notebook

You should be presented with a new browser window that looks like Figure 1.6:

C:\Users\gauravg\Desktop\14070\CH01\B08681_01_06.png

Figure 1.6: Jupyter Notebook installed successfully

Verifying the TensorFlow installation

In this book, we are using TensorFlow 2.7.0. It is important that you install the exact version used in the book as TensorFlow can undergo many changes while migrating from one version to the other. TensorFlow should be installed in the packt.nlp.2 Conda environment if everything went well. If you are having trouble installing TensorFlow, you can find guides and troubleshooting instructions at https://www.tensorflow.org/install.

To check whether TensorFlow installed properly, follow these steps:

  1. Open Command Prompt in Windows or Terminal in Linux or macOS.
  2. Activate the packt.nlp.2 Conda environment.
  3. Type python to enter the Python prompt. You should now see the Python version right below. Make sure that you are using Python 3.
  4. Next, enter the following commands:
    import tensorflow as tf 
    print(tf. version )
    

If all went well, you should not have any errors (there might be warnings if your computer does not have a dedicated GPU, but you can ignore them) and TensorFlow version 2.7.0 should be shown.

Many cloud-based computational platforms are also available, where you can set up your own machine with various customization (operating system, GPU card type, number of GPU cards, and so on). Many are migrating to such cloud-based services due to the following benefits:

  • More customization options
  • Less maintenance effort
  • No infrastructure requirements

Several popular cloud-based computational platforms are as follows:

Google Colab is a great cloud-based platform that allows you to write TensorFlow code and execute it on CPU/GPU hardware for free.

You have been reading a chapter from
Natural Language Processing with TensorFlow - Second Edition
Published in: Jul 2022 Publisher: Packt ISBN-13: 9781838641351
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}