Giter Site home page Giter Site logo

dynamic-learning's Introduction

Marian NMT dynamic adaptation example

This repository aims to provide working self-contained example of Marian NMT system with dynamic adaptation.

The example builds and runs as 3 Docker containers

  • Marian adaptive server
  • Translation memory service
  • Wrapper service

Marian NMT dynamic adaptation works by fine-tuning model on context - (source, target) sentence pairs. So for each translation Marian requires the input text and context for fine-tuning.

Translation memory provides the context sentences for Marian. The current implementation: https://github.com/tilde-nlp/lucene-sentence-search/ Provides with functionality to:

  • Store indexed (source, target) sentence pairs.
  • Retrieve similar sentences by BLEU.
  • Drop sentence pairs.

Wrapper is just an additional service that simplifies API by forwarding calls to Translation Memory and Marian. Wrapper service also serves as a simple example how Translation Memory and Marian interacts.

Prerequisites

The example is built and run with Docker and docker-compose v1.28.0+ and is expected to run on a machine equipped Nvidia GPU https://docs.docker.com/compose/install/

How to build and run example

First download model files by running bash download_model.sh in the repo root directory.
Then build and start the services by docker-compose up.
Which will then load the downloaded marian model and expose the API on port 8088.

Configuration

Wrapper, Marian and Translation Memory startup parameters are defined in docker-compose.yml By default it's configured to load downloaded example marian model in ./marian-model and run on GPU: 0.

API

Wrapper service exposes 3 actions:

  • /translate Translate input sentence, context is fetched from TM.
  • /save Save (source, target) sentence pair in TM by user ID.
  • /delete Drop all saved sentences in index by user ID.

Wrapper API call examples:

POST http://localhost:8088/translate
Content-Type: application/json

Request: 
{
  "input": "Hello world !",
  "meta": {
    "uid": "Artūrs",
    "srclang": "en"
  }
}

Reply:
{
  "output": "Sveikas pasaulis !"
}
POST http://localhost:8088/save
Content-Type: application/json

Request:
{
  "source": "Hello world !",
  "target": "Sveika pasaule !",
  "meta": {
    "uid": "Artūrs",
    "srclang": "en"
  }
}

Reply: 
{
  "errorMessage": null,
  "status": "OK"
}
POST http://localhost:8088/delete
Content-Type: application/json

Request:
{
    "uid": "Artūrs"
}

Reply: 
{
  "errorMessage": null,
  "status": "OK"
}

Using different Translation Memory

Marian itself does not depend on a specific Translation Memory implementation. Different ways of acquiring context can be employed. An example implementation of how marian-adpative server is called can be found in wrapper_service/wrapper_service.py

ws://localhost:80/translate

Sent:
{
    "input": "Hello world !",
    "context": [
        "Source context sentence 1\nSource context sentence 2\nSource context sentence 3",
        "Target context sentence 1\nTarget context sentence 2\nTarget context sentence 3"
    ]
}

Received:
{
  "output": "Sveikas pasaulis !"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.