人工智能
欢迎!
- In 计算机科学 and 编程 circles, rubber ducking or rubber duck debugging is the act of speaking to an inanimate object to be able to talk through a challenging problem like a bug in one’s code.
- Most recently, CS50 created our own rubber duck debugger at CS50.ai, which uses 人工智能 (AI) as a way by which to interact with students to help them with their own challenging problems.
- Students engaging with this 工具 can begin understanding the potential of what AI can offer 世界各地.
Generative 人工智能
- Numerous AI 工具 have created the potential for artificially generated images to enter 世界各地.
- Up until years past, most of these 工具 had numerous tells that might indicate to an observer that an image is AI-generated.
- However, 工具 are becoming exceedingly good at generating these images.
- Indeed, as technology improves, it will soon be almost, if not entirely, impossible for such images to be detected with the naked eye.
- Generative AI 可用于 to create photos,视频, music, and text.
Prompt Engineering and Copilot
- Prompt engineering is the way by which an individual can ask good问题 of an AI.
- We use a system prompt to teach the AI how to interact with users. We teach the AI how to work with students using such a prompt.
- User prompts are those provided by users to interact with the AI. With these prompts, students interact with the AI.
-
我们可以 implement this in code as follows:
# Adds to system prompt. from openai import OpenAI client = OpenAI() user_prompt = input("Prompt: ") system_prompt = "Limit your answer to one sentence. Pretend you're a cat." response = client.responses.create( input=user_prompt, instructions=system_prompt, model="gpt-5" ) print(response.output_text)You can run this code with
python chat.py. You can 下载 this code here - Generative AI can also be used to generate code! This kind of functionality can amplify your abilities as a growing and well-practiced programmer.
- Copilot is one such 工具 for generating code. In CS50, we do not allow the use of generative AI, outside 这门课程’s own 工具. CS50 provides clear guidance for students, in our 学术诚信 policy, on what is considered reasonable and unreasonable use of AI.
AI
- AI has been with us for many decades! Software has long adapted to users. 算法 look for patterns in junk mail, in handwriting recognition, in creating movie and视频 recommendations, and in playing games.
- In games, 例如, step-by-step instructions 五月 allow a computerized adversary to play a game of Breakout.
决策树s
- Decision trees are used by an algorithm to decide what decision to make.
-
例如, in Breakout, an algorithm 五月 consider what choice to make based on the instructions in the code:
While game is ongoing: If ball is left of paddle: Move paddle left Else if ball is right of paddle: Move paddle right Else: Don't move paddle - With most games, they attempt to minimize the number of calculations 必需 to compete with the player.
极小化极大
- AI is often good at gameplay because it reduces moves and outcomes to mathematical values.
- You can imagine where an algorithm 五月 score outcomes as positive, negative, and neutral.
- In tic-tac-toe, the AI 五月 consider a board where the computer wins as
1and one where the computer loses as-1. - You can imagine how a computer 五月 look at a 决策树 of potential outcomes and assign scores to each potential move.
- The computer will attempt to win by maximizing its own score.
-
In the context of tic-tac-toe, the algorithm 五月 conceptualize this as follows:
If player is X: For each possible move: Calculate score for board Choose move with highest score Else if player is O: For each possible move: Calculate score for board Choose move with lowest score -
This could be pictured as follows:

- Because computers are so powerful, they can crunch massive potential outcomes. However, the computers in our pockets or on our desks可能不是 able to calculate trillions of options for ever-更多-complex game trees. This is where 机器学习 can help.
机器学习
- 机器学习 is a way by which a computer can learn through reinforcement.
- 一份 computer can learn how to flip a pancake.
- 一份 computer can learn how to play The Floor is Lava.
- The computer repeats trial after trial after trial to discover what behaviors to repeat and those not to repeat.
-
Within much of AI-based 算法, there are concepts of explore vs. exploit, where the AI 五月 randomly try something that可能不是 considered optimal. Randomness can yield better outcomes. This can be represented in code as follows:
epsilon = 0.10 If random() < epsilon: Make a random move Else: Make the move with the highest value注意
epsilonrepresents the rate of randomness.
深度学习
- Supervised learning is a form of AI-based learning where the human partners with the AI. 例如, you might click the “spam” button in 你的邮件client to teach the AI what emails it should consider spam.
- However, supervised learning does not scale well to larger problems. Hence, unsupervised learning is a 意思s by which the AI can learn with minimal human intervention.
- Deep learning uses neural networks whereby problems and solutions are explored.
-
例如, deep learning 五月 attempt to predict whether a blue or red dot will appear somewhere on a graph. 考虑 following image:

- Existing 训练数据 is used to predict an outcome. Further, 更多 训练数据可能是 created by the AI to discover further patterns.
-
Deep learning creates nodes (pictured below) that associate inputs and outputs.

大语言模型s
- Large language models (LLMs) are massive models that make predictions based on huge amounts of training.
- Just a few years ago, AI was not very good at completing and generating sentences. Google published a paper in 2017 regarding how these AIs can have their attention drawn to the relationships between various words.
- Generative Pre-trained Transformer (GPT for short) are trained on the relationships between words.
- The AI encodes words into embeddings 查找 relationships between words. Thus, through a huge amount of training, a massive neural network can predict the association between words - resulting in the ability for generative AI to generate content and even have conversations with users.
- Sometimes, LLMs can hallucinate and provide incorrect information.
总结
在这节课中, you learned 关于 some of the technology behind CS50.ai. Specifically, we discussed…
- Generative 人工智能
- Prompt Engineering
- AI
- 决策树s
- 极小化极大
- 机器学习
- 深度学习
- 大语言模型s
This was CS50!