Exemplo n.º 1
0
        private void GetOrCreateModel()
        {
            Directory.CreateDirectory(ModelDirectory);

            // create the inputs
            Axis axis     = new Axis("inputAxis");
            var  features = Variable.InputVariable(new[] { Vocab.CharCount }, DataType.Float, "features", new List <Axis> {
                axis, Axis.DefaultBatchAxis()
            });
            var labels = Variable.InputVariable(new[] { Vocab.CharCount }, DataType.Float, "labels", new List <Axis> {
                axis, Axis.DefaultBatchAxis()
            });

            if (TryGetModel(out string filename))
            {
                // load the previous model and use it's features
                // the labels should be identical as before
                Model  = Function.Load(filename, Device);
                Inputs = new IOPair <Variable>(Model.Arguments[0], labels);
                Console.WriteLine($"Loaded {Path.GetFileName(filename)}");
            }
            else
            {
                // create a new model from the features
                Model = features;
                for (int i = 0; i < Layers; i++)
                {
                    Model = Stabilizer.Build(Model, Device);
                    Model = LSTM.Build(Model, HiddenDimensions, Device);
                }

                Model  = Dense.Build(Model, Vocab.CharCount, Device);
                Inputs = new IOPair <Variable>(features, labels);
            }
        }
Exemplo n.º 2
0
 private Func <Variable, Function> CreateModel(int numOutputDimension, int numLstmLayer, int numHiddenDimension)
 {
     return((input) =>
     {
         Function model = input;
         for (int i = 0; i < numLstmLayer; i++)
         {
             model = Stabilizer.Build(model, device);
             model = LSTM.Build(model, numHiddenDimension, device);
         }
         model = Dense.Build(model, numOutputDimension, device);
         return model;
     });
 }