U
    -e
                     @   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                       sD   e Zd ZdZd
eeeedd fddZejejddd	Z	  Z
S )FullyConnectedzh
    Args:
        n_feature: Number of input features
        n_hidden: Internal hidden unit size.
       N)	n_featuren_hiddendropoutrelu_max_clipreturnc                    s2   t t|   tjj||dd| _|| _|| _d S )NT)Zbias)	superr   __init__torchnnLinearfcr   r   )selfr   r   r   r   	__class__ ]/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/torchaudio/models/deepspeech.pyr      s    zFullyConnected.__init__xr	   c                 C   sL   |  |}tjj|}tjj|d| j}| jrHtjj|| j| j}|S )Nr   )	r   r   r   
functionalreluZhardtanhr   r   Ztraining)r   r   r   r   r   forward   s    
zFullyConnected.forward)r   __name__
__module____qualname____doc__intfloatr   r   ZTensorr   __classcell__r   r   r   r   r      s   r   c                       sD   e Zd ZdZdeeeedd fddZejejd	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
       (           N)r   r   n_classr   r	   c                    sx   t t|   || _t|||| _t|||| _t|||| _tj	j
||dddd| _t|||| _tj	||| _d S )N   r   T)Z
num_layersZnonlinearitybidirectional)r
   r   r   r   r   fc1fc2fc3r   r   Z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*   ZsqueezeZ	transposer+   r   r,   r-   Zpermuter   r   r   Z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   