Esempio n. 1
0
	public void train() throws Exception {
		/*
		 * Read the training dataset into an object which implements DataIter
		 * interface(trainData). Each of the training instance is encapsulated
		 * in the object which provides DataSequence interface. The DataIter
		 * interface returns object of DataSequence (training instance) in
		 * next() routine.
		 */
		DataIterImpl trainData = new DataIterImpl();

		/*
		 * Once you have loaded the training dataset, you need to allocate
		 * objects for the model to be learned. allocmodel() method does that
		 * allocation.
		 */
		allocModel();

		/*
		 * You may need to train some of the feature types class. This training
		 * is needed for features which need to learn from the training data for
		 * instance dictionary features build generated from the training set.
		 */
		featureGen.train(trainData);

		/*
		 * Call train routine of the CRF model to train the model using the
		 * train data. This routine returns the learned weight for the features.
		 */
		double featureWts[] = crfModel.train(trainData);

		/*
		 * You can store the learned model for later use into disk. For this you
		 * will have to store features as well as their corresponding weights.
		 */
		crfModel.write(baseDir + "/learntModels/" + outDir + "/crf");
		featureGen.write(baseDir + "/learntModels/" + outDir + "/features");

	}