# How to Run the Examples in AI For Beginners: A Complete Setup Guide

> Learn how to run AI For Beginners examples by cloning the repo, creating a Conda environment, and executing Python scripts or Jupyter notebooks. Get your AI setup quickly.

- Repository: [Microsoft/AI-For-Beginners](https://github.com/microsoft/AI-For-Beginners)
- Tags: how-to-guide
- Published: 2026-08-02

---

**Clone the Microsoft AI For Beginners repository, create the Conda environment from [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml), and run Python scripts with `python` or notebooks with `jupyter notebook`.**

The **AI For Beginners** repository by Microsoft provides self-contained, beginner-friendly code examples that demonstrate core AI concepts without requiring the full curriculum notebooks. This guide walks you through running these examples step by step, from environment setup to executing your first machine learning model.

## Prerequisites for Running AI For Beginners Examples

Before running any examples, ensure you have **Python 3.8 or higher** installed. The repository targets cross-platform compatibility across Windows, macOS, and Linux.

Two dependency management approaches are supported:

- **Conda environment** (recommended): Uses [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) to pin exact versions for reproducibility
- **Minimal pip install**: Lightweight setup for running only the Python scripts

The Conda approach automatically registers a Jupyter kernel, enabling direct notebook execution from the repository.

## Creating the Conda Environment

The [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) file in the repository root defines an isolated environment named **ai4beg** with all required libraries: `numpy`, `jupyter`, `tensorflow`, `pillow`, and others.

Run these commands from the repository root:

```bash
git clone https://github.com/microsoft/AI-For-Beginners.git
cd AI-For-Beginners
conda env create --name ai4beg --file environment.yml
conda activate ai4beg

```

**Alternative lightweight setup** (Python scripts only):

```bash
pip install numpy jupyter pillow tensorflow

```

## Running Python Script Examples

The `examples/` directory contains four self-contained scripts, each runnable directly with the standard interpreter.

### Hello AI World Demo

The [`01-hello-ai-world.py`](https://github.com/microsoft/AI-For-Beginners/blob/main/01-hello-ai-world.py) script trains a minimal linear model (`y = 2x`) to introduce fundamental training concepts:

```bash
python examples/01-hello-ai-world.py

```

**Expected output:**

```

========================================
Welcome to Hello AI World!
========================================

📊 Creating training data...
Training examples: [(1, 2), (2, 4), (3, 6), (4, 8), (5, 10)]

🎓 Training started...
Epoch 20/100 - Average error: 0.4375 - Weight: 1.84
...
✅ Training complete! Final weight: 1.99

```

Each script includes a top-level `main()` guard (`if __name__ == "__main__":`) for direct execution.

### Neural Network From Scratch

Run the multilayer perceptron implementation:

```bash
python examples/02-simple-neural-network.py

```

### Text Sentiment Analysis

Execute the tiny sentiment model on sample sentences:

```bash
python examples/04-text-sentiment.py

```

## Running Jupyter Notebook Examples

Some examples require interactive execution. The `03-image-classifier.ipynb` notebook demonstrates image classification with a pre-trained CNN.

Launch the notebook server:

```bash
jupyter notebook examples/03-image-classifier.ipynb

```

**Execution flow:**

1. First cell: Import TensorFlow and NumPy
2. Second cell: Download and display a sample image
3. Third cell: Load MobileNet, run inference, and print top-5 predictions

The notebook interface renders results inline, making it ideal for visualizing model outputs.

## Using VS Code Dev Containers or GitHub Codespaces

For zero-configuration execution, the repository includes [`.devcontainer/devcontainer.json`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/devcontainer.json). This configuration pre-installs the identical Conda environment in a Docker container.

**Steps:**

1. Open the repository in VS Code
2. Click **"Reopen in Container"** when prompted
3. The Jupyter server starts automatically

This approach eliminates local dependency management entirely.

## Key Files for Running AI For Beginners Examples

| File | Purpose |
|------|---------|
| [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) | Conda specification with pinned Python and library versions |
| [`examples/01-hello-ai-world.py`](https://github.com/microsoft/AI-For-Beginners/blob/main/examples/01-hello-ai-world.py) | Linear model trainer—your first "Hello AI" demo |
| [`examples/02-simple-neural-network.py`](https://github.com/microsoft/AI-For-Beginners/blob/main/examples/02-simple-neural-network.py) | Feed-forward network implemented from scratch |
| `examples/03-image-classifier.ipynb` | Interactive image classification with pre-trained CNN |
| [`examples/04-text-sentiment.py`](https://github.com/microsoft/AI-For-Beginners/blob/main/examples/04-text-sentiment.py) | Sentiment analysis on short text inputs |
| [`.devcontainer/devcontainer.json`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/devcontainer.json) | VS Code container definition for one-click setup |

## Summary

- **Clone** `microsoft/AI-For-Beginners` to your local machine
- **Create environment** using `conda env create` or minimal `pip install`
- **Activate** the `ai4beg` environment before running examples
- **Run scripts** with `python examples/<script>.py`
- **Run notebooks** with `jupyter notebook <notebook>.ipynb`
- **Use dev containers** for dependency-free execution in VS Code or GitHub Codespaces

All examples are deliberately isolated, heavily commented, and executable without the full curriculum—ready for hands-on AI exploration.

## Frequently Asked Questions

### Do I need to install the full curriculum to run the examples?

No. The examples in the `examples/` directory are completely self-contained. You only need the files in that directory plus the dependencies specified in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml). The full lesson notebooks are optional.

### What if I don't want to use Conda?

You can run most examples with a minimal pip installation: `pip install numpy` for the basic scripts, or `pip install numpy jupyter pillow tensorflow` if you need notebook support. However, Conda is recommended for exact version matching.

### Why does the image classifier use a pre-trained model instead of training from scratch?

The `03-image-classifier.ipynb` notebook uses MobileNet, a pre-trained convolutional neural network, to demonstrate **transfer learning**—a practical technique where you leverage existing models rather than training computationally expensive networks from zero. This keeps execution fast and hardware requirements minimal for beginners.

### Can I run these examples on Google Colab?

Yes, though you'll need to upload the notebook files manually. The `03-image-classifier.ipynb` notebook will work in Colab with its pre-installed TensorFlow. For the `.py` scripts, upload them and run in Colab code cells or convert to notebooks using `jupytext`.