Computational Graph
ํจ์๋ฅผ ๋จ์ํํ์ฌ ๊ทธ๋ํ๋ก ํํํ๋ ํ๋ ์์ํฌ์ด๋ค. ์ซ์์ ์ฐ์ฐ์๋ฅผ ๋ชจ๋ ๋ถ๋ฆฌํ๋ฉฐ ๋
ธ๋์ Input์ผ๋ก ์ด๋ฃจ์ด์ ธ์๋ค. computational graph ๋ด๋ถ ๋ชจ๋ ๋ณ์๋ค์ ๊ฑฐ์ณ backpropagation๋ฅผ ์ฌ์ฉ ๊ฐ๋ฅํ๊ฒ ํ๋ค. ํจ์ f์ ์ถ๋ ฅ์ ๋ํ ์ด๋ค ๋ณ์์ gradient๋ฅผ ์ฐพ๊ณ ์ถ์ ๋ ํจ์ f๋ฅผ computational graph๋ก ๋ํ๋ด๋ ๊ฒ์ด ์ฒซ ๋ฒ์งธ step์ด๋ค.
ย
์์) AlexNet, Neural Turing Machine
ย
๋ชจ๋ํ
Computational Graph์์ ์ค์ ๋ก ๋ชจ๋ํ๋ ๊ตฌํ์ด๋ค. forward/backward๊ณผ์ ์ ์ ์ํํ๊ธฐ ์ํด์๋ ๋ชจ๋ํ๊ฐ ํ์ํ๋ค.
forward pass์์๋ ๋
ธ๋์ ์ถ๋ ฅ์ ๊ณ์ฐํ๋ ํจ์๋ฅผ ๊ตฌํํ๋๋ฐ ์ด๋ ์์ ํ ๊ทธ๋ํ๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ฉด ๊ทธ๋ํ์ ๋ชจ๋ ๋
ธ๋๋ฅผ ๋ฐ๋ณตํ์ฌ forward pass๋ก ํต๊ณผ์ํจ๋ค.
backward pass์์๋ chain rule์ ์ด์ฉํด gradient๋ฅผ ๊ณ์ฐํ๋ค.
class ComputationalGraph(object): def forward(inputs): #1. [pass inputs to input gates...] #2. forward the computational graph: for gate in self.graph.modes_topologically_sorted(): gate.forward() retrun loss # the final gate in the graph outputs the loss def backward(): for gate in reversed(self.graph.nodes_topologically_sorted()): gate.backward() #little piece of backprop (chain rule applied) return inputs_gradients
ย