模型服务

使用 Ludwig 训练的模型管道可以通过使用 FastAPI 库生成 Rest API 来提供服务。

让我们来部署刚刚创建的模型。

ludwig serve --model_path ./results/experiment_run/model
docker run -t -i --mount type=bind,source={absolute/path/to/rotten_tomatoes_data},target=/rotten_tomatoes_data ludwigai/ludwig serve --model_path /rotten_tomatoes_data/results/experiment_run/model

现在我们的服务器已启动并运行,你可以通过向该端点发送 POST 请求来获取预测结果。

curl http://0.0.0.0:8000/predict -X POST -F "movie_title=Friends With Money" -F "content_rating=R" -F "genres=Art House & International, Comedy, Drama" -F "runtime=88.0" -F "top_critic=TRUE" -F "review_content=The cast is terrific, the movie isn't."

由于输出特征是二进制类型特征,因此 POST 请求的输出将如下所示:

{
   "review_content_predictions": false,
   "review_content_probabilities_False": 0.76,
   "review_content_probabilities_True": 0.24,
   "review_content_probability": 0.76
}

注意

用户也可以向 /batch_predict 端点发送 POST 请求,一次性对多个样本运行推理。阅读更多关于 Ludwig 服务 的内容,了解更多关于 Ludwig 部署的信息。