Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[译] [102] 本书涉及的技术 #4

Open
cssmagic opened this issue Feb 28, 2024 · 0 comments
Open

[译] [102] 本书涉及的技术 #4

cssmagic opened this issue Feb 28, 2024 · 0 comments

Comments

@cssmagic
Copy link
Owner

cssmagic commented Feb 28, 2024

1.2 About the technology

1.2 本书涉及的技术

We’ll be using two main technologies in this book: Python and GitHub Copilot.

在这本书中,我们将重点介绍两项主要技术:Python 和 GitHub Copilot。

Python is a programming language. It’s a way to communicate with a computer. People use it to write all kinds of programs that do useful things, like games, interactive websites, visualizations, apps for file organization, automating routine tasks, and so on.

Python 是一门编程语言,是与计算机进行交流的途径。人们使用它编写各种程序来完成有用的事情,如游戏、交互式网站、数据可视化、文件管理应用以及自动化常规任务等。

There are other programming languages, too, like Java, C++, Rust, and many others. Copilot works with those, too, but at the time of writing, it works really well with Python. Python code is a lot easier to write compared to many other languages (especially assembly code). Even more importantly, Python is easy to read. After all, we’re not going to be the one writing the Python code. Our AI assistant is!

还有其他的编程语言,如 Java、C++、Rust 等。Copilot 也支持这些语言,但截至目前,它对 Python 的支持尤其出色。与许多其他语言(尤其是汇编语言)相比,编写 Python 代码要简单得多。更为重要的是,Python 更易于阅读。毕竟,编写 Python 代码的将不是我们,而是我们的 AI 助手!

Computers don’t actually know how to read and run Python code. The only thing computers can understand is something called machine code, which looks even more ridiculous than assembly code as it is the binary representation of the assembly code (yep, just a bunch of 0s and 1s!). Behind the scenes, your computer takes any Python code that you provide and converts it into machine code before it runs, as shown in Figure 1.1.

实际上,计算机并不懂得如何读取和执行 Python 代码。计算机唯一能够理解的是称为机器码的内容,这种码相比汇编代码来说更加难以理解,因为它是汇编代码的二进制表现形式(没错,仅仅是一连串的 0 和 1!)。在幕后,你的计算机将接收你所提供的任何 Python 代码,并在执行之前把它转换成机器码,正如图 1.1 所展示的那样。

Figure 1.1 Your Python program goes through several steps before you see the output on your screen

图 1.1 在你的屏幕上看到输出之前,你的 Python 程序需要经历几个步骤

Copilot, your AI Assistant

Copilot,你的 AI 助手

What is an AI Assistant? An AI Assistant is an Artificial Intelligence (AI) agent that helps you get work done. Maybe you have an Amazon Alexa device at home, or an iPhone with Siri-—these are AI assistants. Those ones help you order groceries, learn the weather, or determine that, yes, the woman who played Bellatrix in the Harry Potter movies really was in Fight Club. An AI assistant is just a computer program that responds to normal human inputs like speech and text with human-like answers.

什么是AI 助手?AI 助手是一种人工智能(AI)代理,它帮助你完成任务。你可能在家中使用亚马逊的 Alexa 设备,或拥有一部集成了 Siri 的 iPhone——这些都属于 AI 助手。这类助手能帮你订购生鲜、查询天气,或是确认那位在《哈利·波特》电影中饰演贝拉特里克斯的女演员确实也参演了《搏击俱乐部》。AI 助手只不过是一个响应人类语音和文本输入的计算机程序,并以类人的方式给出答案。

Copilot is an AI Assistant with a specific job: it converts English into computer programs. (It can also do a whole lot more as we will soon see.) There are other AI assistants like Copilot, including CodeWhisperer, Tabnine, and Ghostwriter. We chose Copilot for this book by a combination of the quality of code that we have been able to produce, stability (it has never crashed for us!), and our own personal preferences. We encourage you to check out other tools as well when you feel comfortable doing so.

