The implementation between each model can be entire different, we are not going to go into details about each particular model, each model implementation in Python Bridge is a set of expected functions focus focused in functionality
...
Every class extending from ModelWrapper must implements implement the following methods, but if by any reason you don't need one of them, you can leave it as pass
...
Receives a list of string tokens tokens to be added to the training data
...
Code Block | ||||
---|---|---|---|---|
| ||||
def train(self, **kwargs): |
Trains the model with the documents fed documents, the model can be either kept in memory or saved
...
Retrieves a vector or an array of vectors , from processing the data with the loaded modemodel, which is return returned inside a JSON { 'vector': [ ] }, the value of the vector key must be always be an array.
Code Block | ||||
---|---|---|---|---|
| ||||
def regress(self, data): |
...
Retrieves a label or multiple labels , using the loaded model , from the data. We recommend returning the label along with its confidence.
...
Now that the class is ready, we need to make it available to be useused, for this we need to add a reference in 2 files
...
The other reference lies inside the config.json file in the config folder, in this file there is a section called "model_types", which refers to the classes available. As in the __init__.py file, any new class needs to be reference in this filesfile
Note |
---|
"model_names" does reference to the actual model data, each name in the model_names , refers to a folder , which also contains folders representing the version versions of the model |
Code Block | ||||
---|---|---|---|---|
| ||||
"model_types": { "LatentSemanticIndexing" : { "model_names": ["lsi"] }, "Bert": { "model_names": ["bert-base-uncased"], "default_model": "bert-base-uncased" }, "SentimentAnalysisVader": { "model_names": ["vader"] }, "SentimentAnalysisTextBlob": { "model_names": ["textBlob"] }, "Test"" { "model_names": ["test"] } } |
...
Every model to be used by its implementation needs to be stored in a specific path, compoused composed by the Name of model type, a representative name of the model and a folder representing the version (the version doesn't have to be a number, it can be a name). As it can be seen below, the model for the Test Class was added following this structure
...