📄 gis.java~1~
字号:
///////////////////////////////////////////////////////////////////////////////// Copyright (C) 2001 Jason Baldridge and Gann Bierner//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//////////////////////////////////////////////////////////////////////////////package opennlp.maxent;/** * A Factory class which uses instances of GISTrainer to create and train * GISModels. * 一个工厂类,它调用GISTrainer的实例,来产生和训练GISModel * @author Jason Baldridge * @version $Revision: 1.4 $, $Date: 2003/12/13 16:41:29 $ */public class GIS { /** * Set this to false if you don't want messages about the progress of * model training displayed. Alternately, you can use the overloaded * version of trainModel() to conditionally enable progress messages. * 决定是否显示训练过程中的信息.另外,可以调用重载的trainModel()来根据条件 * 决定过程信息的显示与否 */ public static boolean PRINT_MESSAGES = true; /** * Defines whether the created trainer will use smoothing while training * the model. This can improve model accuracy, though training will * potentially take longer and use more memory. Model size will also be * larger. Set true if smoothing is desired, false if not. * 训练器是否使用平滑? */ public static boolean SMOOTHING = false; // If we are using smoothing, this is used as the "number" of // times we want the trainer to imagine that it saw a feature that it // actually didn't see. Defaulted to 0.1. // 使用平滑时的平滑量设置.对没有出现的特征,训练器认为它出现的次数,默认为0.1 public static double SMOOTHING_OBSERVATION = 0.1; /** * Train a model using the GIS algorithm, assuming 100 iterations and no cutoff. * 根据传入的EventStream,调用GIS算法,迭代100次,生成模型 * @param eventStream The EventStream holding the data on which this model * will be trained. * @return The newly trained model, which can be used immediately or saved * to disk using an opennlp.maxent.io.GISModelWriter object. */ public static GISModel trainModel(EventStream eventStream) { return trainModel(eventStream, 100, 0, PRINT_MESSAGES); } /** * Train a model using the GIS algorithm. * 参数eventStream:由数据文件转化得到的EventStream * @param eventStream The EventStream holding the data on which this model * will be trained. * 迭代次数 * @param iterations The number of GIS iterations to perform. * 特征用于训练的最少出现次数 * @param cutoff The number of times a feature must be seen in order * to be relevant for training. * 返回值:训练得到的模型,可以被GISModelWriter直接调用或者保存到文件中 * @return The newly trained model, which can be used immediately or saved * to disk using an opennlp.maxent.io.GISModelWriter object. */ public static GISModel trainModel(EventStream eventStream, int iterations, int cutoff) { return trainModel(eventStream, iterations, cutoff, PRINT_MESSAGES); } /** * Train a model using the GIS algorithm. * * @param eventStream The EventStream holding the data on which this model * will be trained. * @param iterations The number of GIS iterations to perform. * @param cutoff The number of times a feature must be seen in order * to be relevant for training. * @param printMessagesWhileTraining write training status messages * to STDOUT. * @return The newly trained model, which can be used immediately or saved * to disk using an opennlp.maxent.io.GISModelWriter object. */ public static GISModel trainModel(EventStream eventStream, int iterations, int cutoff, boolean printMessagesWhileTraining) { GISTrainer trainer = new GISTrainer(printMessagesWhileTraining); trainer.setSmoothing(SMOOTHING); trainer.setSmoothingObservation(SMOOTHING_OBSERVATION); return trainer.trainModel(eventStream, iterations, cutoff); } // 新版本中增加的方法,可以由DataIndexer进行训练直接得到最大熵模型 public static GISModel trainModel(int iterations, DataIndexer indexer, boolean printMessagesWhileTraining) { GISTrainer trainer = new GISTrainer(printMessagesWhileTraining); trainer.setSmoothing(SMOOTHING); trainer.setSmoothingObservation(SMOOTHING_OBSERVATION); return trainer.trainModel(iterations, indexer); } public static GISModel trainModel(int iterations, DataIndexer indexer) { return trainModel(iterations,indexer,true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -