Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Sequence Models/Week 1/Building a Recurrent Neural Network - Step by Step/__pycache__/utils.cpython-36.pyc
Views: 13381
3 �)Z^ � @ sf d dl Zdd� Zdd� Zdd� Zdd � Zd d� Zdd� Zd d� Zdd� Zdd� Z ddd�Z dd� ZdS )� Nc C s$ t j| t j| � �}||jdd� S )Nr )�axis)�np�exp�max�sum)�x�e_x� r �T/home/jovyan/work/Week 1/Building a Recurrent Neural Network - Step by Step/utils.py�softmax s r c C s | d |d S )Ng+�����?g����MbP?r )�lossZcur_lossr r r �smooth s r c s* dj � fdd�| D ��}td|f � d S )N� c 3 s | ]}� | V qd S )Nr )�.0�ix)� ix_to_charr r � <genexpr> s zprint_sample.<locals>.<genexpr>z---- %s ----)�join�print)Z sample_ixr �txtr )r r �print_sample s r c C s t jd| � | S )Ng �?)r �log)� vocab_sizeZ seq_lengthr r r �get_initial_loss s r c C s$ t j| t j| � �}||jdd� S )Nr )r )r r r r )r r r r r r s c C sr t jjd� t jj| |�d }t jj| | �d }t jj|| �d }t j| df�}t j|df�}|||||d�}|S )ak Initialize parameters with small random values Returns: parameters -- python dictionary containing: Wax -- Weight matrix multiplying the input, numpy array of shape (n_a, n_x) Waa -- Weight matrix multiplying the hidden state, numpy array of shape (n_a, n_a) Wya -- Weight matrix relating the hidden-state to the output, numpy array of shape (n_y, n_a) b -- Bias, numpy array of shape (n_a, 1) by -- Bias relating the hidden-state to the output, numpy array of shape (n_y, 1) � g{�G�z�?)�Wax�Waa�Wya�b�by)r �random�seed�randn�zeros) Zn_aZn_xZn_yr r r r r � parametersr r r �initialize_parameters s r% c C sj | d | d | d | d | d f\}}}}}t jt j||�t j||� | �}tt j||�| �} || fS )Nr r r r r )r �tanh�dotr ) r$ �a_prevr r r r r r Za_nextZp_tr r r �rnn_step_forward, s ,"r) c C s� |d t j| |j�7 <