AI 与机器学习iamtrask.github.io
用 11 行 Python 实现神经网络
A Neural Network in 11 Lines of Python
2015 — 2017,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章用 11 行核心 Python 代码(外加 NumPy 导入)从零实现一个简单神经网络,并用反向传播在小型数据集上训练,逐行讲解前向传播、sigmoid 激活、误差计算和权重更新;文中还扩展到多层网络。
为什么经久不衰:它用最少代码把神经网络和反向传播的核心机制讲清楚,是理解底层原理而非只调库的经典入门。
HN 评论精选
用 Keras 高层库几行即可完成同样的训练,对比手写实现。
作为对比,用库实现几乎一样:同样的 X/y,用 Keras 的 Sequential 加一个 Dense(3,1, uniform 初始化, sigmoid 激活),编译时损失用平均绝对误差、优化器用 sgd,训练 10000 轮后预测。
elyase查看英文原文
Just for comparison this is almost the same using a library [1]: import numpy as np X = np.array([ [0,0,1],[0,1,1],[1,0,1],[1,1,1]]) y = np.array([[0,0,1,1]]).T from keras.models import Sequential from keras.layers.core import Dense model = Sequential([Dense(3, 1, init='uniform', activation='sigmoid')]) model.compile(loss='mean_absolute_error', optimizer='sgd') model.fit(X, y, nb_epoch=10000) model.predict(X) [1] http://keras.io
称赞教程但指出权重更新和三层网络初始化解释不够直观。
谢谢,解释得很好。不过讲到更新如何发生时,感觉不如前面顺畅,至少没有前面那么像逐步讲解。另外,三层网络里的第 22、23 行对初学者不直观:之前 syn0 是 (3,1),现在变成 (3,4),新加的 syn1 是 (4,1)。你之前对初始化的解释要好得多。不过还是做得很棒,我只是挑刺,非常感谢!
avyfain查看英文原文
Thanks for this. It is really well explained. However, it did feel like it went downhill when you explained how the updating happens. At least it was less of a walkthrough than the previous sections. Also, lines 22 and 23 in the three layer network are not intuitive for a beginner. Before, syn0 was (3,1) and now its (3,4), and the new syn1 is (4,1). Your previous explanation for this initialization was much better. But again, awesome work, just being nitpicky. Really appreciate it!
询问进阶学习路径,并指出简单教程中 ReLU 易不稳定、高斯激活更稳的实践经验。
我学完这个教程(很棒!)和其他几个教程后,很好奇:对随意的神经网络学习者来说,好的第二步是什么?听说研究者积累了很多让大规模数据训练实用且稳定的技巧。一个例子是用 ReLU 激活——我在这种简单教程里试 ReLU 时,训练经常爆炸或失败,所以我猜要么漏了别的步骤,要么初始条件有额外约束?我在教程里用高斯激活往往更稳定、收敛更快,但我猜非单调递增函数某处有巨大缺点?周末爱好者应该研究哪些行业技巧?
dahart查看英文原文
Having gone through this tutorial (which is great!) and several others, I'm curious what is a good second step for the casual neural network learner? It sounds like there is a growing bag of tricks neural network researchers are discovering to make training practical and stable for large data sets. One example would be using relu activation - whenever I play with it in a simple tutorial like this one, training seems to explode and fail much more frequently, so I'm guessing either I'm missing another step people use, or there are some extra constraints on initial conditions? Using a Gaussian for activation in my tutorials has tended to be more stable and converge much faster, but I assume there is a huge downside lurking somewhere to having a non-monotonically increasing function? What are the tricks of the trade that a weekend warrior should investigate?
推荐 3blue1brown 的神经网络视频系列作为互补学习材料。
3blue1brown 目前正在做一个很棒的神经网络原理系列,和这篇博客文章互补得很好。
ocharles查看英文原文
3blue1brown is currently doing a terrific series on how neural networks work, which nicely compliments this blog post. https://www.youtube.com/watch?v=aircAruvnKk&list=PLZHQObOWTQDNU6R1_67000Dx_ZCJB-3pi
历次讨论
同类还值得读
如何写一个拼写纠正器
How to Write a Spelling Corrector
Peter Norvig 用一个几十行的 Python 程序演示如何做拼写纠正:先用编辑距离(删除、插入、替换、换位)生成所有可能的候选词,再用从大量文本中统计出的词频概率,选出…
AI 与机器学习上首页 10 次 · 2007–2022norvig.com编辑精选面向黑客的概率编程与贝叶斯方法
Probabilistic Programming and Bayesian Methods for Hackers (2013)
《黑客的贝叶斯方法与概率编程》是一本开源的贝叶斯统计入门书,以 Python/PyMC 代码和交互式 Jupyter Notebook 为主线,强调“先实践、后数学”的学习路径,…
AI 与机器学习上首页 5 次 · 2013–2018camdavidsonpilon.github.io编辑精选神经网络黑客指南
Hacker's Guide to Neural Networks
Andrej Karpathy 写的神经网络入门教程,面向程序员,从最简单的表达式求导讲起,逐步推导出反向传播和梯度下降,最后引出神经网络。
AI 与机器学习上首页 4 次 · 2014–2019karpathy.github.io编辑精选神经网络能逼近任意函数的可视化证明
A visual proof that neural nets can approximate any function
这一章来自 Michael Nielsen 的在线书《Neural Networks and Deep Learning》,用 sigmoid 单元叠加成局部隆起/平滑阶跃的图示…
AI 与机器学习上首页 4 次 · 2014–2022neuralnetworksanddeeplearning.com编辑精选论乔姆斯基与统计学习的两种文化
On Chomsky and the Two Cultures of Statistical Learning
Norvig 回应 Chomsky 对统计语言模型批评的文章,围绕“统计学习能否解释语言”展开,比较生成与解释、少参数模型与 Shannon 式高参数统计模型。
AI 与机器学习上首页 4 次 · 2011–2025norvig.com编辑精选