Class ComputationGraphConfiguration.GraphBuilder

    • Field Detail

      • vertexInputs

        protected Map<String,​List<String>> vertexInputs
        Key: graph node. Values: input to that node
      • networkInputs

        protected List<String> networkInputs
      • networkOutputs

        protected List<String> networkOutputs
      • tbpttFwdLength

        protected int tbpttFwdLength
      • tbpttBackLength

        protected int tbpttBackLength
      • allowDisconnected

        protected boolean allowDisconnected
      • allowNoOutput

        protected boolean allowNoOutput
      • validateOutputConfig

        protected boolean validateOutputConfig
      • validateTbpttConfig

        protected boolean validateTbpttConfig
      • lastAdded

        protected String lastAdded
    • Method Detail

      • backpropType

        public ComputationGraphConfiguration.GraphBuilder backpropType​(BackpropType type)
        The type of backprop. Default setting is used for most networks (MLP, CNN etc), but optionally truncated BPTT can be used for training recurrent neural networks. If using TruncatedBPTT make sure you set both tBPTTForwardLength() and tBPTTBackwardLength()
        Parameters:
        type - Type of backprop. Default: BackpropType.Standard
      • tBPTTForwardLength

        public ComputationGraphConfiguration.GraphBuilder tBPTTForwardLength​(int forwardLength)
        When doing truncated BPTT: how many steps of forward pass should we do before doing (truncated) backprop?
        Only applicable when doing backpropType(BackpropType.TruncatedBPTT)
        Typically tBPTTForwardLength parameter is same as the tBPTTBackwardLength parameter, but may be larger than it in some circumstances (but never smaller)
        Ideally your training data time series length should be divisible by this This is the k1 parameter on pg23 of http://www.cs.utoronto.ca/~ilya/pubs/ilya_sutskever_phd_thesis.pdf
        Parameters:
        forwardLength - Forward length > 0, >= backwardLength
      • addLayer

        public ComputationGraphConfiguration.GraphBuilder addLayer​(String layerName,
                                                                   Layer layer,
                                                                   InputPreProcessor preProcessor,
                                                                   String... layerInputs)
        Add a layer and an InputPreProcessor, with the specified name and specified inputs.
        Parameters:
        layerName - Name/label of the layer to add
        layer - The layer configuration
        preProcessor - The InputPreProcessor to use with this layer.
        layerInputs - Inputs to this layer. Inputs may be other layers, GraphVertex objects, on a combination of the two.
      • layer

        public ComputationGraphConfiguration.GraphBuilder layer​(String layerName,
                                                                Layer layer,
                                                                InputPreProcessor preProcessor,
                                                                String... layerInputs)
        Add a layer and an InputPreProcessor, with the specified name and specified inputs.
        Parameters:
        layerName - Name/label of the layer to add
        layer - The layer configuration
        preProcessor - The InputPreProcessor to use with this layer.
        layerInputs - Inputs to this layer. Inputs may be other layers, GraphVertex objects, on a combination of the two.
      • removeVertex

        public ComputationGraphConfiguration.GraphBuilder removeVertex​(String vertexName)
        Intended for use with the transfer learning API. Users discouraged from employing it directly. Removes the specified vertex from the vertices list, it's connections and associated preprocessor If the vertex removed is an output vertex it will also be removed from the list of outputs
        Parameters:
        vertexName - Name of the vertex to remove
      • removeVertex

        public ComputationGraphConfiguration.GraphBuilder removeVertex​(String vertexName,
                                                                       boolean removeConnections)
        Intended for use with the transfer learning API. Users discouraged from employing it directly. Removes the specified vertex from the vertices list, Removes it's connections (associated preprocessor and if an output also removes it from list of outputs) if "removeConnections" is specified as true Specifying as false can leave the graph in an invalid state with references to vertices that donot exist unless a new vertex is added back in with the same name
        Parameters:
        removeConnections - Specify true to remove connections
        vertexName - Name of the vertex to remove
      • addInputs

        public ComputationGraphConfiguration.GraphBuilder addInputs​(String... inputNames)
        Specify the inputs to the network, and their associated labels.
        Parameters:
        inputNames - The names of the inputs. This also defines their order
      • setInputTypes

        public ComputationGraphConfiguration.GraphBuilder setInputTypes​(InputType... inputTypes)
        Specify the types of inputs to the network, so that:
        (a) preprocessors can be automatically added, and
        (b) the nIns (input size) for each layer can be automatically calculated and set
        The order here is the same order as .addInputs(). Thus, if you do .addInputs("a","b") and .setInputTypes(InputType.feedForward(), InputType.convolutional(28,28,1)) then the input labelled "a" is a feed forward input, whereas the input labelled "b" in a CNN input, with 28x28x1 images as input.
        Note: Using setInputTypes is not always necessary, but can be especially helpful for example with CNNs such that the calculations on input/output sizes (width, height, channels, etc) don't need to be done manually.
        Note 2: If a preprocessor is manually added for a given layer, it will not be overridden by the automatic addition of preprocessors. Note 3: If a layer has an nIn set manually, this will not be overridden
      • setOutputs

        public ComputationGraphConfiguration.GraphBuilder setOutputs​(String... outputNames)
        Set the network output labels. These should be the names of the OutputLayer instances in the network
        Parameters:
        outputNames - The names of the output layers. This also defines their order.
      • addVertex

        public ComputationGraphConfiguration.GraphBuilder addVertex​(String vertexName,
                                                                    GraphVertex vertex,
                                                                    String... vertexInputs)
        Add a GraphVertex to the network configuration. A GraphVertex defines forward and backward pass methods, and can contain a LayerVertex, a ElementWiseVertex to do element-wise addition/subtraction, a MergeVertex to combine/concatenate the activations out of multiple layers or vertices, a SubsetVertex to select a subset of the activations out of another layer/GraphVertex.
        Custom GraphVertex objects (that extend the abstract GraphVertex class) may also be used.
        Parameters:
        vertexName - The name of the GraphVertex to add
        vertex - The GraphVertex to add
        vertexInputs - The inputs/activations to this GraphVertex.
      • appendVertex

        public ComputationGraphConfiguration.GraphBuilder appendVertex​(String vertexName,
                                                                       GraphVertex vertex)
        Add a GraphVertex to the network configuration, with input from the last added vertex/layer. A GraphVertex defines forward and backward pass methods, and can contain a LayerVertex, a ElementWiseVertex to do element-wise addition/subtraction, a MergeVertex to combine/concatenate the activations out of multiple layers or vertices, a SubsetVertex to select a subset of the activations out of another layer/GraphVertex.
        Custom GraphVertex objects (that extend the abstract GraphVertex class) may also be used.
        Parameters:
        vertexName - The name of the GraphVertex to add
        vertex - The GraphVertex to add
      • allowDisconnected

        public ComputationGraphConfiguration.GraphBuilder allowDisconnected​(boolean allowDisconnected)
        Used only during validation after building.
        If true: don't throw an exception on configurations containing vertices that are 'disconnected'. A disconnected vertex is one that is not an output, and doesn't connect to any other vertices. i.e., it's output activations don't go anywhere. Most users can (and should) leave this as the default value of false.
        Parameters:
        allowDisconnected - Whether to allow disconnected vertices, during validation
      • allowNoOutput

        public ComputationGraphConfiguration.GraphBuilder allowNoOutput​(boolean allowNoOutput)
        Used only during validation after building.
        If true: don't throw an exception on configurations without any outputs. This is enabled by default to avoid creating invalid graphs, but can be disabled if required.
        Most users can (and should) leave this as the default value of false.
        Parameters:
        allowNoOutput - Whether to allow no outputs, during validation
      • validateOutputLayerConfig

        public ComputationGraphConfiguration.GraphBuilder validateOutputLayerConfig​(boolean validate)
        Enabled by default. If enabled, the output layer configuration will be validated, to throw an exception on likely invalid outputs - such as softmax + nOut=1, or LossMCXENT + Tanh.
        If disabled (false) no output layer validation will be performed.
        Disabling this validation is not recommended, as the configurations that fail validation usually will not be able to learn correctly. However, the option to disable this validation is provided for advanced users when creating non-standard architectures.
        Parameters:
        validate - If true: validate output layer configuration. False: don't validate
      • validateTbpttConfig

        public ComputationGraphConfiguration.GraphBuilder validateTbpttConfig​(boolean validate)
        Enabled by default. If enabled, an exception will be throw when using the (invalid) combination of truncated backpropagation through time (TBPTT) with either a GlobalPoolingLayer or LastTimeStepLayer.
        It is possible to disable this validation to allow what is almost certainly an invalid configuration to be used, however this is not recommended.
        Parameters:
        validate - Whether TBPTT validation should be performed
      • getLayerActivationTypes

        public Map<String,​InputType> getLayerActivationTypes()
        For the (perhaps partially constructed) network configuration, return a map of activation sizes for each layer and vertex in the graph.
        Note 1: The network configuration may be incomplete, but the inputs have been added to the layer already.
        Note 2: To use this method, the network input types must have been set using setInputTypes(InputType...) first
        Returns:
        A map of activation types for the graph (key: vertex name. value: type of activations out of that vertex)