主页

索引

模块索引

搜索页面

Microsoft: AI-For-Beginners

I Introduction to AI

01 Introduction to AI

https://img.zhaoweiguo.com/uPic/2023/12/XRIsz4.png

Weak AI vs. Strong AI

  • Weak AI refers to AI systems that are designed and trained for a specific task or a narrow set of tasks.

  • Strong AI, or Artificial General Intelligence (AGI), refers to AI systems with human-level intelligence and understanding.

Different Approaches to AI

  • Top-down Approach (Symbolic Reasoning)

  • 自上而下的方法(符号推理)模拟一个人解决问题的方式。它涉及从人类中提取知识,并以计算机可读的形式表示。我们还需要开发一种在计算机内部模拟推理的方法。

  • Bottom-up Approach (Neural Networks)

  • 自下而上的方法(神经网络)模拟了人脑的结构,由大量称为神经元的简单单元组成。每个神经元都像是其输入的加权平均值,我们可以通过提供训练数据来训练神经元网络来解决有用的问题。

A Brief History of AI

https://img.zhaoweiguo.com/uPic/2023/12/qPY7mu.png
  • 人工智能始于二十世纪中叶的一个领域。最初,符号推理是一种流行的方法,它带来了许多重要的成功,例如专家系统——能够在一些有限的问题领域充当专家的计算机程序。然而,很快就发现这种方法不能很好地扩展。从专家那里提取知识,在计算机中表示知识,并保持知识库的准确性,这是一项非常复杂的任务,而且在许多情况下成本太高而无法实用。这导致了 1970 年代所谓的 AI 冬天。

  • 随着时间的流逝,计算资源变得越来越便宜,并且有更多的数据可用,因此神经网络方法开始在许多领域(例如计算机视觉或语音理解)中与人类竞争中表现出出色的性能。人工智能和神经网络成为同义词,大多数人工智能成功都是基于神经网络。

  • 在未来,我们可能会期待一个完整的基于神经的模型来单独处理对话。最近的 GPT 和 Turing-NLG 神经网络系列在这方面取得了巨大成功。

Recent AI Research

  • 2012 年,卷积神经网络首次用于图像分类,这导致分类误差显着下降(从近 30% 降至 16.4%)。2015年,Microsoft Research的ResNet架构达到了人类水平的准确性。

分类任务中达到人类水平的时间点:

Year    Human Parity achieved
2015    Image Classification
2016    Conversational Speech Recognition
2018    Automatic Machine Translation (Chinese-to-English)
2020    Image Captioning

II Symbolic AI

02 Knowledge Representation and Expert Systems

https://img.zhaoweiguo.com/uPic/2023/12/Op7fYT.png

Pre-lecture quiz

  • In the early days of AI, the top-down approach to creating intelligent systems (discussed in the previous lesson) was popular.

  • The idea was to extract the knowledge from people into some machine-readable form, and then use it to automatically solve problems.

  • This approach was based on two big ideas:

    Knowledge Representation
    Reasoning
    

Knowledge Representation

  • Knowledge is something which is contained in our head and represents our understanding of the world. It is obtained by an active learning process, which integrates pieces of information that we receive into our active model of the world.

https://img.zhaoweiguo.com/uPic/2023/12/x6dBTU.png

DIKW Pyramid

  • Data is something represented in physical media, such as written text or spoken words. Data exists independently of human beings and can be passed between people.

  • Information is how we interpret data in our head. For example, when we hear the word computer, we have some understanding of what it is.

  • Knowledge is information being integrated into our world model. For example, once we learn what a computer is, we start having some ideas about how it works, how much it costs, and what it can be used for. This network of interrelated concepts forms our knowledge.

  • Wisdom is yet one more level of our understanding of the world, and it represents meta-knowledge, eg. some notion on how and when the knowledge should be used.

Classifying Computer Knowledge Representations

  • Network representations: 基于这样一个事实,即我们的头脑中有一个相互关联的概念网络。我们可以尝试在计算机中复制与图形相同的网络 - 所谓的语义网络(semantic network)。

