Search code examples
pythonspeech-recognitionhmmlearn

Why do I get "'diag' mixture covars must be non-negative" error when I use model.score in hmmlearn package?


I've been working on continues speech recognition for a month and I found hmmlearn package. I could create my phoneme models with _model = hmm.GMMHMM(...) and _model.fit(...). But when I want to use _model.score(_extracted_test_features) for test samples, I got this error:

.format(self.covariance_type)) ValueError: 'diag' mixture covars must be non-negative

Here is my code:

    def Main():
        # ---
        _phoneme_files_dir = './database_info/phonemes/phoneme_files/'
        _phoneme_dataset_dir = './database_info/phonemes/extracted_features/'
        _phoneme_models_dir = './database_info/phonemes/models/'
        _phoneme_test = '/home/ali/speech_recognition/database/database_english/timit/data/lisa/data/timit/raw/TIMIT/TEST/DR1/FAKS0/SA1.wav'
        # ---
        _phoneme_test_features = ExtractFeatures(_phoneme_test, 9640, 11240)
        _phoneme_models, _phoneme_models_list_loaded = LoadModels(_phoneme_models_dir)
        print("Getting models has successfully done")
        # ---
        _score_list = {}
        for _model_label in _phoneme_models.keys():
            _model = _phoneme_models[_model_label][0]
            _score = _model.score(_phoneme_test_features)
            _score_list[_model_label] = _score
        _predict = max(_score_list, key=_score_list.get)
        print("predict result phoneme is ", _phoneme_models_list_loaded[_predict])

Anyone knows about this error? I've found some solution but they were for a few years ago and after that hmmlearn package got some updates and fixed them.


Solution

  • Usually it means some phoneme has not enough data during training and your model didn't train properly. You need many many samples > 100 to train, with just couple samples it will not work.

    You can print the model values to check which are negative.

    It is better to use specialized toolkit like kaldi or espnet for speech training, HMMlearn is not the right tool, it is not properly implemented for speech.