在客户端JavaScript中使用/生成训练有素的机器学习模型? [英] Use/productionize trained machine learning model in client-side javascript?

查看:215
本文介绍了在客户端JavaScript中使用/生成训练有素的机器学习模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是一个稍微疯狂的想法,我一直在踢。我正在考虑为某些网页内容(的一个特殊子集)构建分类器,然后以铬扩展的形式将其提供给用户。 (所以:用户转到网页,点击铬扩展上的按钮,扩展应用预先训练的模型来生成预测,并将结果呈现给用户。)

但我便宜,我不想运行服务器接收来自chrome扩展的数据,生成预测并将其发回给用户。它发生在我身上:为什么不找一些方法来序列化训练好的模型或什么,并在客户端完成这一切。

所以如果我最终拟合一个非常简单的模型,如逻辑回归或其他,那么它很容易转移到客户端。最终,经过训练的逻辑回归仅仅可以表示为一种将特征映射到预测的普通数学函数,就像一行代码。我想对于一些更好的模型也是如此(线性SVM)。在这种情况下,chrome扩展可以完成所有的数据清理工作,然后生成预测只是计算点积的一个问题。但是,如果我最终使用随机森林或其他东西,情况就不一样了。



不幸的是,似乎并没有PMML库或类似的东西对于JavaScript。

所以,我转向互联网的智慧。有没有其他方法可以在客户端JavaScript上使用生成ML模型?或者这些选项真的只是(1)运行服务器,(2)为JS编写PMML库,(3)没有第三种选择?



谢谢!

解决方案

数据格式已经存在?



如果是这样,那么:


  1. 将PMML转换为Java源代码。这很容易使用 JPMML 库。

  2. 将Java源代码转换为JavaScript源代码。使用 Google Web Toolkit 更容易。

因此,您将拥有一个自包含的JavaScript模型对象,可以公开模型模式查询和评分API,类似于 JPMML-Evaluator 库。


So this is a slightly insane idea that I've been kicking around. I'm thinking of building a classifier for (a specialized subset of) some web content, and then supplying it to users in the form of a chrome extension. (So: user goes to web page, clicks button on chrome extension, extension applies pre-trained model to generate prediction, presents result to user.)

But I'm cheap, and I don't want to run a server to receive data from the chrome extension, generate a prediction, and send it back to the user. It occurs to me: why not just find some way to serialize the trained model or something, and do it all on the client side.

So if I end up fitting a very simple model, like a logistic regression or something, then it would be easy to transfer to the client-side. Ultimately, a trained logistic regression is just expressible as an ordinary mathematical function mapping features to predictions, it's like one line of code. And I guess that's true of some fancier models as well (linear SVM). Under those circumstances, the chrome extension could do all the data cleaning and such, and then generating predictions is just a matter of calculating a dot product. But the same isn't true if I end up using, say, random forests or something.

Tragically, there doesn't appear to be a PMML library or anything like that for javascript.

So, I turn to the wisdom of the internet. Are there any other methods for productionizing ML models that might be usable on client-side javascript? Or are the options really just (1) run a server, (2) write a PMML library for JS, (3) there is no third option?

Thanks!

解决方案

Do you have your models available in PMML data format already?

If so, then:

  1. Translate PMML to Java source code. This is easy using JPMML libraries.
  2. Translate Java source code to JavaScript source code. This is even easier using Google Web Toolkit.

As a result, you would have a self-contained JavaScript model object that exposes model schema query and scoring API similar to the JPMML-Evaluator library.

这篇关于在客户端JavaScript中使用/生成训练有素的机器学习模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