AI 入门,从数据、训练到可观察结果
从日常任务认识 AI 的能力范围,并用本机练习区分训练、推理和工具动作。
学完这一章,你能够
- 从日常任务认识 AI 的能力范围,并用本机练习区分训练、推理和工具动作。
从一个小任务认识 AI
人工智能可以从输入中提取信息、生成内容、作出预测,或在授权下调用工具。传统程序也能自动执行任务,差别在于某些判断规则可从样本中学得。许多系统会把规则、模型和工具组合使用。
这门入门课适合首次接触 AI 的读者,也适合希望改善办公、设计、运营和开发流程的人。可先从改写段落、整理表格、看图或阅读一段代码开始。先把结果格式、验收条件和需要人复查的步骤写清楚。
感知、理解、推理和执行
感知输入可能是文字、图片、语音或视频。理解需求时要识别关键内容和条件。推理可在候选方案中按约束选择,也可能给出错误方案。执行会改变文件、记录或其他系统,适合独立做权限检查。
试着给对话助手一个明确学习任务。可写“我是零基础,每周可学两小时。请给我四周计划,每周列一个练习和检查结果的方法”。检查回答是否满足时间和成果约束,也可补充背景后重新提问。公开课中的聊天工具只是入口,界面选项、模型和结果会随版本与账号变化。
四个概念和一次本机训练
数据是用于学习或验证的样本,算法定义怎么从样本得到规则,模型是训练后的参数和结构,推理是用固定模型处理新输入。模型能利用上下文响应新要求,权重更新通常需要专门的训练流程。
本机样本根据词项区分退款和物流。原模型对 reimburse 没有足够证据,因此进入复核。追加一条已标注的退款样本,再训练得到一个新模型,才改变同一输入的结果。打开实例切换训练前后的结果。下图显示追加样本后的实际输出。

