2024-04-24 18:41:48 +08:00
|
|
|
// Copyright 2022-2023 by zhaoming
|
|
|
|
|
// Copyright 2024 Xiaomi Corporation
|
2023-08-16 20:16:51 +08:00
|
|
|
|
|
|
|
|
package com.k2fsa.sherpa.onnx;
|
|
|
|
|
|
|
|
|
|
public class OnlineModelConfig {
|
2024-02-26 13:49:37 +08:00
|
|
|
private final OnlineTransducerModelConfig transducer;
|
2024-04-24 18:41:48 +08:00
|
|
|
private final OnlineParaformerModelConfig paraformer;
|
2024-02-26 13:49:37 +08:00
|
|
|
private final OnlineZipformer2CtcModelConfig zipformer2Ctc;
|
2024-05-16 12:16:17 +08:00
|
|
|
private final OnlineNeMoCtcModelConfig neMoCtc;
|
2024-02-26 13:49:37 +08:00
|
|
|
private final String tokens;
|
|
|
|
|
private final int numThreads;
|
|
|
|
|
private final boolean debug;
|
2024-04-24 18:41:48 +08:00
|
|
|
private final String provider;
|
|
|
|
|
private final String modelType;
|
2024-05-23 14:49:37 +08:00
|
|
|
private final String modelingUnit;
|
|
|
|
|
private final String bpeVocab;
|
2024-04-24 21:03:26 +08:00
|
|
|
|
2024-04-24 18:41:48 +08:00
|
|
|
private OnlineModelConfig(Builder builder) {
|
|
|
|
|
this.transducer = builder.transducer;
|
|
|
|
|
this.paraformer = builder.paraformer;
|
|
|
|
|
this.zipformer2Ctc = builder.zipformer2Ctc;
|
2024-05-16 12:16:17 +08:00
|
|
|
this.neMoCtc = builder.neMoCtc;
|
2024-04-24 18:41:48 +08:00
|
|
|
this.tokens = builder.tokens;
|
|
|
|
|
this.numThreads = builder.numThreads;
|
|
|
|
|
this.debug = builder.debug;
|
|
|
|
|
this.provider = builder.provider;
|
|
|
|
|
this.modelType = builder.modelType;
|
2024-05-23 14:49:37 +08:00
|
|
|
this.modelingUnit = builder.modelingUnit;
|
|
|
|
|
this.bpeVocab = builder.bpeVocab;
|
2024-04-24 18:41:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Builder builder() {
|
|
|
|
|
return new Builder();
|
2024-02-26 13:49:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OnlineParaformerModelConfig getParaformer() {
|
|
|
|
|
return paraformer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OnlineTransducerModelConfig getTransducer() {
|
|
|
|
|
return transducer;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 18:41:48 +08:00
|
|
|
public OnlineZipformer2CtcModelConfig getZipformer2Ctc() {
|
|
|
|
|
return zipformer2Ctc;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 12:16:17 +08:00
|
|
|
public OnlineNeMoCtcModelConfig getNeMoCtc() {
|
|
|
|
|
return neMoCtc;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-26 13:49:37 +08:00
|
|
|
public String getTokens() {
|
|
|
|
|
return tokens;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumThreads() {
|
|
|
|
|
return numThreads;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getDebug() {
|
|
|
|
|
return debug;
|
|
|
|
|
}
|
2024-04-24 18:41:48 +08:00
|
|
|
|
|
|
|
|
public String getProvider() {
|
|
|
|
|
return provider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getModelType() {
|
|
|
|
|
return modelType;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 14:49:37 +08:00
|
|
|
public String getModelingUnit() {
|
|
|
|
|
return modelingUnit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getBpeVocab() {
|
|
|
|
|
return bpeVocab;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 18:41:48 +08:00
|
|
|
public static class Builder {
|
|
|
|
|
private OnlineParaformerModelConfig paraformer = OnlineParaformerModelConfig.builder().build();
|
|
|
|
|
private OnlineTransducerModelConfig transducer = OnlineTransducerModelConfig.builder().build();
|
|
|
|
|
private OnlineZipformer2CtcModelConfig zipformer2Ctc = OnlineZipformer2CtcModelConfig.builder().build();
|
2024-05-16 12:16:17 +08:00
|
|
|
private OnlineNeMoCtcModelConfig neMoCtc = OnlineNeMoCtcModelConfig.builder().build();
|
2024-04-24 18:41:48 +08:00
|
|
|
private String tokens = "";
|
|
|
|
|
private int numThreads = 1;
|
|
|
|
|
private boolean debug = true;
|
|
|
|
|
private String provider = "cpu";
|
|
|
|
|
private String modelType = "";
|
2024-05-23 14:49:37 +08:00
|
|
|
private String modelingUnit = "cjkchar";
|
|
|
|
|
private String bpeVocab = "";
|
2024-04-24 18:41:48 +08:00
|
|
|
|
|
|
|
|
public OnlineModelConfig build() {
|
|
|
|
|
return new OnlineModelConfig(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setTransducer(OnlineTransducerModelConfig transducer) {
|
|
|
|
|
this.transducer = transducer;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setParaformer(OnlineParaformerModelConfig paraformer) {
|
|
|
|
|
this.paraformer = paraformer;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setZipformer2Ctc(OnlineZipformer2CtcModelConfig zipformer2Ctc) {
|
|
|
|
|
this.zipformer2Ctc = zipformer2Ctc;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 12:16:17 +08:00
|
|
|
public Builder setNeMoCtc(OnlineNeMoCtcModelConfig neMoCtc) {
|
|
|
|
|
this.neMoCtc = neMoCtc;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 18:41:48 +08:00
|
|
|
public Builder setTokens(String tokens) {
|
|
|
|
|
this.tokens = tokens;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setNumThreads(int numThreads) {
|
|
|
|
|
this.numThreads = numThreads;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setDebug(boolean debug) {
|
|
|
|
|
this.debug = debug;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setProvider(String provider) {
|
|
|
|
|
this.provider = provider;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setModelType(String modelType) {
|
|
|
|
|
this.modelType = modelType;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2024-05-23 14:49:37 +08:00
|
|
|
|
2025-04-24 16:25:36 +08:00
|
|
|
public Builder setModelingUnit(String modelingUnit) {
|
2024-05-23 14:49:37 +08:00
|
|
|
this.modelingUnit = modelingUnit;
|
2025-04-24 16:25:36 +08:00
|
|
|
return this;
|
2024-05-23 14:49:37 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 16:25:36 +08:00
|
|
|
public Builder setBpeVocab(String bpeVocab) {
|
2024-05-23 14:49:37 +08:00
|
|
|
this.bpeVocab = bpeVocab;
|
2025-04-24 16:25:36 +08:00
|
|
|
return this;
|
2024-05-23 14:49:37 +08:00
|
|
|
}
|
2024-04-24 18:41:48 +08:00
|
|
|
}
|
2023-08-16 20:16:51 +08:00
|
|
|
}
|