mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Translated
tech/20220809 Artificial Intelligence- Explaining the Basics.md
This commit is contained in:
parent
35659d3e57
commit
5b61af97e6
@ -1,114 +0,0 @@
|
||||
[#]: subject: "Artificial Intelligence: Explaining the Basics"
|
||||
[#]: via: "https://www.opensourceforu.com/2022/08/artificial-intelligence-explaining-the-basics/"
|
||||
[#]: author: "Deepu Benson https://www.opensourceforu.com/author/deepu-benson/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "toknow-gh"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Artificial Intelligence: Explaining the Basics
|
||||
======
|
||||
*If you are a student or professional interested in the latest trends in the computing world, you would have heard of terms like artificial intelligence, data science, machine learning, deep learning, etc. The first article in this series on artificial intelligence explains these terms, and sets the platform for a simple tutorial that will help beginners get started with AI.*
|
||||
|
||||
Today it is absolutely necessary for any student or professional in the field of computer science to learn at least the basics of AI, data science, machine learning and deep learning. However, where does one begin to do so?
|
||||
|
||||
To answer this question, I have gone through a number of textbooks and tutorials that teach AI. Some start at a theoretical level (a lot of maths), some teach you AI in a language-agnostic way (they don’t care whether you know C, C++, Java, Python, or some other programming language), and yet others assume you are an expert in linear algebra, probability, statistics, etc. In my opinion, all of them are useful to a great extent. But the important question remains — where should an absolute beginner interested in AI begin his or her journey?
|
||||
|
||||
Frankly, there are many fine ways to begin your AI journey. However, I have a few concerns regarding many of them. Too much maths is a distraction while too little is like a driver who doesn’t know where his/her car’s engine is placed. Starting with advanced concepts is really effective if the potential AI engineer or data scientist is good in linear algebra, probability, statistics, etc. Starting with the very basics and ending at the middle of nowhere is fine only if the potential AI learner wants to end the journey at that particular point. Considering all these facts, I believe an AI tutorial for beginners should start at the very basics and end with a real AI project (small, yet one that will outperform any conventional program capable of performing the same task).
|
||||
|
||||
This series on AI will start from the very basics and will reach up to an intermediate level. But in addition to discussing topics in AI, I also want to ‘cut the clutter’ (the name of a popular Indian news show) about the topics involved since there is a lot of confusion among people where terms like AI, machine learning, data science, etc, are concerned. AI based applications are often necessary due to the huge volume of data being produced every single day. A cursory search on the Internet will tell you that about 2.5 quintillion bytes of data are produced a day (quintillion is the enormous number 1018). However, do remember that most of this data is absolutely irrelevant to us, including tons of YouTube videos with no merit, emails sent without a second thought, reports on trivial matters on newspapers, and so on and so forth. However, this vast ocean of data also contains invaluable knowledge which often is priceless. Conventional software programs cannot carry out the Herculean task of processing such data. AI is one of the few technologies that can handle this information overload.
|
||||
|
||||
We also need to distinguish between fact and fiction as far as the power of AI is concerned. I remember a talk by an expert in the field of AI a few years back. He talked about an AI based image recognition system that was able to classify the images of Siberian Huskies (a breed of dogs) and Siberian snow wolves with absolute or near absolute accuracy. Search the Internet and you will see how similar the two animals look. Had the system been so accurate, it would have been considered a triumph of AI. Sadly, this was not the case. The image recognition system was only classifying the background images of the two animals. Images of Siberian Huskies (since they are domestic animals) almost always had some rectangular or round objects in the background, whereas the images of Siberian snow wolves (being wild animals located in Siberia) had snow in the background. Such examples have led to the need for AI with some guarantee for accuracy in recent years.
|
||||
|
||||
Indeed, AI has shown some of its true power in recent years. A simple example is the suggestions we get from a lot of websites like YouTube, Amazon, etc. Many times, I have been astonished by the suggestions I have received as it almost felt as if AI was able to read my mind. Whether such suggestions are good or bad for us in the long run is a hot topic of debate. Then there is the critical question, “Is AI good or bad?” I believe that a ‘Terminator’ movie sort of future, where machines attack humans deliberately is far, far away in the future. However, the word ‘deliberately’ in the previous sentence is very important. AI based systems at present could malfunction and accidentally hurt humans. However, many systems that claim the powers of AI are conventional software programs with a large number of ‘if’ and ‘for’ statements with no magic of AI in it. Thus, it is safe to say that we are yet to see the real power of AI in our daily lives. But whether that impact will be good (like curing cancer) or bad (deepfake videos of world leaders leading to riots and war) is yet to be seen. On a personal level, I believe AI is a boon and will drastically improve the quality of life of the coming generations.
|
||||
|
||||
### What is AI?
|
||||
|
||||
So, before we proceed any further, let us try to understand how AI, machine learning, deep learning, data science, etc, are related yet distinct from each other. Very often these terms are used (erroneously) as synonyms. First, let us consider a Venn diagram that represents the relationship between AI, machine learning, deep learning and data science (Figure 1). Please keep in mind that this is not the only such Venn diagram. Indeed, it is very plausible that you may find other Venn diagrams showing different relationships between the four different entities shown in Figure 1. However, in my opinion, Figure 1 is the most authentic diagram that captures the interrelationship between the different fields in question to the maximum extent.
|
||||
|
||||
![Figure 1: The AI hierarchy and data science][1]
|
||||
|
||||
First of all, let me make a disclaimer. Many of the definitions of the terms involved in this first article in this series on AI may not be mathematically the most accurate. I believe that formally defining every term with utmost precision at this level of our discussion is counterproductive and a wastage of time. However, in the subsequent articles in this series we will revisit these terms and formally define them. At this point in time of our discussion, consider AI as a set of programs that can mimic human intelligence to some extent. But what do I mean by human intelligence?
|
||||
|
||||
Imagine your AI program is a one-year old baby. As usual, this baby will learn his/her mother tongue simply by listening to the people speaking around him/her. He/she will soon learn to identify shapes, colours, objects, etc, without any difficulty at all. Further, he/she will be able to respond to the emotions of people around him. For example, any 3-year-old baby will know how to sweet talk his/her parents into giving him/her all the chocolates and lollipops he/she wants. Similarly, an AI program too will be able to sense and adapt to its surroundings, just like the baby. However, such true AI applications will be achieved only in the far future (if at all).
|
||||
|
||||
Figure 1 shows that machine learning is a strict subset of AI and as such one of the many techniques used to implement artificially intelligent systems. Machine learning involves techniques in which large data sets are used to train programs so that the necessary task can be carried out effectively. Further, the accuracy of performing a particular task increases with larger and larger training data sets. Notice that there are other techniques used to develop artificially intelligent systems like Boolean logic based systems, fuzzy logic based systems, genetic programming based systems, etc. However, nowadays machine learning is the most vibrant technology used to implement AI based systems. Figure 1 also shows that deep learning is a strict subset of machine learning, making it just one of the many machine learning techniques. However, here again I need to inform you that, currently, in practice, most of the serious machine learning techniques involve deep learning. At this point, I refrain even from trying to define deep learning. Just keep in mind that deep learning involves the use of large artificial neural networks.
|
||||
|
||||
Now, what is data science (the red circle) doing in Figure 1? Well, data science is a discipline of computer science/mathematics which deals with the processing and interpretation of large sets of data. By large, how large do I mean? Some of the corporate giants like Facebook claimed that their servers could handle a few petabytes of data as far back in 2010. So, when we say huge data, we mean terabytes and petabytes and not gigabytes of data. A lot of data science applications involve the use of AI, machine learning and deep learning techniques. Hence, it is a bit difficult to ignore data science when we discuss AI. However, data science involves a lot of conventional programming and database management techniques like the use of Apache Hadoop for Big Data analysis.
|
||||
|
||||
Henceforth, I will be using the abbreviations AI, ML, DL and DS as shown in Figure 1. The discussions in this series will mainly focus on AI and ML with frequent additional references to data science.
|
||||
|
||||
### The beginning of our journey and a few difficult choices to make
|
||||
|
||||
Now that we know the topics that will be covered in this series of articles, let us discuss the prerequisites for joining this tutorial. I plan to cover the content in such a way that any person who can operate a Linux machine (a person who can operate an MS Windows or a macOS machine is also fine, but some of the installation steps might require additional help) along with basic knowledge of mathematics and computer programming will definitely appreciate the power of AI, once he or she has meticulously gone through this series.
|
||||
|
||||
It is possible to learn AI in a language-agnostic way without worrying much about programming languages. However, our discussion will involve a lot of programming and will be executed based on a single programming language. So, before we fix our (programming) language of communication, let us review the top programming languages used for AI, ML, DL and DS applications. One of the earliest languages used for developing AI based applications was Lisp, a functional programming language. Prolog, a logic programming language, was used in the 1970s for the same purpose. We will discuss more about Lisp and Prolog in the coming articles when we focus on the history of AI.
|
||||
|
||||
Nowadays, programming languages like Java, C, C++, Scala, Haskell, MATLAB, R, Julia, etc, are also used for developing AI based applications. However, the huge popularity and widespread use of Python in developing AI based applications almost made the choice unanimous. Hence, from this point onwards we will proceed with our discussion on AI based on Python. However, let me caution you. From here onwards, we make a number of choices (or rather I am making the choices for you). The choices mostly depend on ease of use, popularity, and (on a few occasions) on my own comfort and familiarity with a software/technique as well as the best of my intentions to make this tutorial highly effective. However, I encourage you to explore any other potential programming language, software or tool we may not have chosen. Sometimes such an alternative choice may be the best for you in the long run.
|
||||
|
||||
Now we need to make another immediate choice — whether to use Python 2 or Python 3? Considering the youth and the long career ahead of many of the potential readers of this series, I will stick with Python 3. First, let us install Python 3 in our systems. Execute the command ‘sudo apt install python3’ in the Linux terminal to install the latest version of Python 3 in your Ubuntu system (Python 3 is probably already installed in your system). The installation of Python 3 in other Linux distributions is also very easy. It can be easily installed in MS Windows and macOS operating systems too. The following command will show you the version of Python 3 installed in your system:
|
||||
|
||||
```
|
||||
python3 --version
|
||||
Python 3.8.10
|
||||
```
|
||||
|
||||
We need to install a lot of Python packages as we proceed through the series. Hence, we need to install a package management system. Some of the choices include pip, Conda, Mamba, etc. I chose pip as our package management system for this tutorial because it is relatively simple as well as the recommended installation tool for Python. Personally, I am of the opinion that both Conda and Mamba are more powerful than pip and you are welcome to try them out. However, I will stick with pip. The command ‘sudo apt install python3-pip’ will install pip in an Ubuntu system. Notice that pip, Conda and Mamba are cross-platform software and can be installed in Linux, Windows and macOS systems. The command ‘pip3 –version’ shows the version of pip installed in your system, as shown below:
|
||||
|
||||
```
|
||||
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
|
||||
```
|
||||
|
||||
Now we need to install an integrated development environment (IDE) for Python. IDEs help programmers write, compile, debug and execute code very easily. There are many contenders for this position also. PyCharm, IDLE, Spyder, etc, are popular Python IDEs. However, since our primary aim is to develop AI and data science based applications, we consider two other heavy contenders — JupyterLab and Google Colab. Strictly speaking, they are not just IDEs; rather, they are very powerful Web based interactive development environments. Both work on Web browsers and offer immense power. JupyterLab is free and open source software supported by Project Jupyter, a non-profit organisation. Google Colab follows the freemium model, where the basic model is free and for any additional features a payment is required. I am of the opinion that Google Colab is more powerful and has more features than JupyterLab. However, the freemium model of Google Colab and my relative inexperience with it made me choose JupyterLab over Google Colab for this tutorial. But I strongly encourage you to get familiar with Google Colab at some point in your AI journey.
|
||||
|
||||
JupyterLab can be installed locally using the command ‘pip3 install jupyterlab’. The command ‘jupyter-lab’ will execute JupyterLab in the default Web browser of your system. An older and similar Web based system called Jupyter Notebook is also provided by Project Jupyter. Jupyter Notebook can be locally installed with the command ‘pip3 install notebook’ and can be executed using the command ‘jupyter notebook’. However, Jupyter Notebook is less powerful than JupyterLab, and it is now official that JupyterLab will eventually replace Jupyter Notebook. Hence, in this tutorial we will be using JupyterLab when the time comes. However, in the beginning stages of this tutorial we will be using the Linux terminal to run Python programs, and hence the immediate need for pip, the package management system.
|
||||
|
||||
Anaconda is a very popular distribution of Python and R programming languages for machine learning and data science applications. As potential AI engineers and data scientists, it is a good idea to get familiar with Anaconda also.
|
||||
|
||||
Now, we need to fix the most important aspect of this tutorial — the style in which we will cover the topics. There are a large number of Python libraries to support the development of AI based applications. Some of them are NumPy, SciPy, Pandas, Matplotlib, Seaborn, TensorFlow, Keras, Scikit-learn, PyTorch, etc. Many of the textbooks and tutorials on AI, machine learning and data science are based on complete coverage of one or more of these packages. Though such coverage of the features of a particular package is effective, I have planned a more maths-oriented tutorial. We will first discuss a maths concept required for developing AI applications, and then follow the discussion by introducing the necessary Python basics and the details of the Python libraries required. Thus, unlike most other tutorials, we will revisit Python libraries again and again to explore the features necessary for the implementation of certain maths concepts. However, at times, I will also request you to learn some basic concepts of Python and mathematics on your own. That settles the final question about the nature of this tutorial.
|
||||
|
||||
After all this buildup, it would be a sin if we stop this article at this point without discussing even a single line of Python code or a mathematical object necessary for AI. Hence, we move on to learn one of the most important topics in mathematics required for conquering AI and machine learning.
|
||||
|
||||
#### Vectors and matrices
|
||||
|
||||
A matrix is a rectangular array of numbers, symbols or mathematical expressions arranged in rows and columns. Figure 2 shows a 2 x 3 (pronounced ‘2 by 3’) matrix having 2 rows and 3 columns. If you are familiar with programming, this matrix can be represented as a two-dimensional array in many popular programming languages. A matrix with only one row is called a row vector and a matrix with only one column is called a column vector. The vector [11, 22, 33] is an example of a row vector.
|
||||
|
||||
![Figure 2: A 2 x 3 matrix][2]
|
||||
|
||||
But why are matrices and vectors so important in a discussion on AI and machine learning? Well, they are the core of linear algebra, a branch of mathematics. Linear algebraic techniques are heavily used in AI and machine learning. Mathematicians have studied the properties and applications of matrices and vectors for centuries. Mathematicians like Gauss, Euler, Leibniz, Cayley, Cramer, and Hamilton have a theorem named after them in the fields of linear algebra and matrix theory. Thus, over the years, a lot of techniques have been developed in linear algebra to analyse the properties of matrices and vectors.
|
||||
|
||||
Complex data can often easily be represented in the form of a vector or a matrix. Let us see a simple example. Consider a person working in the field of medical transcription. From the medical records of a person named P, details of the age, height in centimetres, weight in kilograms, systolic blood pressure, diastolic blood pressure and fasting blood sugar level in milligrams/decilitres can be obtained. Further, such information can easily be represented as the row vector. As an example, P = [60, 160, 90, 130, 95, 160]. But here comes the first challenge in AI and machine learning. What if there are a billion health records. The task will be incomplete even if tens of thousands of professionals work to manually extract data from these billion health records. Hence, AI and machine learning applications try to extract data from these records using programs.
|
||||
|
||||
The second challenge in AI and machine learning is data interpretation. This is a vast field and there are a number of techniques worth exploring. We will go through the most relevant of them in the coming articles in this series. AI and machine learning based applications also face hardware challenges, in addition to mathematical/computational challenges. With the huge amount of data being processed, data storage, processor speed, power consumption, etc, also become a major challenge for AI based applications. Challenges apart, I believe it is time for us to write the first line of AI code.
|
||||
|
||||
We will write a simple Python script to add two vectors. For that, we use a Python library called NumPy. This is a Python library that supports multi-dimensional matrices (arrays) and a lot of mathematical functions to operate on them. The command ‘pip3 install numpy’ will install the package NumPy for Python 3. Notice that NumPy would have been preinstalled if you were using JupyterLab, Google Colab or Anaconda. However, we will operate from the Linux terminal for the first few articles in this series on AI for ease of use. Execute the command ‘python3’ on the Linux terminal to work from the Python console. This console is software that allows line-by-line execution of Python code. Figure 3 shows the line-by-line execution of the Python code to add two vectors and show the output on the terminal.
|
||||
|
||||
![Figure 3: Python code to find the sum of two row vectors][3]
|
||||
|
||||
First, let us try to understand the code. An important note before we proceed any further. Since this tutorial assumes very little programming experience, I will label lines of code as either (basic) or (AI). Lines labelled (basic) are part of classical Python code, whereas lines labelled (AI) are part of the Python code for developing AI applications. I know such a classification is not necessary or very meaningful. However, I want to distinguish between basic Python and advanced Python so that programmers with both basic and intermediate skills in programming will find this tutorial useful.
|
||||
|
||||
The line of code import numpy as np (basic) imports the library NumPy and names it as np. The import statement in Python is similar to the #include statement of C/C++ to use header files and the import statement of Java to use packages. The lines of code a = np.array([11, 22, 33]) and b = np.array([44, 55, 66]) (AI) create two one-dimensional arrays named ‘a’ and ‘b’. Let me do one more simplification for the sake of understanding. For the time being, assume a vector is equivalent to a one-dimensional array. The line of code c = np.add(a, b) (AI) adds the two vectors named ‘a’ and ‘b’ and stores the result in a vector named ‘c’. Of course, naming variables as ‘a’, ‘b’, ‘c’, etc, is a bad programming practice, but mathematicians tend to differ and name vectors as ‘u’, ‘v’, ‘w’, etc. If you are an absolute beginner in Python programming, please learn how variables in Python work.
|
||||
|
||||
Finally, the line of code print(c) (basic) prints the value of the object, the vector [55 77 99], on the terminal. This is a line of basic Python code. The vector c = [55=11+44 77=22+55 99=33+66] gives you a hint about vector and matrix addition. However, if you want to formally learn how vectors and matrices are added, and if you don’t have any good mathematical textbooks on the topic available at your disposal, I suggest you go through the Wikipedia article on matrix addition. A quick search on the Internet will show you that a classic C, C++ or Java program to add two vectors takes a lot more of code. This itself shows how suitable Python is for handling vectors and matrices, the lifeline of linear algebra. The strength of Python will be further appreciated as we perform more and more complex vector operations.
|
||||
|
||||
Before we conclude this article, I want to make two disclaimers. First, the programming example just discussed above deals with the addition of two row vectors (1 x 3 matrices to be precise). But a real machine learning application might be dealing with a 1000000 X 1000000 matrix. However, with practice and patience we will be able to handle these. The second disclaimer is that many of the definitions given in this article involve gross simplifications and some hand-waving. But, as mentioned earlier, I will give formal definitions for any term I have defined loosely before the conclusion of this series.
|
||||
|
||||
Now it is time for us to wind up this article. I request all of you to install the necessary software mentioned in this article and run each and every line of code discussed here. We will begin the next article in this series by discussing the history, scope and future of AI, and then proceed deeper into matrix theory, the backbone of linear algebra.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.opensourceforu.com/2022/08/artificial-intelligence-explaining-the-basics/
|
||||
|
||||
作者:[Deepu Benson][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.opensourceforu.com/author/deepu-benson/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/05/Figure-1-The-AI-hierarchy-and-data-science.jpg
|
||||
[2]: https://www.opensourceforu.com/wp-content/uploads/2022/05/Figure-2-A-2-X-3-matrix.jpg
|
||||
[3]: https://www.opensourceforu.com/wp-content/uploads/2022/05/Figure-3-Python-code-to-find-the-sum-of-two-row-vectors.jpg
|
@ -0,0 +1,126 @@
|
||||
[#]: subject: "Artificial Intelligence: Explaining the Basics"
|
||||
[#]: via: "https://www.opensourceforu.com/2022/08/artificial-intelligence-explaining-the-basics/"
|
||||
[#]: author: "Deepu Benson https://www.opensourceforu.com/author/deepu-benson/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "toknow-gh"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
人工智能教程:基础知识(一)
|
||||
======
|
||||
*如果你是关注计算机领域最新趋势的学生或从业者,你应该听说过人工智能、数据科学、机器学习、深度学习等术语。作为人工智能系列文章的第一篇,本文将解释这些术语,并搭建一个帮助初学者入门的简易教学平台。*
|
||||
|
||||
如今,计算机科学领域的学生和从业者绝对有必要了解<ruby>人工智能<rt>artificial intelligence</rt></ruby>、<ruby>数据科学<rt>data science</rt></ruby>、<ruby>机器学习<rt>machine learning</rt></ruby>、<ruby>深度学习<rt>deep learning</rt></ruby>方面的基本知识。但是应该从哪里开始呢?
|
||||
|
||||
为了找到答案,我浏览了大量人工智能的就教材和教程。它们有的从大量数学理论开始,有的用编程语言无关的方式(不要求你了解某一门特定的编程语言)讲解,有的假设你是线性代数、概率论和统计学专家。在很大程度上,它们都很有用。但它们都没有回答最重要的问题:真正的初学者应该从哪里开始学习人工智能?
|
||||
|
||||
开始学习人工智能的方式多种多样,但是我对它们各有担忧。涉及太多的数学会让人分心,但如果数学介绍得太少就好像驾驶员不知道汽车引擎在哪里一样。从进阶概念开始讲解对于未来的人工智能工程师和数据科学家来说是最有效率的方式,因为他们精通线性代数、概率论和统计学。如果从基础知识开始,然后在中间某个地方结束也可以,只要学员想要在这里结束学习 。考虑到所有这些事实,我认为初学者的人工智能教程应该从基础知识开始,并以一个实际的人工智能项目结束。这个项目可能很小,但是在相同任务上它将会超越任何传统项目。
|
||||
|
||||
本系列将从最基础的知识讲到中等水平内容。除了讨论人工智能,我还希望对相关的话题进行一些澄清,因为人们对人工智能、机器学习、数据科学等术语有很多困惑。人工智能程序是必要的,因为我们每天会产生海量的数据。根据互联网上查询到的结果,我们每天大约会产生 2.5x10<sup>18</sup> 字节的数据。但是,这些数据中的大多数与我们完全无关,包括大量没有价值的 YouTube 视频,不经思考就发送的电子邮件,琐碎的新闻报道等等。然而,这片浩瀚的数据海洋中同样蕴含着无价的宝贵知识。传统软件无法完成处理这些数据的艰巨任务。人工智能是少数能够应对这种信息过载的技术之一。
|
||||
|
||||
当谈到到人工智能时,我们还需要区分事实和假象。我记得几年前听一位人工智能专家的演讲。他讲述了一个人工智能图像识别系统,它能近乎绝对准确地分辨西伯利亚雪橇犬和西伯利亚雪狼的图像。在互联网上搜索一下,你会看到这两种动物有多么相似。如果这个系统确实那么准确,它将是人工智能的奇迹。可惜的是,事实并非如此。该图像识别系统只是对图像的背景进行了分类。西伯利亚雪橇犬是家养动物,它的图像背景中几乎总会有一些矩形或圆形的物体。而西伯利亚雪狼是野生动物,它所在的背景中有雪。这些例子导致近年来人们对人工智能提出了准确性担保要求。
|
||||
|
||||
确实,最近几年人工智能展现了一些真正的力量。举个简单例子就是 YouTube、Amazon 等网站的推荐系统。很多时候我惊讶于它们的推荐结果,就好像它们会读心术一样。然而不论这些推荐的质量如何,“人工智能到底是好是坏?”都是一个很热门话题。我认为,一个像《终结者》中机器有意识地攻击人类的未来还遥遥无期。然而,前面那句话中的“有意识地”一词非常重要。目前的人工智能系统可能发生故障并且意外地伤害到人类。但是,许多号称具有人工智能能力的系统实际上只是包含大量分支和循环的常规软件。因此目前可以安全地说,我们还没有在日常生活中看到人工智能的真正威力。不论是好的影响(如治愈癌症),还是坏的影响(合成的世界领导人视频导致的暴动和战争),我们都只能拭目以待了。就个人而言,我相信人工智能是一种福祉,并将大大提高未来几代人的生活质量。
|
||||
|
||||
### 什么是人工智能?
|
||||
|
||||
在我们进一步探讨之前,让我们试着理解人工智能、机器学习、深度学习、数据科学等之间的联系和区别。这些术语经常被误用为同义词。图 1 表示了人工智能、机器学习、深度学习和数据科学之间的关系。当然这不是唯一的划分方式,你可能会看到其它的划分图。但在我看来,图 1 是最贴切的,它能够最大程度地概括这些领域之间关系。
|
||||
|
||||
![图 1:人工智能体系结构和数据科学][1]
|
||||
|
||||
在本系列的第一篇文章中,我不会对每个术语定义进行精确的定义。我认为在现阶段,精确地定义它们是适得其反的,是浪费时间。但在后续的文章中,我们将重新讨论这些术语并正式定义它们。目前我们可以暂时把人工智能看作是可以在某种程度上模仿人类智能的程序。那人类智能又是指什么呢?
|
||||
|
||||
想象一下你的人工智能程序是一个一岁大的婴儿。这个宝宝会通过听周围人说话来学习母语。他/她将很快学会识别形状,颜色,物体等,没有任何困难。此外,他/她将能够对周围人的情绪做出反应。例如,任何一个三岁的婴儿都知道如何用甜言蜜语让父母给他/她巧克力和棒棒糖。同样,人工智能程序也将能够感知并适应环境,就像婴儿一样。然而,这种真正的人工智能只能在遥远的未来实现。
|
||||
|
||||
图 1 显示机器学习是人工智能的真子集,它也是实现人工智能系统的技术之一。机器学习是使用大量数据来训练程序的技术,以便有效地执行必要的任务。它的准确性随着训练集的增大而增加。请注意,还有其它技术用于开发人工智能系统,如基于布尔逻辑的系统,基于模糊逻辑的系统,基于遗传编程的系统等。然而,如今机器学习是实现人工智能系统的最主流的技术。图 1 还显示深度学习是机器学习的真子集,它只是众多机器学习技术中的一种。但目前实际上大多数严肃的机器学习技术都用到了深度学习。在这一点上,我甚至避免尝试定义深度学习。请记住,深度学习涉及到使用大型人工神经网络。
|
||||
|
||||
那数据科学(图 1 中的红圈)是做什么的呢?数据科学是计算机科学/数学领域中的一门处理和解读大规模数据的学科。我说的大,有多大呢?早在 2010 年,Facebook 等一些企业巨头就声称它们的服务器可以处理几 Pb 的数据。当我们说大数据时,通常指的是 Tb 或 Pb 级的数据规模,而不是 Gb 级的。许多数据科学应用涉及人工智能、机器学习和深度学习技术的使用。因此,当我们讨论人工智能时,很难不提到数据科学。数据科学也使用很多传统的编程和数据库管理技术,比如使用 Apache Hadoop 进行大数据分析。
|
||||
|
||||
本系列的讨论将主要集中在人工智能和机器学习上,并涉及数据科学。
|
||||
|
||||
### 教学环境搭建
|
||||
|
||||
在表明了本系列文章的主题后,现在说说本教程的前置条件。你需要一台 Linux 电脑(当然 Windows 或 macOS 机器也可以,只是在一些安装步骤上可能需要额外的协助),并了解基本的数学和计算机编程知识。我希望在细心地阅读本系列文章后,你会感受到人工智能的强大。
|
||||
|
||||
用编程语言无关的方式来学习人工智能是可能的。但本系列将基于一门编程语言并涉及大量的编程。在决定使用哪一门编程语言之前,我们先来回顾一下人工智能、机器学习、深度学习和数据科学领域流行的编程语言。Lisp 是一种函数式编程语言,它是最早用于开发人工智能程序的语言之一。Prolog 是一种逻辑编程语言,在 20 世纪 70 年代也被用于同样的目的。我们将在接下来的介绍人工智能历史的文章中更详细地介绍 Lisp 和 Prolog。
|
||||
|
||||
如今,Java、C、C++、Scala、Haskell、MATLAB、R、Julia 等编程语言也被用于开发人工智能程序。Python 在人工智能程序开发中被广泛使用,这使我们选择它作为本教程的编程语言。但我必须声明,从这里开始做的选择(更确切地说,是我替你做的选择),主要考虑的因素是易用性、受欢迎程度、(在少数情况下)我自己对该软件/技术的适应和熟悉程度、对本教程效率的提升。但同时,我也鼓励你尝试其它的编程语言、软件和工具。也许从长远来看,它们对你来说可能是更好的选择。
|
||||
|
||||
现在我们需要立即做出另一个选择:使用 Python 2 还是 Python 3?考虑到本系列有许多年轻的读者,他们还有漫长的职业生涯,我将选择使用 Python 3。在 Ubuntu 系统终端中执行命令 `sudo apt install python3` 安装最新版本的 Python 3(你的系统中可能已经安装了 Python 3)。在其它 Linux 发行版、Windows 和 macOS 机器上安装 Python 3 也非常容易。执行下面的命令查看安装的 Python 3 的版本:
|
||||
|
||||
```
|
||||
python3 --version
|
||||
Python 3.8.10
|
||||
```
|
||||
|
||||
在后续的教程中,我们需要安装许多 Python 包,所以需要一个包管理器。目前主流的包管理器有 pip、Conda 和 Mamba 等。我选择 pip 作为包在本教程的管理器。它相对简单,也是推荐的 Python 安装工具。我认为 Conda 和 Mamba 是比 pip 更强大的工具,你可以尝试一下它们。运行命令 `sudo apt install python3-pip` 将在 Ubuntu 系统中安装 pip。pip、Conda 和 Mamba 是跨平台软件,它们可以安装在 Linux、Windows 和 macOS 系统上。运行命令 `pip3 --version` 查看系统中安装的 pip 版本,如下所示:
|
||||
|
||||
```
|
||||
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
|
||||
```
|
||||
|
||||
现在我们需要一个 Python 集成开发环境(IDE)。IDE 能帮助程序员更容易地编写、编译、调试和执行代码。PyCharm、IDLE、Spyder 等都是流行的 Python IDE。然而,由于我们的主要目的是开发人工智能和数据科学程序,这里考虑另外两个强有力的竞争者 —— JupyterLab 和谷歌 Colab。严格地说,它们不仅仅是 IDE;它们是非常强大的基于网络的交互式开发环境。两者都可以在网络浏览器上工作,并提供强大的功能。JupyterLab 是由非营利组织 Project Jupyter 支持的免费开源软件。谷歌 Colab 遵循 <ruby>免费增值<rt>freemium</rt></ruby> 模式,即基本功能免费,附加功能收费。我认为谷歌 Colab 比 JupyterLab 功能更强大。但是由于谷歌 Colab 的免费增值模式,以及我相对缺乏谷歌 Colab 的使用经验,在本教程中我选择 JupyterLab。但我仍然强烈建议你熟悉谷歌 Colab。
|
||||
|
||||
可以使用命令 `pip3 install JupyterLab` 在本地安装 JupyterLab。执行命令 `jupyter-lab` 将在系统的默认网络浏览器中运行 JupyterLab。Project Jupyter 还提供一个更老的类似系统,称为Jupyter Notebook。可以通过 `pip3 install Notebook` 命令在本地安装 Jupyter Notebook,用`Jupyter Notebook` 运行它。但 Jupyter Notebook 的功能不如 JupyterLab 强大,且官方宣布它最终会被 JupyterLab 取代。在本教程中,我们将在合适的阶段使用 JupyterLab。但在开始阶段,我们将使用 Linux 终端来运行 Python 程序,因此急需的是包管理器 pip。
|
||||
|
||||
Anaconda 是一个非常流行的 Python 和 R 编程语言发行版,它主要用于机器学习和数据科学领域。作为未来的人工智能工程师和数据科学家,熟悉使用 Anaconda 也是一个不错的选择。
|
||||
|
||||
现在我们需要确定最重要的一点——本教程的风格。有大量人工智能开发相关的 Python 库,比如 NumPy、SciPy、Pandas、Matplotlib、Seaborn、TensorFlow、Keras、Scikit-learn 和 PyTorch。许多关于人工智能、机器学习和数据科学的教材和教程都是基于对其中一个或多个库的完整讲解。尽管对特定包的功能进行这样的覆盖讲解是一种高效的方式,但我的教程是更面向数学的。我们将首先讨论开发人工智能程序所需的数学概念,然后再介绍需要的 Python 基础知识和 Python 库。我们会为了探索实现这些数学概念所需的特性而不断回顾这些 Python 库。有时我也会要求你自己学习一些 Python 和数学的基本概念。
|
||||
|
||||
在完成这些准备工作之后,如果我们就在这里结束,任何代码或数学概念都不讲,那将是一种罪过。因此,我们将继续学习人工智能和机器学习中最重要的数学概念:向量和矩阵。
|
||||
|
||||
#### 向量和矩阵
|
||||
|
||||
矩阵是按行和列排列的数字、符号或数学表达式构成的矩形阵列。图 2 显示了一个 2 × 3 矩阵,它有 2 行和 3 列。如果你熟悉编程,在许多流行的编程语言中这个矩阵可以表示为一个二维数组。只有一行的矩阵称为行向量,只有一列的矩阵称为列向量。$[11, 22, 33]$ 就是一个行向量。
|
||||
|
||||
![图 2:一个: A 2 × 3 的矩阵][2]
|
||||
|
||||
为什么矩阵和向量在人工智能和机器学习中如此重要呢?人工智能和机器学习中广泛使用线性代数,而矩阵和向量是线性代数的核心。几个世纪以来,数学家们一直在研究矩阵和向量的性质和应用。高斯、欧拉、莱布尼茨、凯利、克莱姆和汉密尔顿等数学家在线性代数和矩阵论领域都有以他们的名字命名的定理。多年来,线性代数中发展出了许多分析矩阵和向量性质的技术。
|
||||
|
||||
复杂的数据通常可以很容易用向量或矩阵来表示。举一个简单的例子,从一个人的医疗记录中,可以得到详细的年龄、身高(厘米)、体重(公斤)、收缩压、舒张压和空腹血糖(毫克/分升)。这些信息可以很容易用行向量来表示,$[60, 160, 90, 130, 95, 160]$。人工智能和机器学习的第一个挑战来了:如果医疗记录有十亿条怎么办?即使动用成千上万的专业人员从中手动提取数据,这项任务也是无法完成的。因此,人工智能和机器学习利用程序来提取数据。
|
||||
|
||||
人工智能和机器学习的第二个挑战是数据解读。这是一个广阔的领域,有许多技术值得探索。我将在后续文章中介绍相关内容。人工智能和机器学习应用除了面临数学/计算方面的挑战外,还面临硬件方面的挑战。随着处理的数据量的增加,数据存储、处理器速度、功耗等也成为人工智能应用面临的重要挑战。但现在让我们先抛开这些挑战,动手编写第一行人工智能代码。
|
||||
|
||||
我们将编写一个简单的 Python 脚本,用来将两个向量相加。我们将用到名为 NumPy 的 Python 库,它支持多维矩阵(数组)的数学运算。用命令 `pip3 install numpy` 为 Python 3 安装 numpy 包。如果你使用的是 JupyterLab、谷歌 Colab 或 Anaconda,那么 NumPy 应该已经被预安装了。但是为了演示,在本系列的前几篇文章中,我们都将在 Linux 终端上操作。在 Linux 终端上执行命令 ` python3` 进入 Python 控制台。在这个控制台中可以逐行执行 Python 代码。图 3 展示了在控制台中逐行运行 Python 代码,将两个向量相加,并输出结果。
|
||||
|
||||
![图 3:两个向量求和的 Python 代码][3]
|
||||
|
||||
首先,让我们试着逐行理解这些代码。由于本教程假定的编程经验很少,所以我将代码行标记为【基本】或【AI】。标记为【基本】的行是经典 Python 代码,标记为 【AI】的行是用于开发人工智能程序的代码。通过区分基本和进阶的 Python 代码,我希望具有基本知识和中级编程技能的程序员都能够高效地使用本教程。
|
||||
|
||||
```python
|
||||
import numpy as np 【基本】
|
||||
a = np.array([11, 22, 33]) 【AI】
|
||||
b = np.array([44, 55, 66]) 【AI】
|
||||
c = np.add(a, b) 【AI】
|
||||
print(c) 【基本】
|
||||
```
|
||||
|
||||
`import numpy as np` 导入 numpy 库并将其命名为 np。Python 中的 import 语句类似于在 C/C++ 用` #include `来包含头文件,或者在 Java 中用` import ` 来使用包。
|
||||
|
||||
`a = np.array([11, 22, 33])` 和 `b = np.array([44, 55, 66]) ` 分别创建了名为 `a` 和 `b` 的一维数组(为了便于理解,目前假设向量等价于一维数组)。
|
||||
|
||||
`c = np.add(a, b)` 将向量 `a` 和`b` 相加,并将结果存储在名为 `c` 的向量中。当然,用 `a`,`b`,`c` 作为变量名是一种糟糕的编程实践,但数学家倾向于将向量命名为 $u$、$v$、$w$ 等。如果你完全没有 Python 编程经验,请自行了解 Python 变量的相关知识。
|
||||
|
||||
`print(c)` 在终端上打印对象的值,即向量 `[55 77 99]`。你可以暂时这样理解向量相加, `c = [55=11+44 77=22+55 99=33+66]`。如果你想正式地了解向量和矩阵是如何相加的,但手头又没有相关的教材,我建议阅读维基百科上关于矩阵加法的文章。在网上搜索一下就会发现,用经典的 C/C++ 或 Java 程序来实现向量相加需要更多的代码。这说明 Python 很适合处理向量和矩阵。当我们执行越来越复杂的向量运算时,Python 的强大将进一步显现。
|
||||
|
||||
在我们结束本文之前,我要做两个声明。第一,上面讨论的示例只处理了两个行向量(确切地说是 1 x 3 的矩阵)的相加,但真正的机器学习应用可能要处理 1000000 X 1000000 的矩阵。但不用担心,通过练习和耐心,我们将能够处理这些问题。第二,本文中给出许多定义包含了粗略的简化和不充分的描述。但如前面所说,在本系列结束之前,我将给这些模糊的术语下一个正式的定义。
|
||||
|
||||
现在我们该结束这篇文章了。我希望所有人都安装文中提到的必要软件,并运行本文中的代码。在下一篇文章中,我们将首先讨论人工智能的历史、范畴和未来,然后深入探讨线性代数的支柱——矩阵论。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.opensourceforu.com/2022/08/artificial-intelligence-explaining-the-basics/
|
||||
|
||||
作者:[Deepu Benson][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[toknow-gh](https://github.com/toknow-gh)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.opensourceforu.com/author/deepu-benson/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/05/Figure-1-The-AI-hierarchy-and-data-science.jpg
|
||||
[2]: https://www.opensourceforu.com/wp-content/uploads/2022/05/Figure-2-A-2-X-3-matrix.jpg
|
||||
[3]: https://www.opensourceforu.com/wp-content/uploads/2022/05/Figure-3-Python-code-to-find-the-sum-of-two-row-vectors.jpg
|
Loading…
Reference in New Issue
Block a user