Esempio n. 1
0
        public Layer_Output(DNN dnn_model)
        {
            foreach (NeuralLink neurallink in dnn_model.neurallinks)
            {
                if (neurallink.Nt == N_Type.Fully_Connected)
                {
                    layerPooling.Add(new float[1]);
                    layerMaxPooling_Index.Add(new int[1]);
                }
                else
                {
                    layerPooling.Add(new float[dnn_model.LFE.MAX_TOKEN_NUM * neurallink.Neural_Out.Number]);
                    layerMaxPooling_Index.Add(new int[neurallink.Neural_Out.Number]);
                }
                layerPoolingSecondary.Add(new float[dnn_model.MaxPoolSentenceNumber * neurallink.Neural_Out.Number]);
                layerMaxPooling_IndexSecondary.Add(new int[neurallink.Neural_Out.Number]);

                layerOutputs.Add(new float[neurallink.Neural_Out.Number]);

                LayerDim.Add(neurallink.Neural_Out.Number);
            }
            Layer_TOP = layerOutputs.Count - 1;
        }
Esempio n. 2
0
        public static void Embedding(string inTgtModel, string inTgtVocab, ModelType inTgtModelType, int inTgtMaxRetainedSeqLength,
                                     string inFilename, string outFilenamePrefix, int dim, FeatureList featureList)
        {
            Dictionary <string, Dictionary <int, float> > tgtDicWord2Vec = new Dictionary <string, Dictionary <int, float> >();
            int    numDic = 0;
            string line   = "";

            StreamWriter tfeafp = new StreamWriter(outFilenamePrefix + ".words");

            DNN tgt_dssm = new DNN(inTgtModel, inTgtModelType, inTgtVocab, inTgtMaxRetainedSeqLength);

            if (inTgtModelType == ModelType.DSSM)
            {
                inTgtMaxRetainedSeqLength = 1;
            }

            using (StreamReader sr = new StreamReader(inFilename))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    if (line != "")
                    {
                        numDic++;
                    }
                }
            }

            StreamReader inFile = new StreamReader(inFilename);
            //string line = "";
            int linecnt = 0;

            tfeafp.WriteLine(numDic + " " + dim);
            while ((line = inFile.ReadLine()) != null)
            {
                linecnt++;
                if (0 == linecnt % 1000000)
                {
                    Console.Write("|");
                }
                else if (0 == linecnt % 100000)
                {
                    Console.Write(".");
                }

                string tgtstr = line;

                List <float> tgtvec = null;
                tgtvec = tgt_dssm.Forward(tgtstr, tgtDicWord2Vec, featureList);

                tfeafp.Write(tgtstr + " ");

                foreach (float x in tgtvec)
                {
                    tfeafp.Write(string.Format("{0:0.######} ", x));
                }
                tfeafp.WriteLine();
            }

            if (tfeafp != null)
            {
                tfeafp.Close();
            }
            Console.WriteLine("total {0} lines processed!", linecnt);
        }