Example #1
0
        public static CommonOutputs.TransformOutput LightLda(IHostEnvironment env, LatentDirichletAllocationTransformer.Arguments input)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(input, nameof(input));

            var h    = EntryPointUtils.CheckArgsAndCreateHost(env, "LightLda", input);
            var cols = input.Column.Select(colPair => new LatentDirichletAllocationTransformer.ColumnInfo(colPair, input)).ToArray();
            var est  = new LatentDirichletAllocationEstimator(h, cols);
            var view = est.Fit(input.Data).Transform(input.Data);

            return(new CommonOutputs.TransformOutput()
            {
                Model = new TransformModelImpl(h, view, input.Data),
                OutputData = view
            });
        }
            public override IEstimator <ITransformer> Reconcile(IHostEnvironment env,
                                                                PipelineColumn[] toOutput,
                                                                IReadOnlyDictionary <PipelineColumn, string> inputNames,
                                                                IReadOnlyDictionary <PipelineColumn, string> outputNames,
                                                                IReadOnlyCollection <string> usedNames)
            {
                var infos = new LatentDirichletAllocationTransformer.ColumnInfo[toOutput.Length];
                Action <LatentDirichletAllocationTransformer> onFit = null;

                for (int i = 0; i < toOutput.Length; ++i)
                {
                    var tcol = (ILdaCol)toOutput[i];

                    infos[i] = new LatentDirichletAllocationTransformer.ColumnInfo(outputNames[toOutput[i]],
                                                                                   inputNames[tcol.Input],
                                                                                   tcol.Config.NumTopic,
                                                                                   tcol.Config.AlphaSum,
                                                                                   tcol.Config.Beta,
                                                                                   tcol.Config.MHStep,
                                                                                   tcol.Config.NumIter,
                                                                                   tcol.Config.LikelihoodInterval,
                                                                                   tcol.Config.NumThread,
                                                                                   tcol.Config.NumMaxDocToken,
                                                                                   tcol.Config.NumSummaryTermPerTopic,
                                                                                   tcol.Config.NumBurninIter,
                                                                                   tcol.Config.ResetRandomGenerator);

                    if (tcol.Config.OnFit != null)
                    {
                        int ii = i; // Necessary because if we capture i that will change to toOutput.Length on call.
                        onFit += tt => tcol.Config.OnFit(tt.GetLdaDetails(ii));
                    }
                }

                var est = new LatentDirichletAllocationEstimator(env, infos);

                if (onFit == null)
                {
                    return(est);
                }

                return(est.WithOnFitDelegate(onFit));
            }