Currently, the easiest way to use the library is from the Docker images. For example if you followed the README to generate “ende_ctranslate2” you could try:
$ docker run -it --rm -v $PWD:/data --entrypoint python opennmt/ctranslate2:latest-ubuntu18
Python 2.7.15+ (default, Oct 7 2019, 17:39:04)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctranslate2
>>> translator = ctranslate2.Translator("/data/ende_ctranslate2/", device="cpu")
>>> translator.translate_batch([["▁H", "ello", "▁world", "!"]])
[[{'tokens': ['\xe2\x96\x81Hallo', '\xe2\x96\x81Welt', '!'], 'score': -1.0516233444213867}]]
Many thanks for your prompt reply.
Well, actually mi intention was to use it as a library inside an already working python project outside docker.
So I guess I would need to be able to deploy all that code as a Python package in the same way it was done inside the docker machine.
I actually tried, but I don’t know how to do it.
You could define an new Docker images starting with FROM opennmt/ctranslate2:latest-ubuntu18 which adds your projects and dependencies.
Or if you have a Linux distribution that matches one of the CTranslate2 Docker images, you could extract the Python package and install it on the host, for example:
I am trying generate “ende_ctranslate2 python terminal” from Docker image with the following command:(in windows machine)
Volume mount: Converted model in my local folder
docker run -it --rm -v //c/Users/Documents/python/cnvrtd_model:/data --entrypoint python opennmt/ctranslate2:latest-ubuntu18
Error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"python\": executable file not found in $PATH": unknown.