- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我尝试在 Java 中运行 Mallet,但出现以下错误。
Couldn't open cc.mallet.util.MalletLogger resources/logging.properties file.
Perhaps the 'resources' directories weren't copied into the 'class' directory.
Continuing.
我正在尝试运行 Mallet 网站 ( http://mallet.cs.umass.edu/topics-devel.php ) 中的示例。下面是我的代码。任何帮助表示赞赏。
package scriptAnalyzer;
import cc.mallet.util.*;
import cc.mallet.types.*;
import cc.mallet.pipe.*;
import cc.mallet.pipe.iterator.*;
import cc.mallet.topics.*;
import java.util.*;
import java.util.regex.*;
import java.io.*;
public class Mallet {
public static void main(String[] args) throws Exception {
String filePath = "C:/mallet/ap.txt";
// Begin by importing documents from text to feature sequences
ArrayList<Pipe> pipeList = new ArrayList<Pipe>();
// Pipes: lowercase, tokenize, remove stopwords, map to features
pipeList.add( new CharSequenceLowercase() );
pipeList.add( new CharSequence2TokenSequence(Pattern.compile("\\p{L}[\\p{L}\\p{P}]+\\p{L}")) );
pipeList.add( new TokenSequenceRemoveStopwords(new File("stoplists/en.txt"), "UTF-8", false, false, false) );
pipeList.add( new TokenSequence2FeatureSequence() );
InstanceList instances = new InstanceList (new SerialPipes(pipeList));
Reader fileReader = new InputStreamReader(new FileInputStream(new File(filePath)), "UTF-8");
instances.addThruPipe(new CsvIterator (fileReader, Pattern.compile("^(\\S*)[\\s,]*(\\S*)[\\s,]*(.*)$"),
3, 2, 1)); // data, label, name fields
// Create a model with 100 topics, alpha_t = 0.01, beta_w = 0.01
// Note that the first parameter is passed as the sum over topics, while
// the second is the parameter for a single dimension of the Dirichlet prior.
int numTopics = 5;
ParallelTopicModel model = new ParallelTopicModel(numTopics, 1.0, 0.01);
model.addInstances(instances);
// Use two parallel samplers, which each look at one half the corpus and combine
// statistics after every iteration.
model.setNumThreads(2);
// Run the model for 50 iterations and stop (this is for testing only,
// for real applications, use 1000 to 2000 iterations)
model.setNumIterations(50);
model.estimate();
// Show the words and topics in the first instance
// The data alphabet maps word IDs to strings
Alphabet dataAlphabet = instances.getDataAlphabet();
FeatureSequence tokens = (FeatureSequence) model.getData().get(0).instance.getData();
LabelSequence topics = model.getData().get(0).topicSequence;
Formatter out = new Formatter(new StringBuilder(), Locale.US);
for (int position = 0; position < tokens.getLength(); position++) {
out.format("%s-%d ", dataAlphabet.lookupObject(tokens.getIndexAtPosition(position)), topics.getIndexAtPosition(position));
}
System.out.println(out);
// Estimate the topic distribution of the first instance,
// given the current Gibbs state.
double[] topicDistribution = model.getTopicProbabilities(0);
// Get an array of sorted sets of word ID/count pairs
ArrayList<TreeSet<IDSorter>> topicSortedWords = model.getSortedWords();
// Show top 5 words in topics with proportions for the first document
for (int topic = 0; topic < numTopics; topic++) {
Iterator<IDSorter> iterator = topicSortedWords.get(topic).iterator();
out = new Formatter(new StringBuilder(), Locale.US);
out.format("%d\t%.3f\t", topic, topicDistribution[topic]);
int rank = 0;
while (iterator.hasNext() && rank < 5) {
IDSorter idCountPair = iterator.next();
out.format("%s (%.0f) ", dataAlphabet.lookupObject(idCountPair.getID()), idCountPair.getWeight());
rank++;
}
System.out.println(out);
}
// Create a new instance with high probability of topic 0
StringBuilder topicZeroText = new StringBuilder();
Iterator<IDSorter> iterator = topicSortedWords.get(0).iterator();
int rank = 0;
while (iterator.hasNext() && rank < 5) {
IDSorter idCountPair = iterator.next();
topicZeroText.append(dataAlphabet.lookupObject(idCountPair.getID()) + " ");
rank++;
}
// Create a new instance named "test instance" with empty target and source fields.
InstanceList testing = new InstanceList(instances.getPipe());
testing.addThruPipe(new Instance(topicZeroText.toString(), null, "test instance", null));
TopicInferencer inferencer = model.getInferencer();
double[] testProbabilities = inferencer.getSampledDistribution(testing.get(0), 10, 1, 5);
System.out.println("0\t" + testProbabilities[0]);
}
}
最佳答案
如果系统属性中未指定日志文件,则 Mallet 会查找日志文件。如果您使用 Maven,解决这个问题的最简单方法是将文件放入
src/main/resources/cc/mallet/util/resources/logging.properties
这会自动将标准 Maven 构建过程的一部分复制到:
target/classes/cc/mallet/util/resources/logging.properties
所以你不需要任何特殊的配置。该文件可以为空,但在逻辑上是故意遗漏的,因此您可以配置自己的日志记录。
关于java - 在 Java 中运行 MALLET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20959505/
我想使用 --use-ngrams true 选项运行 mallet,但似乎无法正常工作。 bin\mallet import-file --input ovary.txt --output ovar
这是我第一次使用槌 LDA。基本上,我下载了 mallet-2.0.8 zip 文件和 JDK。我安装了 JDK,将 mallet-2.0.8 提取到目标文件夹。我设置了 MALLET_HOME。这是
我尝试使用 Java 中的 Mallet 实现文档分类器。我已经有一个基本包含特征值的文件。所以我不想运行整个 raw text 处理管道。 目前我的特征文件中的一行看起来像这样(2 个特征,ID 和
我使用的是 Windows 7。我安装了 Mallet,当我进入 Mallet 目录时它运行得很好。但是,我正在使用一些调用它的 python 软件( https://github.com/uwgra
我正在使用 CRF 在 Mallet 上开发一个 NER 系统。 您知道是否可以收集每个预测的特征贡献吗?我需要知道并理解 CRF 模型的精确行为。 有什么建议吗? 谢谢。 干杯,乌克兰 最佳答案 是
我正在寻找有人写/知道MALLET类的详细信息。我知道这是解决ML问题的好工具,现在我尝试实现此处Andrew McCallum, Kedar Bellare and Fernando Pereira
我正在使用 MALLET 进行主题分析,它在几千行和一百左右行的文本文件(“topics.txt”)中输出结果,其中每行由制表符分隔的变量组成,如下所示: Num1 text1 topic1 prop
我已经有一个使用 SimpleTagger 训练过的 CRF 训练模型。 SimpleTagger.main(new String[] { "--tra
老实说,我对 LDA 并不熟悉,但我的一个项目需要使用 MALLET 的主题建模。 我的问题是:给定特定时间戳内的一组文档作为主题模型的训练数据,使用模型(使用推理器)来跟踪主题趋势是否合适,对于文档
我使用 MALLET 进行主题建模。 http://mallet.cs.umass.edu/topics.php 首先,我尝试按照说明导入培训文档集。 bin/mallet import-dir --
MALLET 在训练主题模型时使用 --output-doc-topics 参数生成一个制表符分隔的文件,其中包含每个文档的主题分布。它看起来像这样: doc# filename topi
我用 Mallet 训练了 maxent 文档分类模型,结果是 130MB,这对于我希望运行它的实例来说太大了。我想知道是否有一种方法可以潜在地减少模型的词汇量,从而减少整体模型的大小。有管道可以做到
我正在使用 mallet 库进行主题建模。我的数据集位于 filePath 路径中,并且 csvIterator 似乎可以读取数据,因为 model.getData() 有大约 27000 行,等于我
我使用 Java-Mallet API 通过 LDA 进行主题建模。 API 产生以下结果:主题:关键字1(计数)、关键字2(计数) 例如 主题 0:文件 (12423)、测试 (3123) ...主
我正在尝试运行 Mallet 的主题建模,但出现以下错误: Couldn't open cc.mallet.util.MalletLogger resources/logging.properties
我有一个格式如下的 csv 文件 产品名称,产品评论 现在使用 mallet 我必须训练分类器,以便如果输入包含产品评论的测试数据集,它应该告诉我特定评论属于哪个产品 mallet java api
我正在尝试将 mallet 包合并到我的 java 代码中以完成我的序列标记任务。但是,我不太确定我应该如何仅根据 mallet 网站上的数据导入指南进行操作。谁能帮我解决这个问题? 我的第一个问题是
我正在查看 Mallet 源代码,似乎大多数分类器实现(例如朴素贝叶斯)并没有真正考虑到功能选择,即使 InstanceList 类具有setFeatureSelection 方法。 现在我想对我的数
有人有幸加载过之前训练过的模型吗?翻阅其API ,CRFWriter类是拼图的1/2,但是你到底如何CRFRead(类不存在) 感谢您的帮助。 最佳答案 根据您使用的训练器,您应该能够将对象转换为 C
我正在尝试使用 Mallet 2.0.7 执行 LDA 主题建模。从训练类(class)的输出来看,我可以训练 LDA 模型并获得良好的结果。此外,我可以使用该过程中内置的推理器,并在重新处理我的训练
我是一名优秀的程序员,十分优秀!