Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The implementation between each model can could be entire completely different, we are not going to go into explaining details about each particular model, each model implementation in Python Bridge is a set of expected functions focused in functionality.

Model Class Creation

Every model class must be under the package models, inside the Python Bridge folder, and must extended extend from the class ModelWrapper, which can be imported from models.model_wrapper. An example of a model class with the bare minimum, can be found below:

Code Block
languagepy
themeFadeToGrey
from models.model_wrapper import ModelWrapper


class Test(ModelWrapper):
    
    def __init__(self):
        super().__init__()

    def initialize(self, model_dir, **kwargs):
        pass

    def load(self, model_dir, name, version):
        pass

    def save(self):
        pass

    def clear(self):
        pass

    def feed(self, data):
        pass

    def train(self, **kwargs):
        pass

    def predict(self, data: list):
        pass

    def regress(self, data):
        pass

    def classify(self, data) -> (str, float):
        pass

...

Code Block
languagepy
themeFadeToGrey
def initialize(self, model_dir, **kwargs):

Receive Receives the path to the model type and the configuration for the path.

...

Code Block
languagepy
themeFadeToGrey
def load(self, model_dir, name, version):

Receive Receives the path to the model type, the name of the model and the version of it, in this section the loading of the model is expected.

...

Code Block
languagepy
themeFadeToGrey
def save(self):

Save Saves the current loaded model.

...

Code Block
languagepy
themeFadeToGrey
def clear(self):

Remove Removes the current loaded model, and any training data in memory.

...

Inside the models package there is a __init__.py file which exposes the Model Classes to the server. Any new class needs to be added to this files, and an example can be seen below with the Test class:

Code Block
languagepy
themeFadeToGrey
from .latent_semantic_indexing import LatentSemanticIndexing
from .bert import Bert
from .bert_qa import BertQA
from .sbert import SBert
from .sentiment_analysis_vader import SentimentAnalysisVader
from .sentiment_analysis_text_blob import SentimentAnalysisTextBlob
from .model_wrapper import ModelWrapper
from .tfidf_vectorizer import TfidfVectorizer

from .test import Test


config/config.json

The other reference lies inside in 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 referenced in this file.

Note

"model_names" does reference the actual model data, each name in the model_names refers to a folder which also contains folders representing the versions of the model

...