- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过 Java 使用 Mallet,但我无法弄清楚如何根据我训练过的现有主题模型来评估新文档。
我生成模型的初始代码与 Mallett Developers Guide for Topic Modelling 中的代码非常相似。 ,之后我只需将模型保存为 Java 对象。在稍后的过程中,我从文件中重新加载该 Java 对象,通过 .addInstances()
添加新实例,然后仅根据原始训练集中找到的主题评估这些新实例。
This stats.SE thread提供了一些高级建议,但我不知道如何将它们应用到 Mallet 框架中。
非常感谢任何帮助。
最佳答案
推理实际上也列在 example link 中问题中提供(最后几行)。
对于对保存/加载训练模型的整个代码感兴趣的人,然后使用它来推断新文档的模型分布 - 这里有一些片段:
model.estimate()
之后完成后,您就拥有了实际训练过的模型,因此您可以使用标准 Java ObjectOutputStream
对其进行序列化(因为 ParallelTopicModel
实现了 Serializable
):
try {
FileOutputStream outFile = new FileOutputStream("model.ser");
ObjectOutputStream oos = new ObjectOutputStream(outFile);
oos.writeObject(model);
oos.close();
} catch (FileNotFoundException ex) {
// handle this error
} catch (IOException ex) {
// handle this error
}
但请注意,当您推断时,您还需要通过同一管道传递新句子(如 Instance
)以便对其进行预处理(tokenzie 等),因此,您还需要保存管道列表(因为我们使用SerialPipe
何时可以创建实例然后序列化它):
// initialize the pipelist (using in model training)
SerialPipes pipes = new SerialPipes(pipeList);
try {
FileOutputStream outFile = new FileOutputStream("pipes.ser");
ObjectOutputStream oos = new ObjectOutputStream(outFile);
oos.writeObject(pipes);
oos.close();
} catch (FileNotFoundException ex) {
// handle error
} catch (IOException ex) {
// handle error
}
为了加载模型/管道并将其用于推理,我们需要反序列化:
private static void InferByModel(String sentence) {
// define model and pipeline
ParallelTopicModel model = null;
SerialPipes pipes = null;
// load the model
try {
FileInputStream outFile = new FileInputStream("model.ser");
ObjectInputStream oos = new ObjectInputStream(outFile);
model = (ParallelTopicModel) oos.readObject();
} catch (IOException ex) {
System.out.println("Could not read model from file: " + ex);
} catch (ClassNotFoundException ex) {
System.out.println("Could not load the model: " + ex);
}
// load the pipeline
try {
FileInputStream outFile = new FileInputStream("pipes.ser");
ObjectInputStream oos = new ObjectInputStream(outFile);
pipes = (SerialPipes) oos.readObject();
} catch (IOException ex) {
System.out.println("Could not read pipes from file: " + ex);
} catch (ClassNotFoundException ex) {
System.out.println("Could not load the pipes: " + ex);
}
// if both are properly loaded
if (model != null && pipes != null){
// Create a new instance named "test instance" with empty target
// and source fields note we are using the pipes list here
InstanceList testing = new InstanceList(pipes);
testing.addThruPipe(
new Instance(sentence, null, "test instance", null));
// here we get an inferencer from our loaded model and use it
TopicInferencer inferencer = model.getInferencer();
double[] testProbabilities = inferencer
.getSampledDistribution(testing.get(0), 10, 1, 5);
System.out.println("0\t" + testProbabilities[0]);
}
}
由于某种原因,我没有得到与原始模型完全相同的加载模型的推论 - 但这是另一个问题的问题(如果有人知道,我很高兴听到)
关于java - 在 Java 中使用 Mallet 在 LDA 中折叠(估计新文档的主题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14141195/
我想计算或至少估计放置在相机/kinect 前面的物体的体积。知道我应该从哪里开始吗?你推荐 OpenCV 吗?您是否推荐任何其他技术,例如声纳/激光? 最佳答案 一直在用 OpenCV 2.3 编写
我想知道 MySQL 对表中总行数的 TABLE_ROWS 估计值是否有限制或保证误差范围? 最佳答案 如果它与 SHOW TABLE STATUS 发出的数字类似,则至少会偏差 +/- 40%,有时
我们都曾 mock 过“还剩 X 分钟”的对话框,它似乎过于简单,但我们如何改进它呢? 实际上,输入是截至当前时间的一组下载速度,我们需要使用它来估计完成时间,也许带有确定性指示,例如使用一些 Y%
我们都曾 mock 过“还剩 X 分钟”的对话框,它似乎过于简单,但我们如何改进它呢? 实际上,输入是截至当前时间的一组下载速度,我们需要使用它来估计完成时间,也许带有确定性指示,例如使用一些 Y%
我的理解是 glmnet 采用矩阵,其中每一列都是一个解释变量。 我有一个包含约 10 个解释变量的数据框(其中一些是因子) 我怎样才能使用诸如 y~(x1*x2*x3)+(x4*x5)+x6 之类的
有没有办法估计运行 R 的时间?命令而不实际运行它或仅部分运行命令? 我知道 system.time()存在但需要运行整个命令然后它给出了花费的时间。 最佳答案 还有http://www.ats.uc
在尝试使用 libGD 在 PHP 中调整图像大小之前,我想检查是否有足够的内存来执行操作,因为“内存不足”会完全杀死 PHP 进程并且无法被捕获。 我的想法是,原始图像和新图像中的每个像素 (RGB
我有一些 VHDL 文件,我可以在 Debian 上用 ghdl 编译它们。一些人已将相同的文件改编为 ASIC 实现。算法有一个“大面积”实现和一个“紧凑”实现。我想编写更多实现,但要评估它们,我需
我在 Amazon EC2 上使用 RStudio 0.97.320 (R 2.15.3)。我的数据框有 20 万行和 12 列。 我正在尝试使用大约 1500 个参数来拟合逻辑回归。 R 使用 7%
我目前正在估算一个新项目。假设只有一名开发人员在处理它,我的高水平估计是 25 周。 实际上会有两个开发人员并行工作。减少估计的什么因素是合理的? (我意识到不会是0.5) 最佳答案 根据原始开发人员
我试图更好地理解创建 Postgres 索引所涉及的权衡。作为其中的一部分,我很想了解通常使用多少空间索引。我已通读 the docs ,但找不到这方面的任何信息。我一直在做自己的小实验来创建表和索引
我对 Azure 平台相当陌生,需要一些有关 Azure 搜索服务成本估算的帮助。每个月我们都会有大约 500GB 的文件被放入 Azure Blob 存储中。我们希望仅根据文件名使用 Azure 搜
我正在尝试最大化横截面面板数据中的数据点数量。我的矩阵结构如下,y 轴为年份,x 轴为国家/地区: A B C D 2000 NA 50 NA
如果我有两个时间序列,例如: t f1 #[1] 0.25 #> f2 #[1] 0.25 f phase_difference #[1] 0.5 这意味着时间序列相移 pi/2,因为它们应该根据
我对 Azure 平台相当陌生,需要一些有关 Azure 搜索服务成本估算的帮助。每个月我们都会有大约 500GB 的文件被放入 Azure Blob 存储中。我们希望仅根据文件名使用 Azure 搜
我使用了以下 R 包:mice、mitools 和 pROC。 基本设计:3 个预测变量度量,在 n~1,000 的数据缺失率在 5% 到 70% 之间。 1 个二进制目标结果变量。 分析目标:确定
如何使用 lsmeans 来估计两个成对对比的差异?例如——想象一个连续的 dv 和两个因子预测变量 library(lsmeans) library(tidyverse) dat % fac
我制作了一个使用 BigDecimal 的科学计算器。它有一个特别消耗资源的功能:阶乘。现在,输入任何数字都会启动计算。根据运行此代码的设备,答案会在不同的时间显示。输入像 50000 这样的巨大值!
我已经发出了 sympy 命令来求解某个方程或另一个方程。现在已经好几天了,我不知道什么时候能完成。 我可以使用 sympy 来记录调用 .solvers.solve 的进度吗?如果不是,我如何估计
最近我得到了一些 error C6020: Constant register limit exceeded at variable; more than 1024 registers needed
我是一名优秀的程序员,十分优秀!