Python bindings for alignment do not (yet?) work
jelmervdl opened this issue · 0 comments
jelmervdl commented
[IPKernelApp] ERROR | Exception in message handler:
TypeError: Unregistered type : std::__1::vector<std::__1::vector<std::__1::vector<float, std::__1::allocator<float> >, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float> > > >, std::__1::allocator<std::__1::vector<std::__1::vector<float, std::__1::allocator<float> >, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float> > > > > >
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/jelmer/Workspace/statmt/bergamot-translator/pyenv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3251, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "/var/folders/dc/wd4f060x3ms829gcm4dthzzm0000gn/T/ipykernel_92325/2745258443.py", line 1, in <module>
translate("This sentence should now be in the cache").alignments
TypeError: Unable to convert function return value to a Python type! The signature was
(self: bergamot._bergamot.Response) -> std::__1::vector<std::__1::vector<std::__1::vector<float, std::__1::allocator<float> >, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float> > > >, std::__1::allocator<std::__1::vector<std::__1::vector<float, std::__1::allocator<float> >, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float> > > > > >
Test code:
import bergamot
service = None
config = bergamot.ServiceConfig(numWorkers=4,logLevel='warn', cacheEnabled=True, cacheSize=4000)
service = bergamot.Service(config)
config_path = bergamot.REPOSITORY.modelConfigPath('browsermt', 'en-de-tiny')
model = service.modelFromConfigPath(config_path)
def translate(text, **options):
response_options = bergamot.ResponseOptions(**options)
out = service.translate(model, bergamot.VectorString([text]), response_options)
return out[0]
response = translate("This sentence should now be in the cache") # also fails when `alignment=True` is added
response.alignments