受Python Vetiver model - use alternative prediction method的启发,我希望在vetiver和pins的帮助下部署https://fasttext.cc/模型。不幸的是,链接中的解决方案对我不起作用。在编写了我的FastTextHandler类之后,我甚至无法执行以下行:
from vetiver.handlers.base import VetiverHandler
此错误是否是由于版本更新0.1.5 -> 0.1.6而产生的?
因此,我从VetiverHandler更改为BaseHandler,然后得到以下代码:
from vetiver.handlers.base import BaseHandler
class FastTextHandler(BaseHandler):
def __init__(model, ptype_data):
super().__init__(model, ptype_data)
def handler_predict(self, input_data, check_ptype):
"""
Define how to make predictions from your model
"""
prediction = self.model.predict(input_data)
return prediction
custom_model = FastTextHandler(model,"hello")但这会引发以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_3423/1130715213.py in <module>
11 return prediction
12
---> 13 custom_model = FastTextHandler(model, "hello")
TypeError: __init__() takes 2 positional arguments but 3 were give我不明白为什么模型对象被解释为两个位置参数。这是由于fastText结构造成的吗?如何将其与vetiver结合使用?
非常感谢您提前!
最好,M。
发布于 2022-08-10 20:44:21
您的__init__函数缺少一个self参数。
class FastTextHandler(BaseHandler):
def __init__(self, model, ptype_data):
super().__init__(model, ptype_data)等。
查看这段代码,您将字符串"hello“传入ptype_data参数。为了避免以后出现这样的问题,请使用custom_model = FastTextHandler(model, data) (或将数据保留为None),然后在创建可部署的模型对象(如VetiverModel(custom_model, "hello") )时添加模型名称"hello“。
https://stackoverflow.com/questions/73306557
复制相似问题