https://img.zhaoweiguo.com/uPic/2023/12/HwZXC1.png

由于图形可以在计算机内部表示为节点和边的列表,因此我们可以通过包含对象、属性和值的三元组列表来表示语义网络。Object-Attribute-Value triplets or attribute-value pairs

  • Hierarchical representations: 强调这样一个事实,即我们经常在头脑中创建对象的层次结构。例如,我们知道金丝雀是一种鸟,所有的鸟都有翅膀。

https://img.zhaoweiguo.com/uPic/2023/12/0Sk0QK.png
  • Procedural representations: 基于通过在特定条件发生时可以执行的操作列表来表示知识。例: if-then statements or Algorithms

  • Logic: 代表普遍人类知识的一种方式

Expert Systems

  • One of the early successes of symbolic AI

  • [定义]Expert Systems is computer systems that were designed to act as an expert in some limited problem domain. They were based on a knowledge base extracted from one or more human experts, and they contained an inference engine that performed some reasoning on top of it.

https://img.zhaoweiguo.com/uPic/2023/12/GlXTdL.png
  • Expert systems are built like the human reasoning system, which contains short-term memory and long-term memory.

  • Working memory: 包含有关当前正在解决的问题的知识

  • Knowledge base: 表示有关问题域的长期知识。它是从人类专家那里手动提取的,并且不会因咨询而改变。

  • Inference engine: 编排在问题状态空间中搜索的整个过程,必要时向用户提问。

Forward vs. Backward Inference
  • forward inference: It starts with some initial data about the problem available in the working memory, and then executes the following reasoning loop:

    1. If the target attribute is present in the working memory - stop and give the result
    2. Look for all the rules whose condition is currently satisfied - obtain conflict set of rules.
    3. Perform conflict resolution - select one rule(below) that will be executed on this step.
        first applicable rule
        random rule
        specific rule
    4. Apply selected rule and insert new piece of knowledge into the problem state
    5. Repeat from step 1.
    
  • backward inference: It is driven by the goal:

    1. Select all rules that can give us the value of a goal - a conflict set
    2. If there are no rules for this attribute,
        or there is a rule saying that we should ask the value from the user - ask for it,
    otherwise:
    3. Use conflict resolution strategy to select one rule that we will use as hypothesis
        - we will try to prove it
    4. Recurrently repeat the process for all attributes of the rule,
        trying to prove them as goals
    5. If at any point the process fails - use another rule at step 3.
    
Implementing Expert Systems
  • 直接用一些高级编程语言对它们进行编程。这不是最好的主意,因为基于知识的系统的主要优点是: 知识与推理是分开的,这样问题领域专家就可以在不了解推理过程细节的情况下编写规则

  • 使用专家系统外壳(expert systems shell),即专门设计为使用某种知识表示语言由知识填充的系统。

  • The important characteristics of knowledge-based systems is that you can always explain exactly how any of the decisions were made.基于知识的系统的重要特征是,你总是可以准确地解释任何决策是如何做出的。

Implementing Directly

class Ask():
    def __init__(self,choices=['y','n']):
        self.choices = choices
    def ask(self):
        if max([len(x) for x in self.choices])>1:
            for i,x in enumerate(self.choices):
                print("{0}. {1}".format(i,x),flush=True)
            x = int(input())
            return self.choices[x]
        else:
            print("/".join(self.choices),flush=True)
            return input()

class Content():
    def __init__(self,x):
        self.x=x
        
class If(Content):
    pass

class AND(Content):
    pass

class OR(Content):
    pass




