public static void main (String[] args) throws IOException { InstanceList training = InstanceList.load (new File(args[0])); int numTopics = args.length > 1 ? Integer.parseInt(args[1]) : 200; InstanceList testing = args.length > 2 ? InstanceList.load (new File(args[2])) : null; DMRTopicModel lda = new DMRTopicModel (numTopics); lda.setOptimizeInterval(100); lda.setTopicDisplay(100, 10); lda.addInstances(training); lda.estimate(); lda.writeParameters(new File("dmr.parameters")); lda.printState(new File("dmr.state.gz")); } }
public void printTopWords (PrintStream out, int numWords, boolean usingNewLines) { if (dmrParameters != null) { setAlphas(); } super.printTopWords(out, numWords, usingNewLines); }
printTopWords (System.out, wordsPerTopic, false); this.printState(new File(stateFilename + '.' + iterationsSoFar + ".gz")); learnParameters(); setAlphas(data.get(doc).instance); sampleTopicsForOneDoc (tokenSequence, topicSequence, false, false); if (printLogLikelihood) System.out.println (modelLogLikelihood());
printTopWords (System.out, wordsPerTopic, false); this.printState(new File(stateFilename + '.' + iterationsSoFar + ".gz")); learnParameters(); setAlphas(data.get(doc).instance); sampleTopicsForOneDoc (tokenSequence, topicSequence, false, false); if (printLogLikelihood) System.out.println (modelLogLikelihood());
public static void main (String[] args) throws IOException { InstanceList training = InstanceList.load (new File(args[0])); int numTopics = args.length > 1 ? Integer.parseInt(args[1]) : 200; InstanceList testing = args.length > 2 ? InstanceList.load (new File(args[2])) : null; DMRTopicModel lda = new DMRTopicModel (numTopics); lda.setOptimizeInterval(100); lda.setTopicDisplay(100, 10); lda.addInstances(training); lda.estimate(); lda.writeParameters(new File("dmr.parameters")); lda.printState(new File("dmr.state.gz")); } }
printTopWords (System.out, wordsPerTopic, false); this.printState(new File(stateFilename + '.' + iterationsSoFar + ".gz")); learnParameters(); setAlphas(data.get(doc).instance); sampleTopicsForOneDoc (tokenSequence, topicSequence, false, false); if (printLogLikelihood) System.out.println (modelLogLikelihood());
public void printTopWords (PrintStream out, int numWords, boolean usingNewLines) { if (dmrParameters != null) { setAlphas(); } super.printTopWords(out, numWords, usingNewLines); }
public static void main (String[] args) throws IOException { InstanceList training = InstanceList.load (new File(args[0])); int numTopics = args.length > 1 ? Integer.parseInt(args[1]) : 200; InstanceList testing = args.length > 2 ? InstanceList.load (new File(args[2])) : null; DMRTopicModel lda = new DMRTopicModel (numTopics); lda.setOptimizeInterval(100); lda.setTopicDisplay(100, 10); lda.addInstances(training); lda.estimate(); lda.writeParameters(new File("dmr.parameters")); lda.printState(new File("dmr.state.gz")); } }
public void printTopWords (PrintStream out, int numWords, boolean usingNewLines) { if (dmrParameters != null) { setAlphas(); } super.printTopWords(out, numWords, usingNewLines); }
/** * Set alpha based on features in an instance */ public void setAlphas(Instance instance) { // we can't use the standard score functions from MaxEnt, // since our features are currently in the Target. FeatureVector features = (FeatureVector) instance.getTarget(); if (features == null) { setAlphas(); return; } double[] parameters = dmrParameters.getParameters(); alphaSum = 0.0; smoothingOnlyMass = 0.0; for (int topic = 0; topic < numTopics; topic++) { alpha[topic] = parameters[topic*numFeatures + defaultFeatureIndex] + MatrixOps.rowDotProduct (parameters, numFeatures, topic, features, defaultFeatureIndex, null); alpha[topic] = Math.exp(alpha[topic]); alphaSum += alpha[topic]; smoothingOnlyMass += alpha[topic] * beta / (tokensPerTopic[topic] + betaSum); cachedCoefficients[topic] = alpha[topic] / (tokensPerTopic[topic] + betaSum); } }
/** * Set alpha based on features in an instance */ public void setAlphas(Instance instance) { // we can't use the standard score functions from MaxEnt, // since our features are currently in the Target. FeatureVector features = (FeatureVector) instance.getTarget(); if (features == null) { setAlphas(); return; } double[] parameters = dmrParameters.getParameters(); alphaSum = 0.0; smoothingOnlyMass = 0.0; for (int topic = 0; topic < numTopics; topic++) { alpha[topic] = parameters[topic*numFeatures + defaultFeatureIndex] + MatrixOps.rowDotProduct (parameters, numFeatures, topic, features, defaultFeatureIndex, null); alpha[topic] = Math.exp(alpha[topic]); alphaSum += alpha[topic]; smoothingOnlyMass += alpha[topic] * beta / (tokensPerTopic[topic] + betaSum); cachedCoefficients[topic] = alpha[topic] / (tokensPerTopic[topic] + betaSum); } }
/** * Set alpha based on features in an instance */ public void setAlphas(Instance instance) { // we can't use the standard score functions from MaxEnt, // since our features are currently in the Target. FeatureVector features = (FeatureVector) instance.getTarget(); if (features == null) { setAlphas(); return; } double[] parameters = dmrParameters.getParameters(); alphaSum = 0.0; smoothingOnlyMass = 0.0; for (int topic = 0; topic < numTopics; topic++) { alpha[topic] = parameters[topic*numFeatures + defaultFeatureIndex] + MatrixOps.rowDotProduct (parameters, numFeatures, topic, features, defaultFeatureIndex, null); alpha[topic] = Math.exp(alpha[topic]); alphaSum += alpha[topic]; smoothingOnlyMass += alpha[topic] * beta / (tokensPerTopic[topic] + betaSum); cachedCoefficients[topic] = alpha[topic] / (tokensPerTopic[topic] + betaSum); } }
setAlphas(instance);