Skip to main content

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 ."

Notes

  • When instantiating a MarianClient instance, if we receive a ConnectionRefusedError, we attempt to reconnect connection_retries times, with exponential backoff, maxing out at max_wait_time_between_connection_attempts.
  • This means in the default case, if Marian Server is unavailable, we will try to connect, wait 1 second, try to connect again, wait 2 seconds, try to connect again, wait 4 seconds, ... then 8, 16, 32, 64, 128, 256, 300, then actually fail, for a total wait time of 811 seconds.

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!

Release files for marian-client 0.16.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for marian-client 0.16.0
File Size Uploaded
marian-client-0.16.0.tar.gz 7.2 kB Details

Release files / marian-client-0.16.0.tar.gz

Download URL marian-client-0.16.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d13a626922acadc5d7b7d27563ce7e7f0e66e1a89eb2f13e8780c2be7cb8bce3
BLAKE2b-256 checksum
How to use checksums
3ba99c84ea9ab60acee6c070040475b1850780ef96da73e928aae0d20c59a889
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.16.0 This release

1 release file

0.15.0

1 release file

0.14.0

1 release file

0.13.0

1 release file

0.12.0

1 release file

0.11.0

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page