我一直在研究CNTK,并决定为xor函数创建一个创建模型,以确保我了解基本知识。我在下面创建了文件,但是由于该模型确实非常糟糕,所以我想我缺少一些基本知识。

command = Train:Output:DumpNodeInfo

modelPath = "Models\xor.dnn"
deviceId = -1
makeMode = false
featureDimension = 2
labelDimension = 1

Train = [
    action = "train"

    BrainScriptNetworkBuilder = {
        FDim = $featureDimension$
        LDim = $labelDimension$

        features = Input {FDim}
        labels = Input {LDim}

        W0 = ParameterTensor {(FDim:FDim)} ; b0 = ParameterTensor {FDim}
        W1 = ParameterTensor {(LDim:FDim)} ; b1 = ParameterTensor {LDim}
        o1 = W0*features + b0
        z = Sigmoid (W1*o1 + b1)

        ce = SquareError (labels, z)
        errs = ClassificationError (labels, z)

        # root nodes
        featureNodes    = (features)
        labelNodes      = (labels)
        criterionNodes  = (ce)
        evaluationNodes = (errs)
        outputNodes     = (z)
    }

    SGD = [
        epochSize = 0
        minibatchSize = 1
        learningRatesPerSample = 0.4
        maxEpochs = 50
    ]

    reader=[
        readerType="CNTKTextFormatReader"
        file="Train_xor.txt"

        input = [
            features = [
                dim = $featureDimension$
                alias = X
                format = "dense"
            ]
            labels = [
                dim = $labelDimension$
                alias = y
                format = "dense"
            ]
        ]
    ]
]

Output = [
    action="write"
    reader=[
        readerType="CNTKTextFormatReader"
        file="Train_xor.txt"

        input = [
            features = [
                dim = $featureDimension$
                alias = X
                format = "dense"
            ]
            labels = [
                dim = $labelDimension$
                alias = y
                format = "dense"
            ]
        ]
    ]
    outputNodeNames = z
    outputPath = "Output\xor.txt"
]

DumpNodeInfo = [
    action = "dumpNode"
    printValues = true
]


输入文件如下所示

|y 0 |X 0 0
|y 1 |X 1 0
|y 1 |X 0 1
|y 0 |X 1 1


我得到这个输出

0.490156
0.490092
0.489984
0.489920


如果有帮助,则节点转储如下所示

b0=LearnableParameter [2,1]   learningRateMultiplier=1.000000  NeedsGradient=true
 -0.00745151564
 0.0358283482
 ####################################################################
b1=LearnableParameter [1,1]   learningRateMultiplier=1.000000  NeedsGradient=true
 -0.0403601788
 ####################################################################
ce=SquareError ( labels , z )
errs=ClassificationError ( labels , z )
features=InputValue [ 2 ]
labels=InputValue [ 1 ]
o1=Plus ( o1.PlusArgs[0] , b0 )
o1.PlusArgs[0]=Times ( W0 , features )
W0=LearnableParameter [2,2]   learningRateMultiplier=1.000000  NeedsGradient=true
 -0.0214280766 0.0442263819
 -0.0401388146 0.0261882655
 ####################################################################
W1=LearnableParameter [1,2]   learningRateMultiplier=1.000000  NeedsGradient=true
 -0.0281925034 0.0214234442
 ####################################################################
z=Sigmoid ( z._ )
z._=Plus ( z._.PlusArgs[0] , b1 )
z._.PlusArgs[0]=Times ( W1 , o1 )

最佳答案

您的隐藏单元中肯定需要一些非线性,例如
o1 = Tanh(W0*features + b0)
通常,通过sgd用两个隐藏的单元学习xor是很棘手的:有许多随机初始化可能导致发散。如果您拥有3个或更多的隐藏单位,将变得更加容易学习。

关于machine-learning - 所有样本的简单CNTK网络输出均相似,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41096954/

10-13 09:06