Code Monkey home page Code Monkey logo

ctranslate's Introduction

CTranslate

CTranslate is a C++ implementation of OpenNMT's translate.lua script, with no Torch/Lua dependencies. It facilitates the use of OpenNMT models in existing products and on various platforms using Eigen as a backend.

It supports CPU OpenNMT models. You can convert GPU trained models with the release_model.lua script.

Dependencies

  • C++11
  • CMake
  • Boost
  • Eigen > 3.3

Compiling

$ mkdir build
$ cd build
$ cmake -DEIGEN_ROOT=<path to Eigen library> ..

It will produce the dynamic library libonmt.so and the translation client cli/translate.

To compile only the library, use the -DLIB_ONLY=ON flag.

Using

Client

See cli/translate --help. It has the same interface as the translate.lua script in OpenNMT while adding the ability to work with the standard input and output.

Library

This project is also a convenient way to load OpenNMT models and translate texts in existing software.

Here is a very simple example:

#include <iostream>

#include <onmt/TranslatorFactory.h>

int main()
{
  // Create a new Translator object.
  auto translator = onmt::TranslatorFactory::build("enfr_model_release.t7");

  // Translate a tokenized sentence.
  std::cout << translator->translate("Hello world !") << std::endl;

  return 0;
}

For a more advanced usage, see:

  • include/onmt/TranslatorFactory.h to instantiate a new translator
  • include/onmt/ITranslator.h to translate sequences or batch of sequences
  • include/onmt/TranslationResult.h to retrieve results and attention vectors

Missing features

  • OpenNMT tokenization and detokenization

ctranslate's People

Contributors

guillaumekln avatar srush avatar

Watchers

 avatar

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.