swh:1:snp:f50ab94432af916b5fb8b4ad831e8dddded77084
Raw File
Tip revision: 2003303aba820a91be4b2db9788d15db14cff6dd authored by Frank Seide on 08 September 2020, 19:38:44 UTC
some updates, Marian-related
Tip revision: 2003303
lr_bs.cntk
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

# logistic regression cntk script -- using network description language BrainScript

# which commands to run
command=Train:Output:DumpNodeInfo:Test

# required...
modelPath = "Models/LR_reg.dnn"  # where to write the model to
deviceId = -1                    # -1 means CPU; use 0 for your first GPU, 1 for the second etc.
dimension = 2                    # input data dimensions

# training config
Train = [             # command=Train --> CNTK will look for a parameter named Train
    action = "train"  # execute CNTK's 'train' routine
        
    # network description
    BrainScriptNetworkBuilder = [

        # sample and label dimensions
        SDim = $dimension$
        LDim = 1

        features = Input (SDim)
        labels   = Input (LDim)

        # parameters to learn
        b = Parameter (LDim, 1)     # bias
        w = Parameter (LDim, SDim)  # weights

        # operations
        p = Sigmoid (w * features + b)    
    
        lr = Logistic (labels, p)
        err = SquareError (labels, p)

        # root nodes
        featureNodes    = (features)
        labelNodes      = (labels)
        criterionNodes  = (lr)
        evaluationNodes = (err)
        outputNodes     = (p)
    ]   

    # configuration parameters of the SGD procedure
    SGD = [
        epochSize = 0                  # =0 means size of the training set
        minibatchSize = 25
        learningRatesPerSample = 0.04  # gradient contribution from each sample
        maxEpochs = 50
    ]

    # configuration of data reading
    reader = [

        readerType = "CNTKTextFormatReader"
        file = "Train_cntk_text.txt"

        input = [
            features = [
                dim = $dimension$
                format = "dense"
            ]
            labels = [
                dim = 1
                format = "dense"
            ]
        ]
    ]
]

# test
Test = [
    action = "test"
    reader = [
        readerType = "CNTKTextFormatReader"
        file = "Test_cntk_text.txt"
        input = [
            features = [
                dim = $dimension$
                format = "dense"
            ]
            labels = [
                dim = 1
                format = "dense"
            ]
        ]
    ]
]

# output the results
Output = [
    action = "write"
    reader = [
        readerType = "CNTKTextFormatReader"
        file = "Test_cntk_text.txt"
        input = [
            features = [
                dim = $dimension$  # $$ means variable substitution
                format = "dense"
            ]
            labels = [
                dim = 1            # label has 1 dimension
                format = "dense"
            ]
        ]
    ]
    outputPath = "LR.txt"  # dump the output to this text file
]

# dump parameter values
DumpNodeInfo = [
    action = "dumpNode"
    printValues = true
]
back to top