Copilot 是一款具有特定任务的 AI 助手:它能将英语转换成计算机程序(我们很快就会看到,它还能做更多的事情)。除了 Copilot,还有其他一些类似的 AI 助手,如 CodeWhisperer、Tabnine 和 Ghostwriter。我们选择 Copilot 作为本书介绍的工具,这是基于我们所生成的代码质量、其稳定性(它从未发生过崩溃!)以及我们个人的偏好。我们也鼓励你在感觉合适时,探索其他的工具。

How Copilot works behind the scenes-—in 30 seconds

Copilot 幕后工作原理——仅用 30 秒

You can think of Copilot as a layer between you and the computer program you’re writing. Instead of writing the Python directly, you simply describe the program you want in words—this is called a prompt—and Copilot generates the program for you.

你可以把 Copilot 想象成你和你正在编写的计算机程序之间的一个中介层。不必直接编写 Python,你只需用语言描述你想要实现的程序——这称为提示词——之后 Copilot 就会为你生成相应的程序。

The brains behind Copilot is a fancy computer program called a large language model, or LLM. An LLM stores information about relationships between words, including which words make sense in certain contexts, and uses this to predict the best sequence of words to respond to a prompt.

Copilot 的智能核心是一个称为大型语言模型(LLM)的复杂计算机程序。大型语言模型存储了关于单词之间关系的信息,包括在特定上下文中哪些单词是有意义的,并利用这些信息来预测对一个提示词最佳的单词序列。

Imagine that we asked you what the next word should be in this sentence: "The person opened the ________". There are many words that you could fill in here, like “door” or “box” or “conversation,” but there are also many words that would not fit here, like “the” or “it” or “open.” An LLM takes into account the current context of words to produce the next word, and it keeps doing this until it has completed the task.

设想我们询问你在这个句子中:“这个人打开了______。” 下一个词应当是什么。这里有很多可能的填词,如“门”、“盒子”或“谈话”,但同时也存在许多不适合此处的词,如“这”、“它”或“打开”。大型语言模型会根据当前词汇的上下文来预测下一个合适的词,并持续这个过程直到任务完成。

Notice that we didn't say anything about Copilot having an understanding of what it is doing. It just uses the current context to keep writing code. Keep this in mind throughout your journey: only we know whether the code that's generated actually does what we intended it to do. Very often it does, but you should always exercise healthy skepticism regardless.

请注意,我们并未提及 Copilot 是否真的理解其正在进行的操作。它仅根据当前上下文继续编写代码。在你的编程旅程中,请始终牢记这一点:只有我们自己知道生成的代码是否确实按照我们的意图行事。虽然很多时候它确实能够实现这一点,但无论如何,你都应当始终保持一种健康的怀疑心态。

Figure 1.2 will give you an idea of how Copilot goes from prompt to program.

图 1.2 将为你揭示 Copilot 是如何从提示词生成程序的过程。

Figure 1.2 Going from prompt to program with Copilot

图 1.2 使用 Copilot 从提示词生成程序

You might wonder why Copilot writes Python code for us and not machine code directly. Isn’t Python an expendable intermediate step now? Well, no, and the reason is that Copilot is going to make mistakes. And if it’s going to make mistakes, and we need to get them fixed, then it’s a lot easier to do that with Python than with machine code.

你可能好奇,为什么 Copilot 会为我们编写 Python 代码,而不是直接生成机器码。Python 难道现在不只是一个可有可无的中间步骤吗?实际上,并非如此,这是因为 Copilot 可能会出错。既然它可能犯错,我们需要对这些错误进行修正,那么相比于机器码,使用 Python 进行修正无疑要简单得多。

In fact, virtually no one checks if the machine code produced from Python is correct. This is partially because of the determinism of the Python language specification. One could imagine a future where Copilot conversations are so accurate that inspecting the Python is unnecessary, but we’re a long way from that.

实际上,几乎无人检查由 Python 转换而成的机器码是否准确。这在一定程度上是因为 Python 语言规范的决定性。可以设想,将来 Copilot 的对话准确率如此之高,以致于审查 Python 代码将变得非必需,但距离那一天我们还有很长的路要走。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant