プリンキピア

第3章回帰のための線形ニューラルネットワーク

3.5. Concise Implementation of Linear Regression3.5 線形回帰の簡潔な実装

Deep learning has witnessed a sort of Cambrian explosion over the past decade. The sheer number of techniques, applications and algorithms by far surpasses the progress of previous decades. This is due to a fortuitous combination of multiple factors, one of which is the powerful free tools offered by a number of open-source deep learning frameworks. Theano (Bergstra et al., 2010), DistBelief (Dean et al., 2012), and Caffe (Jia et al., 2014) arguably represent the first generation of such models that found widespread adoption. In contrast to earlier (seminal) works like SN2 (Simulateur Neuristique) (Bottou and Le Cun, 1988), which provided a Lisp-like programming experience, modern frameworks offer automatic differentiation and the convenience of Python. These frameworks allow us to automate and modularize the repetitive work of implementing gradient-based learning algorithms.
英語のヒント
深層学習は、ここ10年で一種のカンブリア爆発を経験してきた。技術、応用、アルゴリズムの数の多さは、それまでの数十年の進歩をはるかにしのぐ。これは複数の要因の幸運な組み合わせによるもので、その一つが、いくつものオープンソースの深層学習フレームワークが提供する強力な無料の道具である。Theano(Bergstra et al., 2010)、DistBelief(Dean et al., 2012)、Caffe(Jia et al., 2014)は、広く採用された、こうしたモデルの第一世代を代表すると言えるだろう。Lispのようなプログラミング体験を提供したSN2(Simulateur Neuristique)(Bottou and Le Cun, 1988)のような初期の(画期的な)仕事と違って、現代のフレームワークは自動微分とPythonの便利さを提供する。これらのフレームワークのおかげで、勾配にもとづく学習アルゴリズムを実装する繰り返しの作業を、自動化しモジュール化できる。
In Section 3.4, we relied only on (i) tensors for data storage and linear algebra; and (ii) automatic differentiation for calculating gradients. In practice, because data iterators, loss functions, optimizers, and neural network layers are so common, modern libraries implement these components for us as well. In this section, we will show you how to implement the linear regression model from Section 3.4 concisely by using high-level APIs of deep learning frameworks.
英語のヒント
3.4節では、(i)データの保存と線形代数のためのテンソルと、(ii)勾配を計算するための自動微分だけに頼った。実際には、データのイテレータ、損失関数、最適化手法、ニューラルネットワークの層はとてもよく使われるので、現代のライブラリはこれらの構成要素も私たちのために実装してくれている。この節では、深層学習フレームワークの高水準APIを使って、3.4節の線形回帰モデルを簡潔に実装する方法を示す。
import numpy as np
import torch
from torch import nn
from d2l import torch as d2l