How to use the farm.infer.Inferencer.load function in farm

To help you get started, we’ve selected a few farm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepset-ai / FARM / test / test_doc_regression.py View on Github external
evaluate_every=evaluate_every,
        device=device
    )

    model = trainer.train(model)

    save_dir = "testsave/doc_regr"
    model.save(save_dir)
    processor.save(save_dir)

    basic_texts = [
        {"text": "The dress is just fabulous and it totally fits my size. The fabric is of great quality and the seams are really well hidden. I am super happy with this purchase and I am looking forward to trying some more from the same brand."},
        {"text": "it just did not fit right. The top is very thin showing everything."},
    ]

    model = Inferencer.load(save_dir)
    result = model.inference_from_dicts(dicts=basic_texts)
    assert isinstance(result[0]["predictions"][0]["pred"], np.float32)
github deepset-ai / FARM / farm / inference_rest_api.py View on Github external
level="INFO",
    datefmt="%Y-%m-%d %H:%M:%S",
)

MODELS_DIRS = ["saved_models", "base_models"]

model_paths = []
for model_dir in MODELS_DIRS:
    path = Path(model_dir)
    if path.is_dir():
        models = [f for f in path.iterdir() if f.is_dir()]
        model_paths.extend(models)

INFERENCERS = {}
for idx, model_dir in enumerate(model_paths):
    INFERENCERS[idx + 1] = Inferencer.load(str(model_dir))

app = Flask(__name__)
CORS(app)
api = Api(app, debug=True, validate=True, version="1.0", title="FARM NLP APIs")
app.config["JSON_SORT_KEYS"] = True
app.config["RESTPLUS_VALIDATE"] = True


@api.route("/models")
class ModelListEndpoint(Resource):
    def get(self):
        resp = []

        for idx, model in INFERENCERS.items():
            _res = {
                "id": idx,