Upload INTEGRATION_GUIDE.txt with huggingface_hub
Browse files- INTEGRATION_GUIDE.txt +26 -0
INTEGRATION_GUIDE.txt
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
// Android Integration for CTranslate2 Helsinki-NLP/opus-mt-zh-bg
|
3 |
+
// Requires: CTranslate2 Java bindings + SentencePiece JNI
|
4 |
+
|
5 |
+
public 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-zh-bg
|
26 |
+
// Language pair: ZH -> BG
|