Example #1
0
 public NCEOutputLayer(NCELayerConfig config) : base(config)
 {
     NegativeSampleSize = config.NegativeSampleSize;
     if (NegativeSampleSize > LayerSize)
     {
         throw new ArgumentException(
                   $"The size of negative sampling('{NegativeSampleSize}') cannot be greater than the hidden layer size('{LayerSize}').");
     }
 }
Example #2
0
        private void SetOutputLayers()
        {
            //Settings for output layer
            var outputLayer     = config.GetValueRequired(OUTPUT_LAYER);
            var items           = outputLayer.Split(':');
            var sLayerType      = items[0];
            var outputLayerType = LayerType.None;

            foreach (
                var type in
                Enum.GetValues(typeof(LayerType))
                .Cast <LayerType>()
                .Where(type => sLayerType.Equals(type.ToString(), StringComparison.InvariantCultureIgnoreCase)))
            {
                outputLayerType = type;
                break;
            }

            switch (outputLayerType)
            {
            case LayerType.Softmax:
                var softmaxLayerConfig = new SoftmaxLayerConfig();
                OutputLayerConfig = softmaxLayerConfig;

                Logger.WriteLine("Initialize configuration for softmax layer.");
                break;

            case LayerType.NCESoftmax:
                var nceLayerConfig = new NCELayerConfig {
                    NegativeSampleSize = int.Parse(items[1])
                };
                OutputLayerConfig = nceLayerConfig;

                Logger.WriteLine(
                    $"Initialize configuration for NCESoftmax layer. Negative sample size = '{nceLayerConfig.NegativeSampleSize}'");
                break;
            }
        }