Tutorial V.I - Programming with AI
Programming: Everyday Decision-Making Algorithms
Programming with AI
Using AI to generate code
- Coding by hand is not the only way to generate code
- Most likely, a lot of you have already used ChatGPT
. . .
How do
Large Language
Models work?
Large Language Models (LLMs)
- Think of them like advanced pattern recognition systems
- They have “read” massive amounts of text
- Books, websites, articles, code, and more
- Text is broken into tokens, parts of words or punctuation
- Based on patterns, they can generate new text
Training LLMs
- Imagine learning a language by reading millions of books
- Learns patterns in how words and ideas connect via tokens
- Interconnected nodes with weights representing patterns
- During training, these weights are adjusted
- Once trained, applying them takes much less ressources
. . .
Using a trained model is called inference.
Pattern Recognition
- Not like a search engine!
- When asked, it looks for relevant patterns it learned
- Like having a huge library in its “memory” to draw from
- It can find patterns between concepts and your question
- Knows only limited text at once (context window)
. . .
Managing context windows is crucial!
Probability based responses
- After each written token, it predicts “what should come next?”
- Like a advanced version of the word prediction on your phone
- Chooses the most likely next token based on training
- But can’t actually “think” or “understand” like humans
Limitations
Impact on Jobs
- Question: What do you think about their impact on jobs?
- Question: What are the implications for us?
- Question: Can we use them to our advantage?
. . .
If you use free models, be aware that your prompts are going to be used by the providers and are not private. But for learning and experimenting, this should be no issue.
A Great Overview by 3Blue1Brown
- Greg Sanderson provides an excellent explanation of LLMs
- Great starting point to understand LLMs
- Check out his YouTube channel, 3Blue1Brown for more
AI Coding Partner
What is GitHub Copilot?
GitHub Copilot is an AI pair programmer that helps you write code faster and with less effort.
. . .
Think of it as:
- An autocomplete for entire lines or blocks of code
- A coding assistant that understands context
- A learning tool that shows you coding patterns
. . .
Copilot uses AI trained on billions of lines of public code to suggest completions.
. . .
There are alternative like Zed or Cursor, but you can use Copilot for free as student.
Used autocomplete before?
. . .
When you type on your phone, it suggests the next word.
. . .
GitHub Copilot does the same for code:
- You write a comment describing what you want
- Copilot suggests the code to do it
- You accept, modify, or reject the suggestion
. . .
It’s autocomplete but much better then what you are used to
Why Use Copilot?
Benefits you while learning and working with Python:
- Faster coding: Less time typing boilerplate code
- Learn patterns: See how experienced programmers code
- Understand syntax: Get correct syntax without memorizing
- Stay in flow: Focus on logic, not syntax errors
. . .
Especially helpful when you know WHAT you want to do but forget HOW to do it.
When should you use Copilot?
. . .
Good uses of Copilot
- Understanding Python syntax you forgot
- Writing repetitive or boilerplate code
- Getting unstuck on simple problems
- Exploring different approaches
What shouldn’t you do with Copilot?
. . .
Not so good uses of Copilot
- Replacing learning fundamentals
- Accepting code you don’t understand
- Skipping practice exercises
- Copy-pasting without reading
. . .
Always understand what Copilot suggests before accepting!
. . .
But of course I know you will not do that ;)
Accept without reading?
. . .
Copilot might suggest code that:
- Works but uses concepts you haven’t learned yet
- Contains subtle bugs or edge cases
- Doesn’t match your specific requirements
- Uses inefficient approaches
- Introduce dangerous code in your project
. . .
Dangerous code can lead to security vulnerabilities, data loss, or other issues. In the context of this lecture it should be no issue, but in companies it can be one!
My take: Just be careful, ok?
Your code, your responsibility:
- Read the suggestion carefully
- Understand what it does
- Test it with examples
- Modify if needed
. . .
Don’t accept code blindly, especially later if things are more complicated.
Getting Started with Copilot
Get Free Access
GitHub Student Developer Pack gives you free Copilot access!
. . .
- Go to education.github.com/pack
- Sign up with your university email
- Verify your student status
- Wait for approval (usually 1-2 days)
- Login into your account in VS Code
. . .
You’ll need a GitHub account. Create one at github.com if you don’t have one.
Verifying Copilot is Working
- Create a new Python file (
.py) and type something - Wait 1-2 seconds
. . .
If working, you’ll see:
- Gray “ghost text” suggesting code
- Press
Tabto accept - Press
Escto reject
. . .
Try to get copilot running on your own until next session.
Summary
Key Takeaways
- GitHub Copilot is a tool: You still need to learn fundamentals
- Understand before accepting: Read every suggestion carefully
- Use it strategically: Syntax help yes, thinking replacement no
- Get free access: GitHub Student Developer Pack
- Practice: The more you use it, the more helpful it becomes
Footnotes
https://www.anthropic.com/research/tracing-thoughts-language-model↩︎
This can partially be improved by using context from the internet.↩︎