public void CopyModel(LdaSingleBox trainer, int wordId) { int length = NumTopic; LdaInterface.GetWordTopic(trainer._engine, wordId, _topics, _probabilities, ref length); LdaInterface.SetWordTopic(_engine, wordId, _topics, _probabilities, length); }
public LdaState(IExceptionContext ectx, ColInfoEx ex, int numVocab) : this() { Contracts.AssertValue(ectx); ectx.AssertValue(ex, "ex"); ectx.Assert(numVocab >= 0); InfoEx = ex; _numVocab = numVocab; _ldaTrainer = new LdaSingleBox( InfoEx.NumTopic, numVocab, /* Need to set number of vocabulary here */ InfoEx.AlphaSum, InfoEx.Beta, InfoEx.NumIter, InfoEx.LikelihoodInterval, InfoEx.NumThread, InfoEx.MHStep, InfoEx.NumSummaryTermPerTopic, false, InfoEx.NumMaxDocToken); }
public LdaState(IExceptionContext ectx, ModelLoadContext ctx) : this() { ectx.AssertValue(ctx); // *** Binary format *** // <ColInfoEx> // int: vocabnum // long: memblocksize // long: aliasMemBlockSize // (serializing term by term, for one term) // int: term_id, int: topic_num, KeyValuePair<int, int>[]: termTopicVector InfoEx = new ColInfoEx(ectx, ctx); _numVocab = ctx.Reader.ReadInt32(); ectx.CheckDecode(_numVocab > 0); long memBlockSize = ctx.Reader.ReadInt64(); ectx.CheckDecode(memBlockSize > 0); long aliasMemBlockSize = ctx.Reader.ReadInt64(); ectx.CheckDecode(aliasMemBlockSize > 0); _ldaTrainer = new LdaSingleBox( InfoEx.NumTopic, _numVocab, /* Need to set number of vocabulary here */ InfoEx.AlphaSum, InfoEx.Beta, InfoEx.NumIter, InfoEx.LikelihoodInterval, InfoEx.NumThread, InfoEx.MHStep, InfoEx.NumSummaryTermPerTopic, false, InfoEx.NumMaxDocToken); _ldaTrainer.AllocateModelMemory(_numVocab, InfoEx.NumTopic, memBlockSize, aliasMemBlockSize); for (int i = 0; i < _numVocab; i++) { int termID = ctx.Reader.ReadInt32(); ectx.CheckDecode(termID >= 0); int termTopicNum = ctx.Reader.ReadInt32(); ectx.CheckDecode(termTopicNum >= 0); int[] topicId = new int[termTopicNum]; int[] topicProb = new int[termTopicNum]; for (int j = 0; j < termTopicNum; j++) { topicId[j] = ctx.Reader.ReadInt32(); topicProb[j] = ctx.Reader.ReadInt32(); } //set the topic into _ldaTrainer inner topic table _ldaTrainer.SetModel(termID, topicId, topicProb, termTopicNum); } //do the preparation if (!_predictionPreparationDone) { _ldaTrainer.InitializeBeforeTest(); _predictionPreparationDone = true; } }