Wav2letter: cannot import name 'LexiconFreeDecoder'

Created on 5 Aug 2020  路  5Comments  路  Source: flashlight/wav2letter

Bug Description

>>> from wav2letter.decoder import LexiconFreeDecoder
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'LexiconFreeDecoder'
Can you help me out?

enhancement python-bindings

Most helpful comment

Also, need to include
#include "libraries/decoder/LexiconFreeDecoder.h"
around line 13

Thanks @Liam1030 for the help here

I was able to build...I'll submit a push if I'm able to test a model with this

All 5 comments

Could you try just

import wav2letter

?

Could you try just

import wav2letter

?
@tlikhomanenko
Yes,import wav2letterworks. And import wav2letter.decoder also works. But from wav2letter.decoder import LexiconFreeDecoder does not work.

ohh, sorry, didn't notice that you are importing LexiconFreeDecoder: we don't support it in python bindings right now. I will add this in future, but feel free to use this code (feel free to submit pull request on this as soon as you test if this works):

void LexiconFreeDecoder_decodeStep(
    LexiconFreeDecoder& decoder,
    uintptr_t emissions,
    int T,
    int N) {
  decoder.decodeStep(reinterpret_cast<const float*>(emissions), T, N);
}

std::vector<DecodeResult> LexiconFreeDecoder_decode(
    LexiconFreeDecoder& decoder,
    uintptr_t emissions,
    int T,
    int N) {
  return decoder.decode(reinterpret_cast<const float*>(emissions), T, N);
}
py::class_<LexiconFreeDecoder>(m, "LexiconFreeDecoder")
      .def(py::init<
           const DecoderOptions&,
           const LMPtr,
           const int,
           const int,
           const std::vector<float>&>())
      .def("decode_begin", &LexiconFreeDecoder::decodeBegin)
      .def(
          "decode_step",
          &LexiconFreeDecoder_decodeStep,
          "emissions"_a,
          "T"_a,
          "N"_a)
      .def("decode_end", &LexiconFreeDecoder::decodeEnd)
      .def("decode", &LexiconFreeDecoder_decode, "emissions"_a, "T"_a, "N"_a)
      .def("prune", &LexiconFreeDecoder::prune, "look_back"_a = 0)
      .def(
          "get_best_hypothesis",
          &LexiconFreeDecoder::getBestHypothesis,
          "look_back"_a = 0)
      .def("get_all_final_hypothesis", &LexiconFreeDecoder::getAllFinalHypothesis);

Then you need to reinstall python bindings and LexiconFreeDecoder will be available.

ohh, sorry, didn't notice that you are importing LexiconFreeDecoder: we don't support it in python bindings right now. I will add this in future, but feel free to use this code (feel free to submit pull request on this as soon as you test if this works):

void LexiconFreeDecoder_decodeStep(
    LexiconFreeDecoder& decoder,
    uintptr_t emissions,
    int T,
    int N) {
  decoder.decodeStep(reinterpret_cast<const float*>(emissions), T, N);
}

std::vector<DecodeResult> LexiconFreeDecoder_decode(
    LexiconFreeDecoder& decoder,
    uintptr_t emissions,
    int T,
    int N) {
  return decoder.decode(reinterpret_cast<const float*>(emissions), T, N);
}
py::class_<LexiconFreeDecoder>(m, "LexiconFreeDecoder")
      .def(py::init<
           const DecoderOptions&,
           const LMPtr,
           const int,
           const int,
           const std::vector<float>&>())
      .def("decode_begin", &LexiconFreeDecoder::decodeBegin)
      .def(
          "decode_step",
          &LexiconFreeDecoder_decodeStep,
          "emissions"_a,
          "T"_a,
          "N"_a)
      .def("decode_end", &LexiconFreeDecoder::decodeEnd)
      .def("decode", &LexiconFreeDecoder_decode, "emissions"_a, "T"_a, "N"_a)
      .def("prune", &LexiconFreeDecoder::prune, "look_back"_a = 0)
      .def(
          "get_best_hypothesis",
          &LexiconFreeDecoder::getBestHypothesis,
          "look_back"_a = 0)
      .def("get_all_final_hypothesis", &LexiconFreeDecoder::getAllFinalHypothesis);

Then you need to reinstall python bindings and LexiconFreeDecoder will be available.

Many thanks! I'll try that later. Also I tried to use LexiconDecoder with a lexicon and that works well.

Also, need to include
#include "libraries/decoder/LexiconFreeDecoder.h"
around line 13

Thanks @Liam1030 for the help here

I was able to build...I'll submit a push if I'm able to test a model with this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nutriver picture nutriver  路  3Comments

JanX2 picture JanX2  路  5Comments

AvielNiego picture AvielNiego  路  6Comments

ekorudi picture ekorudi  路  5Comments

kamakshi-malhotra picture kamakshi-malhotra  路  5Comments