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:
- Download Anaconda from https://www.continuum.io/downloads
- Select the appropriate OS and download Python 3.7
- 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:
- Run Conda and create
-n packt.nlp.2 python=3.7
in the terminal window using the commandconda create -n packt.nlp.2 python=3.7
. - Change directory (
cd
) to the project directory. - 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. - Install the required libraries using one of the following options.
- If you have a GPU, use
pip install -r requirements-base.txt -r requirements-tf-gpu.txt
- 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:
- Open a Terminal window.
- Activate the
packt.nlp.2
Conda environment if it is not already by runningactivate packt.nlp.2
- Run the command:
jupyter notebook
You should be presented with a new browser window that looks like Figure 1.6:
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:
- Open Command Prompt in Windows or Terminal in Linux or macOS.
- Activate the
packt.nlp.2
Conda environment. - Type
python
to enter the Python prompt. You should now see the Python version right below. Make sure that you are using Python 3. - 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: https://colab.research.google.com/
- Google Cloud Platform (GCP): https://cloud.google.com/
- Amazon Web Services (AWS): https://aws.amazon.com/
Google Colab is a great cloud-based platform that allows you to write TensorFlow code and execute it on CPU/GPU hardware for free.