create static method

Future<FutoSwipeEngine> create({
  1. required FutoSwipeOnnxBackend backend,
  2. required List<String> vocabulary,
  3. required Map<String, dynamic> scoring,
  4. required List<FutoSwipeWord> lexicon,
  5. required bool includeModelVocabulary,
  6. required int beamWidth,
})

Implementation

static Future<FutoSwipeEngine> create({
  required FutoSwipeOnnxBackend backend,
  required List<String> vocabulary,
  required Map<String, dynamic> scoring,
  required List<FutoSwipeWord> lexicon,
  required bool includeModelVocabulary,
  required int beamWidth,
}) async {
  if (vocabulary.length != futoContextVocabularySize) {
    throw FormatException(
      'FUTO vocabulary has ${vocabulary.length} words; '
      'expected $futoContextVocabularySize',
    );
  }
  final engine = FutoSwipeEngine._(
    backend: backend,
    vocabulary: List<String>.unmodifiable(vocabulary),
    decoderWeights: FutoScoringWeights.fromJson(scoring, _decoderScoringKey),
    contextWeights: FutoScoringWeights.fromJson(scoring, _contextScoringKey),
    embeddings: await backend.loadEmbeddings(),
    beamWidth: beamWidth,
  );
  engine.setLexicon(lexicon, includeModelVocabulary: includeModelVocabulary);
  return engine;
}