Skip to main content

No project description provided

Project description

Marian Client

A client for interacting with Marian-NMT websocket server (see MarianNMT).

Marian is a state of the art Neural Machine Translation framework written in C++. Eventually, someone should write Python bindings (not it!). Until then, the recommended way of communicating with Marian is via WebSockets. The authors of Marian provide an example of doing this with this script. If you need Python2 support, you should look at that script.

What this project contributes beyond the above script:

  • Persistent connection - This keeps a connection open between Marian Server and Python. This saves a few hundred ms per call, which is significant
  • Encapsulation - just import a class, instantiate, and call. Don't think about websockets at all
  • Timeout, retries, and error handling - websockets are not the most reliable. Connections fail, timeouts happen. Just pass a value for timeout and retries when you instantiate MarianClient and this will just be handled for you.

Installation

pip install marian-client

Usage

from marian_client import MarianClient

# These are the default values:
host = "localhost"
port = "8080"

# or give the fully qualified URL
url = "ws://my.marian.server.ip/translate"

# Default values
timeout = 30  # measured in seconds - you may want to make this much lower
retries = 3  # amount of times to retry on error. backs off exponentially.

debug = False  # set to True for a little more info on errors

mc = MarianClient(PORT=port, HOST=host, timeout=timeout, retries=retries, debug=debug)
# or if you want to specify url
# mc = MarianClient(url, timeout=timeout, retries=retries, debug=debug)

# if you just want all the default values, and marian-server is running locally:
# mc = MarianClient()

tokenized_sentence = "Alice like cats ."

success, corrected_sentence, error_info = mc(tokenized_sentence)

if success:
    print(corrected_sentence)
else:
    print(f"Call to MarianClient failed with error code {error_info[0]} and message {error_info[1]}")

# If marian-server is sert up and working, this prints
# >>> "Alice likes cats ."

License

Like Marian, this package is released under the MIT license.

Credits

This package was made by the NLP team at Qordoba. If you are using it, and interested in working on NLP, maybe reach out to Sam?

Thanks to Marcin Junczys-Dowmunt and the rest of the awesome authors of Marian!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marian-client-0.13.0.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file marian-client-0.13.0.tar.gz.

File metadata

  • Download URL: marian-client-0.13.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for marian-client-0.13.0.tar.gz
Algorithm Hash digest
SHA256 7da46187d423b819c39ba94c6e4b80a2657f6aeac6e314a4b5ccfb65b18c441c
MD5 98a49907a2c2370841b1ebf8a19362ac
BLAKE2b-256 889c3f67bd8a6bfcda051672191d0850817aef74a0192c5fee997c785b880613

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page