Пример #1
0
        public SimpleLayer(LayerConfig config)
        {
            LayerConfig = config;
            if (LayerSize % Vector <float> .Count != 0)
            {
                LayerSize += (Vector <float> .Count - (LayerSize % Vector <float> .Count));
            }

            Cells          = new float[LayerSize];
            Errs           = new float[LayerSize];
            LabelShortList = new List <int>();
        }
Пример #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;
            }

            if (IsCRFTraining == true && outputLayerType != LayerType.Simple)
            {
                throw new ArgumentException($"For RNN-CRF model, its output layer type must be simple layer.");
            }

            switch (outputLayerType)
            {
            case LayerType.Softmax:
                OutputLayerConfig = new SoftmaxLayerConfig();
                Logger.WriteLine("Initialize configuration for softmax layer.");
                break;

            case LayerType.SampledSoftmax:
                var sampledSoftmaxLayerConfig = new SampledSoftmaxLayerConfig {
                    NegativeSampleSize = int.Parse(items[1])
                };
                OutputLayerConfig = sampledSoftmaxLayerConfig;

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

            case LayerType.Simple:
                OutputLayerConfig = new SimpleLayerConfig();
                Logger.WriteLine("Initialize configuration for simple layer.");
                break;

            default:
                Logger.WriteLine($"Invalidated output layer type {sLayerType}");
                throw new ArgumentException($"Invalidated output layer type {sLayerType}");
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
 public LSTMLayer()
 {
     LayerConfig = new LayerConfig();
 }
Пример #5
0
 public NCEOutputLayer()
 {
     LayerConfig = new LayerConfig();
 }
Пример #6
0
 public BPTTLayer()
 {
     LayerConfig = new LayerConfig();
 }
Пример #7
0
 public SimpleLayer()
 {
     LayerConfig    = new LayerConfig();
     LabelShortList = new List <int>();
 }
Пример #8
0
 public SimpleLayer(LayerConfig config)
 {
     LayerConfig = config;
     AllocateMemoryForCells();
     LabelShortList = new List <int>();
 }