ml-classify-text-js
ml-classify-text-js copied to clipboard
Add ability to define custom getter/setter methods for model data
Add support for for passing custom methods to Classifier
and Model
for defining custom getter/setter methods that allows us to bypass the data
object literal that is currently stored directly as a property in Model
instances.
For example:
const { createClient } = require('redis')
const client = createClient()
const classifier = new Classifier({
getData: async (label) => {
return await client.get(label || '*')
},
setData: async (label, data) => {
return await client.set(label, data)
}
})
There will be default getData
and setData
methods which work like in the current version (but still with some performance improvements like being asynchronous by default and where we optimize the way the data
object is stored in memory).
From there we can update the train
and predict
methods in Classifier
to call those, instead of the current behaviour of directly accessing this._model.data
.
When using the library in this way, the data that still remains in Model
(and is accessible via the serialize
method) simply serves as general model meta data, and one would need to use the same custom data store every time the model is used later on.
It should also be noted this needs to wait until the upcoming version where all methods have been rewritten to be asynchronous by default is has been released.