CoolFace
Modelpublic

manancode/opus-mt-fi-bem-ctranslate2-android

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes7downloads
INTEGRATION_GUIDE.txt27 linesDownload Raw Back to root
1 2// Android Integration for CTranslate2 Helsinki-NLP/opus-mt-fi-bem3// Requires: CTranslate2 Java bindings + SentencePiece JNI4 5public class CTranslate2Translator {6    private Translator translator;7    private SentencePieceProcessor sourceProcessor;8    private SentencePieceProcessor targetProcessor;9 10    public CTranslate2Translator(String modelPath, String sourceSpm, String targetSpm) {11        translator = new Translator(modelPath);12        sourceProcessor = new SentencePieceProcessor();13        targetProcessor = new SentencePieceProcessor();14        sourceProcessor.load(sourceSpm);15        targetProcessor.load(targetSpm);16    }17 18    public String translate(String text) {19        String[] srcTokens = sourceProcessor.encode(text);20        TranslationResult result = translator.translateBatch(Arrays.asList(srcTokens)).get(0);21        return targetProcessor.decode(result.getHypotheses().get(0));22    }23}24 25// Model: Helsinki-NLP/opus-mt-fi-bem26// Language pair: FI -> BEM27