Esempio n. 1
0
        public double TrainOne(double [] input, int y)
        {
            if (_rand == null)
            {
                _rand = new RNG(_seed);
            }
            var f = new Flow(true, _rand);



            Timer.build.Start();
            BuildOne(f, input, y, out var probs);
            Timer.build.Stop();


            Timer.forward.Start();
            Forward(f);
            Timer.forward.Stop();


            Timer.backward.Start();
            Backward(f);
            Timer.backward.Stop();


            Timer.update.Start();
            _opt.Update(FixedParam);
            Timer.update.Stop();

            return(Evaluate(y, probs));
        }
Esempio n. 2
0
        public float TrainOne(Sent sent)
        {
            G.Need = true;
            var c = new ArcStandardConfig(sent, false, _rngChoice);

            GetTokenRepr(sent, true);
            var losses = 0f;

            while (!c.IsTerminal())
            {
                var oracle = c.GetOracle(_conf.OraType, out float[] target, out string slabel);
                GetTrans(c, out Tensor op, out Tensor label);
                G.SoftmaxWithCrossEntropy(op, target, out float loss);
                losses += loss;
                if (slabel != null)
                {
                    // in mapping 0 is unk, 1 is root
                    var labelid = _train.DepLabel[slabel] - 1;
                    G.SoftmaxWithCrossEntropy(label, labelid, out loss);
                    losses += loss;
                }

                c.Apply(oracle, slabel);
            }
            G.Backward();
            _opt.Update(FixedParams);
            _opt.Update(VariedParams);
            VariedParams.Clear();
            G.Clear();
            return(losses / sent.Count);
        }
Esempio n. 3
0
 // Update the parameters of the neural network
 // Time it when training
 public void Update()
 {
     Timer.Update.Start();
     _opt.Update(FixedParam);
     Timer.Update.Stop();
 }