mirror of
https://github.com/browsermt/bergamot-translator.git
synced 2024-10-26 05:43:59 +03:00
Remove AbstractTranslationModel class and its references
This commit is contained in:
parent
a3250b401f
commit
f38a0bfbcc
@ -7,9 +7,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "AbstractTranslationModel.h"
|
||||
#include "TranslationRequest.h"
|
||||
#include "TranslationResult.h"
|
||||
#include "TranslationModel.h"
|
||||
#include "translator/parser.h"
|
||||
#include "translator/byteArrayExample.h"
|
||||
|
||||
@ -21,11 +19,9 @@ int main(int argc, char **argv) {
|
||||
auto options = configParser.parseOptions(argc, argv, true);
|
||||
std::string config = options->asYamlString();
|
||||
|
||||
// Route the config string to construct marian model through
|
||||
// AbstractTranslationModel
|
||||
// Route the config string to construct marian model through TranslationModel
|
||||
void * model_bytes = bergamot::getBinaryModelFromConfig(options);
|
||||
std::shared_ptr<AbstractTranslationModel> model =
|
||||
AbstractTranslationModel::createInstance(config, model_bytes);
|
||||
auto model = std::make_shared<TranslationModel>(config, model_bytes);
|
||||
|
||||
TranslationRequest translationRequest;
|
||||
std::vector<std::string> texts;
|
||||
|
@ -7,9 +7,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "AbstractTranslationModel.h"
|
||||
#include "TranslationRequest.h"
|
||||
#include "TranslationResult.h"
|
||||
#include "TranslationModel.h"
|
||||
#include "translator/parser.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@ -20,10 +18,8 @@ int main(int argc, char **argv) {
|
||||
auto options = configParser.parseOptions(argc, argv, true);
|
||||
std::string config = options->asYamlString();
|
||||
|
||||
// Route the config string to construct marian model through
|
||||
// AbstractTranslationModel
|
||||
std::shared_ptr<AbstractTranslationModel> model =
|
||||
AbstractTranslationModel::createInstance(config);
|
||||
// Route the config string to construct marian model through TranslationModel
|
||||
auto model = std::make_shared<TranslationModel>(config);
|
||||
|
||||
TranslationRequest translationRequest;
|
||||
std::vector<std::string> texts;
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* AbstractTranslationModel.h
|
||||
*
|
||||
* An interface for a translation model for translating a plain (without any
|
||||
* markups and emojis) UTF-8 encoded text. The model supports translation from 1
|
||||
* source language to 1 target language. There can be different implementations
|
||||
* of this interface.
|
||||
*/
|
||||
|
||||
#ifndef SRC_TRANSLATOR_ABSTRACTTRANSLATIONMODEL_H_
|
||||
#define SRC_TRANSLATOR_ABSTRACTTRANSLATIONMODEL_H_
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "TranslationRequest.h"
|
||||
#include "TranslationResult.h"
|
||||
|
||||
/* An interface for a translation model for translating a plain (without any
|
||||
* markups and emojis) UTF-8 encoded text. The model supports translation from 1
|
||||
* source language to 1 target language.
|
||||
*/
|
||||
class AbstractTranslationModel {
|
||||
public:
|
||||
/* A Factory method to create and return an instance of an implementation of
|
||||
* AbstractTranslationModel. The instance is created using translation model
|
||||
* configuration provided as yaml-formatted string.
|
||||
*/
|
||||
/**
|
||||
* @param config Marian yml config file in the form of a string
|
||||
* @param model_memory byte array (aligned to 64!!!) that contains the bytes of a model.bin. Optional, defaults to nullptr when not used
|
||||
*/
|
||||
static std::shared_ptr<AbstractTranslationModel>
|
||||
createInstance(const std::string &config, const void * model_memory=nullptr);
|
||||
|
||||
AbstractTranslationModel() = default;
|
||||
|
||||
virtual ~AbstractTranslationModel() = default;
|
||||
|
||||
/* This method performs translation on a list of (UTF-8 encoded) texts and
|
||||
* returns a list of results in the same order. Each text entry can either be
|
||||
* a word, a phrase, a sentence or a list of sentences and should contain
|
||||
* plain text (without any markups or emojis). Additional information related
|
||||
* to the translated text can be requested via TranslationRequest which is
|
||||
* applied equally to each text entry.
|
||||
*
|
||||
* The translated text corresponding to each text entry and the additional
|
||||
* information (as specified in the TranslationRequest) is encapsulated and
|
||||
* returned in TranslationResult.
|
||||
*
|
||||
* The API splits each text entry into sentences internally, which are then
|
||||
* translated independent of each other. The translated sentences are then
|
||||
* joined together and returned in TranslationResult. Please refer to the
|
||||
* TranslationRequest class to find out what additional information can be
|
||||
* requested. The alignment information can only be requested if the model
|
||||
* supports it (check isAlignmentSupported() API).
|
||||
*
|
||||
* The texts argument will become empty after the execution of this API (each
|
||||
* entry of texts list will be moved to its corresponding TranslationResult
|
||||
* object).
|
||||
*/
|
||||
virtual std::vector<TranslationResult>
|
||||
translate(std::vector<std::string> &&texts, TranslationRequest request) = 0;
|
||||
|
||||
/* Check if the model can provide alignment information b/w original and
|
||||
* translated text. */
|
||||
virtual bool isAlignmentSupported() const = 0;
|
||||
};
|
||||
|
||||
#endif /* SRC_TRANSLATOR_ABSTRACTTRANSLATIONMODEL_H_ */
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* TranslationModel.h
|
||||
*
|
||||
* A implementation of AbstractTranslationModel interface.
|
||||
* Main interface for translation API.
|
||||
*/
|
||||
|
||||
#ifndef SRC_TRANSLATOR_TRANSLATIONMODEL_H_
|
||||
@ -15,14 +15,15 @@
|
||||
#include "3rd_party/marian-dev/src/common/options.h"
|
||||
|
||||
// All local project includes
|
||||
#include "AbstractTranslationModel.h"
|
||||
#include "TranslationRequest.h"
|
||||
#include "TranslationResult.h"
|
||||
#include "translator/service.h"
|
||||
|
||||
/* A Translation model that translates a plain (without any markups and emojis)
|
||||
* UTF-8 encoded text. This implementation supports translation from 1 source
|
||||
* language to 1 target language.
|
||||
*/
|
||||
class TranslationModel : public AbstractTranslationModel {
|
||||
class TranslationModel {
|
||||
public:
|
||||
/* Construct the model using the model configuration options as yaml-formatted
|
||||
* string
|
||||
@ -62,11 +63,11 @@ public:
|
||||
* object).
|
||||
*/
|
||||
std::vector<TranslationResult> translate(std::vector<std::string> &&texts,
|
||||
TranslationRequest request) override;
|
||||
TranslationRequest request);
|
||||
|
||||
/* Check if the model can provide alignment information b/w original and
|
||||
* translated text. */
|
||||
bool isAlignmentSupported() const override;
|
||||
bool isAlignmentSupported() const;
|
||||
|
||||
private:
|
||||
// Model configuration options
|
@ -2,7 +2,7 @@
|
||||
* TranslationRequest.h
|
||||
*
|
||||
* This file defines the translation request class to be used in
|
||||
* AbstractTranslationModel::translate() API.
|
||||
* TranslationModel::translate() API.
|
||||
*/
|
||||
|
||||
#ifndef SRC_TRANSLATOR_TRANSLATIONREQUEST_H_
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* TranslationResult.h
|
||||
*
|
||||
* The class that represents the result of AbstractTranslationModel::translate()
|
||||
* The class that represents the result of TranslationModel::translate()
|
||||
* API for each of its text entry and TranslationRequest.
|
||||
*/
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
#include "QualityScore.h"
|
||||
|
||||
/* This class represents the result of AbstractTranslationModel::translate() API
|
||||
/* This class represents the result of TranslationModel::translate() API
|
||||
* for each of its text entry and TranslationRequest.
|
||||
*/
|
||||
class TranslationResult {
|
||||
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* AbstractTranslationModel.cpp
|
||||
*
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
// All local includes
|
||||
#include "AbstractTranslationModel.h"
|
||||
#include "TranslationModel.h"
|
||||
|
||||
/**
|
||||
* @param config Marian yml config file in the form of a string
|
||||
* @param model_memory byte array (aligned to 64!!!) that contains the bytes of a model.bin. Optional, defaults to nullptr when not used
|
||||
*/
|
||||
std::shared_ptr<AbstractTranslationModel>
|
||||
AbstractTranslationModel::createInstance(const std::string &config, const void * model_memory) {
|
||||
return std::make_shared<TranslationModel>(config, model_memory);
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
add_library(bergamot-translator STATIC
|
||||
AbstractTranslationModel.cpp
|
||||
TranslationModel.cpp
|
||||
|
||||
byteArrayExample.cpp
|
||||
@ -30,7 +29,7 @@ endif(COMPILE_WASM)
|
||||
target_link_libraries(bergamot-translator marian ssplit)
|
||||
|
||||
target_include_directories(bergamot-translator
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}
|
||||
PUBLIC ${CMAKE_SOURCE_DIR}
|
||||
PUBLIC ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
TranslationModel::TranslationModel(const std::string &config,
|
||||
const void *model_memory)
|
||||
: AbstractTranslationModel(), service_(config, model_memory) {}
|
||||
: service_(config, model_memory) {}
|
||||
|
||||
TranslationModel::~TranslationModel() {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user