rules = {
    'default': Ask(['y','n']),
    'color' : Ask(['red-brown','black and white','other']),
    'pattern' : Ask(['dark stripes','dark spots']),
    'mammal': If(OR(['hair','gives milk'])),
    'carnivor': If(OR([AND(['sharp teeth','claws','forward-looking eyes']),'eats meat'])),
    'ungulate': If(['mammal',OR(['has hooves','chews cud'])]),
    'bird': If(OR(['feathers',AND(['flies','lies eggs'])])),
    'animal:monkey' : If(['mammal','carnivor','color:red-brown','pattern:dark spots']),
    'animal:tiger' : If(['mammal','carnivor','color:red-brown','pattern:dark stripes']),
    'animal:giraffe' : If(['ungulate','long neck','long legs','pattern:dark spots']),
    'animal:zebra' : If(['ungulate','pattern:dark stripes']),
    'animal:ostrich' : If(['bird','long nech','color:black and white','cannot fly']),
    'animal:pinguin' : If(['bird','swims','color:black and white','cannot fly']),
    'animal:albatross' : If(['bird','flies well'])
}

class KnowledgeBase():
    def __init__(self,rules):
        self.rules = rules
        self.memory = {}
        
    def get(self,name):
        if ':' in name:
            k,v = name.split(':')
            vv = self.get(k)
            return 'y' if v==vv else 'n'
        if name in self.memory.keys():
            return self.memory[name]
        for fld in self.rules.keys():
            if fld==name or fld.startswith(name+":"):
                # print(" + proving {}".format(fld))
                value = 'y' if fld==name else fld.split(':')[1]
                res = self.eval(self.rules[fld],field=name)
                if res!='y' and res!='n' and value=='y':
                    self.memory[name] = res
                    return res
                if res=='y':
                    self.memory[name] = value
                    return value
        # field is not found, using default
        res = self.eval(self.rules['default'],field=name)
        self.memory[name]=res
        return res
                
    def eval(self,expr,field=None):
        # print(" + eval {}".format(expr))
        if isinstance(expr,Ask):
            print(field)
            return expr.ask()
        elif isinstance(expr,If):
            return self.eval(expr.x)
        elif isinstance(expr,AND) or isinstance(expr,list):
            expr = expr.x if isinstance(expr,AND) else expr
            for x in expr:
                if self.eval(x)=='n':
                    return 'n'
            return 'y'
        elif isinstance(expr,OR):
            for x in expr.x:
                if self.eval(x)=='y':
                    return 'y'
            return 'n'
        elif isinstance(expr,str):
            return self.get(expr)
        else:
            print("Unknown expr: {}".format(expr))

# 执行

kb = KnowledgeBase(rules)
kb.get('animal')


# 输出

hair
y/n
y
sharp teeth
y/n
y
claws
y/n
n
eats meat
y/n
y
color
0. red-brown
1. black and white
2. other
0
pattern
0. dark stripes
1. dark spots
0
tiger
Implementing with Expert Systems Shell

Ontologies and the Semantic Web

  • Semantic Web: 语义网

  • Ontologies: 本体论

  • At the end of 20th century there was an initiative to use knowledge representation to annotate Internet resources, so that it would be possible to find resources that correspond to very specific queries. This motion was called Semantic Web, and it relied on several concepts:

    A special knowledge representation based on description logics (DL).
    Distributed knowledge representation,
        where all concepts are represented by a global URI identifier,
        making it possible to create knowledge hierarchies that span the internet.
    A family of XML-based languages for knowledge description:
        RDF (Resource Description Framework),
        RDFS (RDF Schema),
        OWL (Ontology Web Language).
    

备注

语义网的一个核心概念是本体论的概念。它指的是使用一些正式的知识表示来明确规范问题域。最简单的本体可以只是问题域中对象的层次结构,但更复杂的本体将包括可用于推理的规则。

https://img.zhaoweiguo.com/uPic/2023/12/M4VdGA.png

在语义网中,所有表示都基于三元组。每个对象和每个关系都由 URI 唯一标识。例如,如果我们想说明这个人工智能课程是由德米特里·索什尼科夫(Dmitry Soshnikov)于2022年1月1日开发的。其中 http://www.example.com/terms/creation-datehttp://purl.org/dc/elements/1.1/creator 一些众所周知且普遍接受的 URI,用于表达创建者和创建日期的概念。