按任务和风险选用方式
语言、视觉、语音、多模态和自动化是便于入门的任务视角。一个产品可以同时具备几类能力。要分别检查输入格式、所用模型、输出品质和所需权限。
本机读取图像像素和 WAV 样本,再用文字阈值解释图像结果。对文件自动化则先给预期和确认条件,确认后才实际写出样本报告。业务资料和外部工具的访问仍须通过自己的权限设置。
五类常见 AI 任务
| 类型 | 输入与结果 | 典型任务 | 常见工具或入口 |
|---|---|---|---|
| 语言 | 理解或生成文本。 | 对话、写作、代码、翻译、摘要和问答。 | ChatGPT、Claude、Qwen、豆包等助手可用于文本任务。 |
| 视觉 | 从图像或视频提取信息,或根据条件生成视觉内容。 | 识别、修图、绘图、剪辑、检测和证件照处理。 | 视觉生成可用 Midjourney、Stable Diffusion。美图和剪辑产品也可能提供视觉功能。 |
| 语音 | 从声音提取文字或由文字合成语音。 | 转写、字幕、配音、语音翻译和语音助手。 | 讯飞听见、剪映字幕和手机语音助手面向不同的交互任务。 |
| 多模态 | 在同一任务中联合处理文字、图像、语音或视频。 | 图文问答、图文创作、视频理解和多格式生成。 | 一些豆包与 Qwen 模型支持多种输入。GPT-4V 是历史视觉模型名称,应用搭建平台能力另看其运行配置。 |
| 自动化智能体 | 把模型、工具和规则串成可控制的任务流程。 | 文件整理、数据分析、报表、演示文稿和批处理。 | QoderWork 等面向任务的入口和 n8n 工作流面向不同的自动化需求。 |
训练一个小型模型并控制文件动作
"""Train a small intent model and test local data, modalities and action controls."""
from collections import Counter, defaultdict
from math import sqrt
from pathlib import Path
import re
import struct
import wave
from lab_tools import run_exercise
def words(text):
return re.findall(r"[a-z]+",text.casefold())
def fit(examples):
counts=defaultdict(Counter)
for text,label in examples:
counts[label].update(words(text))
return dict(counts)
def infer(model,text):
scores={label:sum(count[word] for word in words(text)) for label,count in model.items()}
high=max(scores.values(),default=0)
leaders=[label for label,score in scores.items() if score==high and high>0]
return (leaders[0] if len(leaders)==1 else "review"),scores
def pixel_count(path):
header,dimensions,maximum,pixels=path.read_bytes().split(b"\n",3)
assert (header,dimensions,maximum)==(b"P6",b"2 2",b"255") and len(pixels)==12
return sum(pixels[i]>200 and pixels[i+1]<40 and pixels[i+2]<40 for i in range(0,12,3))
def read_wave(path):
with wave.open(str(path),"rb") as audio:
rate=audio.getframerate()
assert audio.getsampwidth()==2 and audio.getnchannels()==1
frames=audio.getnframes()
data=struct.unpack("<"+"h"*frames,audio.readframes(frames))
return [rate,frames,int(sqrt(sum(sample**2 for sample in data)/frames))]
def report(workspace,total,approved):
if not approved:
return "confirmation_needed"
(workspace/"report.txt").write_text(f"Count: {total}\n",encoding="utf8")
return "file_created"
def exercise(checks,workspace):
expect=checks.expect
samples=[("refund parcel","refund"),("return parcel","refund"),
("track parcel","tracking"),("shipping parcel status","tracking")]
model=fit(samples)
prompts=["refund request","shipping status","parcel","reimburse"]
expect("ai_fit_infer",prompts,"Use learned term counts and send ties or missing evidence to review",
["refund","tracking","review","review"],[infer(model,prompt)[0] for prompt in prompts])
example=("reimburse","refund")
updated=fit([*samples,example])
expect("ai_training_boundary",example,"Fit a separate model and compare the same input against the old model",
["review","refund",{"refund":0,"tracking":0},{"refund":1,"tracking":0}],
[infer(model,example[0])[0],infer(updated,example[0])[0],
infer(model,example[0])[1],infer(updated,example[0])[1]])
ppm=workspace/"small.ppm"
ppm.write_bytes(b"P6\n2 2\n255\n"+bytes([255,0,0,0,0,0,230,10,5,0,255,0]))
colors=pixel_count(ppm)
expect("ai_vision_input","2 x 2 PPM","Read image bytes and count pixels that satisfy the declared rule",2,colors)
wav=workspace/"small.wav"
with wave.open(str(wav),"wb") as audio:
audio.setparams((1,2,8000,0,"NONE","not compressed"))
audio.writeframes(struct.pack("<hhhh",1000,-1000,1000,-1000))
expect("ai_audio_input","4 signed PCM frames","Decode samples and read rate, frame count and RMS",
[8000,4,1000],read_wave(wav))
conditions=[1,2,3]
expect("ai_mixed_input",conditions,"Combine measured pixel count with three text thresholds",
[True,True,False],[colors>=threshold for threshold in conditions])
path=workspace/"report.txt"
before=report(workspace,colors,False)
untouched=not path.exists()
after=report(workspace,colors,True)
expect("ai_controlled_action",[False,True],"Verify no file until approval, then read the actual saved report",
["confirmation_needed",True,"file_created","Count: 2\n"],
[before,untouched,after,path.read_text(encoding="utf8")])
if __name__=="__main__":
run_exercise(exercise)
- 原模型将 reimburse 送复核。加入已标注样本重新训练后得到退款。确认后才创建报告。
所需环境:Python 3.12.14,标准库、临时图像和 WAV 文件、现代浏览器。
当前源码 SHA256:f6319b8c69d63862d32e2f92b6caea1a6be4f4b747e076d6499b797dc9f9a8d6
运行本站入门练习
ZIP 包含本机训练、图像与声音数据生成和浏览器观察。
所需环境:Python 3.12.14,标准库、临时图像和 WAV 文件、现代浏览器。
ZIP SHA256:d89356de83f5beb53bcd3299dd402adb9b4285405ba96b4a6362c64c3018d888
常见错误与边界
- 未注明模型和数据版本时,示例结果难以复查。
- 生成文字、图像或计划后,按真实结果验证再执行动作。
练习与解答
打开本机观察页,点击“追加样本后”,对比同一输入和两类分数。
展开参考解答
训练前两个分数均为 0。追加已标注样本后退款为 1,物流仍为 0。