o
    }oiH                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZ d dlmZ d d	lmZmZ d
d ZG dd dZdS )    N)
DictConfig
ListConfig)LogisticRegression)Pipeline)StandardScaler)EncDecCTCModelEncDecHybridRNNTCTCModelEncDecRNNTModel)ConfidenceEnsembleModel)CTCDecodingConfig)ConfidenceConfigConfidenceMethodConfigc           	      C   s  ddi}g d}ddddd}| t u r,d	d t||d
}tdt|t|t|d}nRddddd}ddddd}dddid}dddid}tdt|t|tdddt|t|t|t|t|ddid d!d"d	d t||d
ttd#d$}| j d%| j |d&< |S )'N_target_z>nemo.collections.asr.modules.AudioToMelSpectrogramPreprocessor) 'abcz-nemo.collections.asr.modules.ConformerEncoder@         )r   feat_inn_layersd_modelz+nemo.collections.asr.modules.ConvASRDecoder)r   r   num_classes
vocabularyT)compute_eval_losspreprocessorencoderdecoderz(nemo.collections.asr.modules.RNNTDecoder   )pred_hiddenpred_rnn_layers)r   prednetz&nemo.collections.asr.modules.RNNTJointrelu)joint_hidden
activation)r   jointnetgreedy_batchmax_symbols   )strategygreedydefaultfastemit_lambdagMbP?)	loss_namewarprnnt_numba_kwargs)
enc_hiddenr!   nameadamwg333333?F
mean_batch)ctc_loss_weightuse_cerctc_reductionr   decoding)r   labelsr   model_defaultsr   r   jointr8   lossoptimaux_ctc.target)r   lenr   r   r   
__module____name__)	model_classpreprocessor_configr   encoder_configdecoder_configmodel_configjoint_configdecoding_configloss_config rL   c/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/asr/test_confidence_ensembles.pyget_model_config   sj   
rN   c                   @   sP   e Zd ZdZejjejdee	e
gejdee	e
gdd Zdd ZdS )	TestConfidenceEnsembleszOnly basic tests that are very fast to run.

    There are much more extensive integration tests available in
    scripts/confidence_ensembles/test_confidence_ensembles.py
    model_class0model_class1c              
   C   s~   t |}t |}tdt fdt fg}t||d  tdddtdddd	d
d}tt	t
|d |dd||ddd dS )z=Basic test to check that ensemble of 2 models can be created.scalerclf	dummy.pklTmeanentropyrenyi      ?linr2   entropy_typealphaentropy_normpreserve_frame_confidenceexclude_blankaggregation
method_cfg      ?   )model_selection_block
confidencetemperature
num_modelsmodel0model1Ncfgtrainer)rN   r   r   r   joblibdumpr   r   r
   r   str)selftmp_pathrP   rQ   model_config0model_config1pipeconfidence_configrL   rL   rM   test_model_creation_2modelsf   s6   


z3TestConfidenceEnsembles.test_model_creation_2modelsc                 C   s   dd t dD }tdt fdt fg}t||d  tdddtd	d
dddd}tt	t
|d |dd|d |d |d |d |d d	dd dS )z=Basic test to check that ensemble of 5 models can be created.c                 S   s   g | ]}t tqS rL   )rN   r   ).0_rL   rL   rM   
<listcomp>   s    zGTestConfidenceEnsembles.test_model_creation_5models.<locals>.<listcomp>   rR   rS   rT   TrU   rV   rW   rX   rY   rZ   r^   rc   rd   r   r       r   )	re   rf   rg   rh   ri   rj   model2model3model4Nrk   )ranger   r   r   rn   ro   r   r   r
   r   rp   )rq   rr   model_configsru   rv   rL   rL   rM   test_model_creation_5models   s:   

z3TestConfidenceEnsembles.test_model_creation_5modelsN)rC   rB   __qualname____doc__pytestmarkunitparametrizer   r	   r   rw   r   rL   rL   rL   rM   rO   _   s    &rO   )rn   r   	omegaconfr   r   sklearn.linear_modelr   sklearn.pipeliner   sklearn.preprocessingr   nemo.collections.asr.modelsr   r   r	   /nemo.collections.asr.models.confidence_ensembler
   2nemo.collections.asr.parts.submodules.ctc_decodingr   5nemo.collections.asr.parts.utils.asr_confidence_utilsr   r   rN   rO   rL   rL   rL   rM   <module>   s   C