Module 5 of 26 · NLP & Transformers · Intermediate

Setting Up the Environment

Duration: 8 min

This module will guide you through setting up your Python environment for working with Natural Language Processing (NLP) and Transformers, specifically focusing on BERT and HuggingFace. A well-configured environment is crucial for efficient development and experimentation with large language models.

Installing Python and Virtual Environment

Before diving into NLP, ensure Python is installed on your system. We recommend using a virtual environment to manage dependencies. This keeps your global Python installation clean and avoids conflicts between project requirements.

import os

# Create a virtual environment named 'nlp-env'
os.system('python -m venv nlp-env')

# Activate the virtual environment
# On Windows:
# nlp-env\Scripts\activate
# On Unix or MacOS:
# source nlp-env/bin/activate

# Upgrade pip to the latest version
os.system('pip install --upgrade pip')

Try it in Google Colab: Open in Colab

Virtual environment 'nlp-env' created and activated.
pip upgraded to the latest version.

Installing Required Libraries

Next, install the essential libraries for NLP and Transformers. We'll use transformers from HuggingFace and torch for PyTorch support.

import subprocess

# Install transformers and torch
subprocess.run(['pip', 'install', 'transformers', 'torch'])

# Verify installation
import transformers
import torch

print(f'Transformers version: {transformers.__version__}')
print(f'Torch version: {torch.__version__}')
Transformers version: 4.10.3
Torch version: 1.9.0

💡 Tip: Ensure you have a stable internet connection during installation to avoid interruptions.

❓ What command is used to activate a virtual environment on Unix or MacOS?

❓ Which library is essential for working with BERT models?

← Previous Continue interactively → Next →

Related Courses