opus-mt-zls-zls-ctranslate2-android / INTEGRATION_GUIDE.txt
manancode's picture
Upload INTEGRATION_GUIDE.txt with huggingface_hub
b209fd1 verified
raw
history blame contribute delete
988 Bytes
// Android Integration for CTranslate2 Helsinki-NLP/opus-mt-zls-zls
// Requires: CTranslate2 Java bindings + SentencePiece JNI
public class CTranslate2Translator {
private Translator translator;
private SentencePieceProcessor sourceProcessor;
private SentencePieceProcessor targetProcessor;
public CTranslate2Translator(String modelPath, String sourceSpm, String targetSpm) {
translator = new Translator(modelPath);
sourceProcessor = new SentencePieceProcessor();
targetProcessor = new SentencePieceProcessor();
sourceProcessor.load(sourceSpm);
targetProcessor.load(targetSpm);
}
public String translate(String text) {
String[] srcTokens = sourceProcessor.encode(text);
TranslationResult result = translator.translateBatch(Arrays.asList(srcTokens)).get(0);
return targetProcessor.decode(result.getHypotheses().get(0));
}
}
// Model: Helsinki-NLP/opus-mt-zls-zls
// Language pair: ZLS -> ZLS