Typo.
[dagnn.git] / README.md
1
2 This package implements a new module nn.DAG which inherits from nn.Container and allows to combine modules in an arbitrary graph without cycle.
3
4 #Example#
5
6 A typical use would be:
7
8 ```Lua
9 model = nn.DAG()
10
11 a = nn.Linear(100, 10)
12 b = nn.ReLU()
13 c = nn.Linear(10, 15)
14 d = nn.CMulTable()
15 e = nn.Linear(15, 15)
16
17 model:addEdge(a, b)
18 model:addEdge(b, nn.Linear(10, 15), nn.ReLU(), d)
19 model:addEdge(b, c)
20 model:addEdge(c, d)
21 model:addEdge(c, nn.Mul(-1), e)
22
23 model:setInput(a)
24 model:setOutput({ d, e })
25
26 input = torch.Tensor(30, 100):uniform()
27 output = model:updateOutput(input)
28
29 ```
30
31 which would encode the following graph
32
33                  +- Linear(10, 10) -> ReLU ---> d -->
34                 /                              /
35                /                              /
36     --> a --> b -----------> c --------------+
37                               \
38                                \
39                                 +-- Mul(-1) --> e -->
40
41 and run a forward pass with a random batch of 30 samples.
42
43 Note that DAG:addEdge
44
45 #Input and output#
46
47 If a node has a single successor, its output is sent unchanged as input to that successor. If it has multiple successors, the outputs are collected into a table, and the table is used as input to the successor node. The indexes of the outputs in that table reflects the order in which they appear in the addEdge commands.
48
49 The expected input (respectively the produced output) is a nested table of inputs reflecting the structure of the nested table of modules provided to DAG:setInput (respectively DAG:setOutput)
50
51 So for instance, in the example above, the model expects a tensor as input, since it is the input to the module a, and its output will is a table composed of two tensors, corresponding to the outputs of d and e respectively.
52
53 *Francois Fleuret, Jan 12th, 2017*