o
     ôjº
  ã                   @   s:   d dl Z dgZG dd„ de jjƒZG dd„ de jjƒZdS )é    NÚ
DeepSpeechc                       sN   e Zd ZdZddededededdf
‡ fd	d
„Zdejdejfdd„Z	‡  Z
S )ÚFullyConnectedzh
    Args:
        n_feature: Number of input features
        n_hidden: Internal hidden unit size.
    é   Ú	n_featureÚn_hiddenÚdropoutÚrelu_max_clipÚreturnNc                    s2   t t| ƒ ¡  tjj||dd�| _|| _|| _d S )NT)Úbias)	Úsuperr   Ú__init__ÚtorchÚnnÚLinearÚfcr   r   )Úselfr   r   r   r   ©Ú	__class__© úo/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torchaudio/models/deepspeech.pyr      s   
zFullyConnected.__init__Úxc                 C   sL   |   |¡}tjj |¡}tjj |d| j¡}| jr$tjj || j| j¡}|S )Nr   )	r   r   r   Ú
functionalÚreluÚhardtanhr   r   Útraining)r   r   r   r   r   Úforward   s   
zFullyConnected.forward)r   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintÚfloatr   r   ÚTensorr   Ú__classcell__r   r   r   r   r      s    $r   c                       sT   e Zd ZdZ			ddedededed	d
f
‡ fdd„Zdejd	ejfdd„Z	‡  Z
S )r   a  DeepSpeech architecture introduced in
    *Deep Speech: Scaling up end-to-end speech recognition* :cite:`hannun2014deep`.

    Args:
        n_feature: Number of input features
        n_hidden: Internal hidden unit size.
        n_class: Number of output classes
    é   é(   ç        r   r   Ún_classr   r	   Nc                    sx   t t| ƒ ¡  || _t|||ƒ| _t|||ƒ| _t|||ƒ| _tj	j
||dddd�| _t|||ƒ| _tj	 ||¡| _d S )Né   r   T)Ú
num_layersÚnonlinearityÚbidirectional)r   r   r   r   r   Úfc1Úfc2Úfc3r   r   ÚRNNÚbi_rnnÚfc4r   Úout)r   r   r   r(   r   r   r   r   r   &   s   zDeepSpeech.__init__r   c                 C   s²   |   |¡}|  |¡}|  |¡}| d¡}| dd¡}|  |¡\}}|dd…dd…d| j…f |dd…dd…| jd…f  }|  |¡}|  |¡}| 	ddd¡}t
jjj|dd�}|S )zÃ
        Args:
            x (torch.Tensor): Tensor of dimension (batch, channel, time, feature).
        Returns:
            Tensor: Predictor tensor of dimension (batch, time, class).
        r)   r   Né   )Údim)r-   r.   r/   ÚsqueezeÚ	transposer1   r   r2   r3   Úpermuter   r   r   Úlog_softmax)r   r   Ú_r   r   r   r   6   s   



8

zDeepSpeech.forward)r%   r&   r'   r   r   r   r   r   r      s"    ûþýüûú)r   Ú__all__r   ÚModuler   r   r   r   r   r   Ú<module>   s    