from typing import List import os import fasttext.util import re def preprocess(text): text = re.sub(r"&", "and", text) text = re.sub(r"[^\w\s]", " ", text) text = re.sub("\n", " ", text) text = re.sub(" +", " ", text) return text.strip().lower() class PreTrainedPipeline(): def __init__(self, path=""): """ Initialize model """ self.model = fasttext.load_model(os.path.join(path, 'model.bin')) def __call__(self, inputs: str): """ Args: inputs (:obj:`str`): a string to get the features of. Return: A :obj:`list` of floats: The features computed by the model. """ inputs = preprocess(inputs) return self.model.predict(inputs)