OfflineAddPunctuation.java
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2024 Xiaomi Corporation
// This file shows how to use a punctuation model to add punctuations to text.
//
// The model supports both English and Chinese.
import com.k2fsa.sherpa.onnx.*;
public class OfflineAddPunctuation {
public static void main(String[] args) {
// please download the model from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/punctuation-models
String model = "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx";
OfflinePunctuationModelConfig modelConfig =
OfflinePunctuationModelConfig.builder()
.setCtTransformer(model)
.setNumThreads(1)
.setDebug(true)
.build();
OfflinePunctuationConfig config =
OfflinePunctuationConfig.builder().setModel(modelConfig).build();
OfflinePunctuation punct = new OfflinePunctuation(config);
String[] sentences =
new String[] {
"这是一个测试你好吗How are you我很好thank you are you ok谢谢你",
"我们都是木头人不会说话不会动",
"The African blogosphere is rapidly expanding bringing more voices online in the form of"
+ " commentaries opinions analyses rants and poetry",
};
System.out.println("---");
for (String text : sentences) {
String out = punct.addPunctuation(text);
System.out.printf("Input: %s\n", text);
System.out.printf("Output: %s\n", out);
System.out.println("---");
}
}
}