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/Dinosaur Island -- Character-level language model/__pycache__/utils.cpython-36.pyc
Views: 13420
3 0�oZ1 � @ 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 �S/home/jovyan/work/Week 1/Dinosaur Island -- Character-level language model/utils.py�softmax s r c C s | d |d S )Ng+�����?g����MbP?r )�lossZcur_lossr r r �smooth s r c sF dj � fdd�| D ��}|d j� |dd � }td|f dd� d S )N� c 3 s | ]}� | V qd S )Nr )�.0�ix)� ix_to_charr r � <genexpr> s zprint_sample.<locals>.<genexpr>r � z%s)�end)�join�upper�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) r 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'