プリンキピア

第6章構築者のための手引き

6.5. Custom Layers6.5 独自の層

One factor behind deep learning’s success is the availability of a wide range of layers that can be composed in creative ways to design architectures suitable for a wide variety of tasks. For instance, researchers have invented layers specifically for handling images, text, looping over sequential data, and performing dynamic programming. Sooner or later, you will need a layer that does not exist yet in the deep learning framework. In these cases, you must build a custom layer. In this section, we show you how.
英語のヒント
深層学習が成功した要因の一つは、多種多様な課題に適した構造を設計するために工夫して組み合わせられる、幅広い種類の層が手に入ることである。たとえば研究者たちは、画像やテキストを扱うため、系列データにわたってループを回すため、動的計画法を行うために、特別な層を考案してきた。遅かれ早かれ、深層学習のフレームワークにまだない層が必要になるだろう。そうした場合には、独自の層を作らなければならない。この節では、その方法を示す。
import torch
from torch import nn
from torch.nn import functional as F
from d2l import torch as d2l