我正在尝试DynamicLMClassifier.createNGramProcess(categories,nGram)
在大于 20GB 的大数据集上训练 a。我目前正在将整个培训文件作为字符串提供给培训方法,出于显而易见的原因,我得到了一个java.lang.OutOfMemoryError: Java heap space
尽管可能增加 JVM 堆大小以支持此类训练,但我有兴趣找到一种增量方法。
训练代码如下所示:
char[] csBuf = new char[numChars];
for (int i = 0; i < categories.length; ++i) {
String category = categories[i];
File trainingFile = new File(new File(dataDir,category),
category + ".txt");
FileInputStream fileIn
= new FileInputStream(trainingFile);
InputStreamReader reader
= new InputStreamReader(fileIn,Strings.UTF8);
reader.read(csBuf);
String text = new String(csBuf,0,numChars);
Classification c = new Classification(category);
Classified<CharSequence> classified
= new Classified<CharSequence>(text,c);
classifier.handle(classified);
reader.close();
}
理想的解决方案是在训练集的 N 个子集的循环中提供分类器.handle()。从理论上讲,我认为这应该是可能的,因为模型只需要记住具有各自计数的 ngram 元组来计算 MLE。