Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 16.1 — The AI Python Landscape: Which Library Does What
Python · Example 2 of 2

Every layer is a function

The "model" and the "LLM" here are tiny stand-ins. The call shape (values in, value out) is the same as the real thing.

AI work in Python is a stack of layers: NumPy and pandas for data, scikit-learn for classic machine learning, PyTorch for neural networks, Hugging Face for trained models, SDKs for hosted LLMs, frameworks and FastAPI on top. Knowing what each layer is for tells you what to learn first.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a function pick_layer(task) that returns the right library for a few tasks and a helpful default otherwise.

02

Write a function comes_first(a, b) that says whether layer a should be learned before layer b, using a list that gives the learning order.

03

Write a function layer_count(stack) that counts how many distinct layers a list mentions (the list may repeat names).

Explain it without notes

01

What is the role of Python in an AI system, given that the heavy computation is not done in Python?

02

Name the layers of the AI Python stack and say what each is for.

03

When would you use scikit-learn instead of PyTorch, and when would you call a hosted LLM instead of either?

04

A teammate proposes an LLM call to classify 2 million support tickets into 12 fixed categories you already have labelled history for. What do you ask, and what would you try first?

Every layer is a function
Sign in to run this example in your browser.

Expected output

pure Python dot: 32
NumPy dot:       32
tiny model y = w*x + b: [3.0, 5.0, 7.0]
You asked: what is a tensor?