备注

搜索引擎和自然语言处理技术的成功在某种程度上减缓了构建语义网的进度,这些技术允许从文本中提取结构化数据。

  • WikiData 是维基百科页面中的结构化内容。您可以在SPARQL中查询维基数据,SPARQL是语义网的一种特殊查询语言。

  • DBpedia 是另一个类似于WikiData的努力

III Introduction to Neural Networks

https://img.zhaoweiguo.com/uPic/2023/12/UcdfmM.png
  • Neural Networks are a part of a larger discipline called Machine Learning, whose goal is to use data to train computer models that are able to solve problems.

the most common machine learning problems:

1. Classification, where we need to classify an input object into two or more classes.
2. Regression, where we need to predict a numerical number for each of the input samples.

03 Perceptron

  • one of the earliest neural network models for two-class classification

  • [history]One of the first attempts to implement something similar to a modern neural network was done by Frank Rosenblatt from Cornell Aeronautical Laboratory in 1957. It was a hardware implementation called “Mark-1”, designed to recognize primitive geometric figures, such as triangles, squares and circles.

Perceptron Model

  • Suppose we have N features in our model, in which case the input vector would be a vector of size N. A perceptron is a binary classification model, i.e. it can distinguish between two classes of input data.

Training the Perceptron

  • To train a perceptron we need to find a weights vector w that classifies most of the values correctly, i.e. results in the smallest error.

04 Multi-Layered Perceptron

备注

反向传播是 AI 和 ML 中常用的算法,值得更详细地研究: https://en.wikipedia.org/wiki/Backpropagation

05 Frameworks

IV Computer Vision

https://img.zhaoweiguo.com/uPic/2023/12/0pw0BM.png

06 Intro to Computer Vision and OpenCV

understanding of digital images can mean many different things:

finding an object on a picture (object detection),
understanding what is happening (event detection),
describing a picture in text,
reconstructing a scene in 3D.

several Python libraries available for image processing

  • imageio can be used for reading/writing different image formats. It also support ffmpeg, a useful tool to convert video frames to images.

  • Pillow (also known as PIL) is a bit more powerful, and also supports some image manipulation such as morphing, palette adjustments, and more.

  • OpenCV is a powerful image processing library written in C++, which has become the de facto standard for image processing. It has a convenient Python interface.

  • dlib is a C++ library that implements many machine learning algorithms, including some of the Computer Vision algorithms. It also has a Python interface, and can be used for challenging tasks such as face and facial landmark detection.

OpenCV

Loading Images:

import cv2
import matplotlib.pyplot as plt

im = cv2.imread('image.jpeg')
plt.imshow(im)
# openCV使用BGR解码,其他库使用RGB解码,所以要转一下
im = cv2.cvtColor(im,cv2.COLOR_BGR2RGB)

Image Processing:

Resizing the image
    im = cv2.resize(im, (320,200), interpolation=cv2.INTER_LANCZOS)
Blurring the image
    im = cv2.medianBlur(im,3)
    or
    im = cv2.GaussianBlur(im, (3,3), 0)
Changing the brightness and contrast of the image can be done by NumPy array manipulations

Examples of using Computer Vision

  • Pre-processing a photograph of a Braille book:

  • Detecting motion in video using frame difference:

  • Detecting motion using Optical Flow

  • 说明:这三个对应的例子都在 openCV 部分详解

07 Convolutional Neural Networks

08 Pre-trained Networks and Transfer Learning

09 Autoencoders

10 Generative Adversarial Networks

11 Object Detection

12 Semantic Segmentation

V. NLP

https://img.zhaoweiguo.com/uPic/2023/12/YOj8XE.png

13. Representing text as tensors

14. Word Embeddings

15. Language Modeling

16. Recurrent Neural Networks

17. Generative Networks

18. Transformers

19. NER

20. LangModels

VI. Other

21. GeneticAlgorithms

22. DeepRL

23. MultiagentSystems

VII. Ethics

主页

索引

模块索引

搜索页面