CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
y33-j3T

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: y33-j3T/Coursera-Deep-Learning
Path: blob/master/Sequence Models/Week 1/Jazz improvisation with LSTM/__pycache__/lstm.cpython-36.pyc
Views: 13381
3

�RZ�@sRdZddlmZddlmZddlmZmZmZddl	m
Z
ddlZd
dd	�Z
dS)a,
Author:     Ji-Sung Kim
Project:    deepjazz
Purpose:    Builds an LSTM, a type of recurrent neural network (RNN). 

Code was built while significantly referencing public examples from the
Keras documentation on GitHub:
https://github.com/fchollet/keras/blob/master/examples/lstm_text_generation.py
�)�print_function)�
Sequential)�Dense�
Activation�Dropout)�LSTMN�cCs|tt|��}d}g}g}xDtdt|�||�D],}|j||||��|j|||�q.Wtdt|��tjt|�||ftjd�}	tjt|�|ftjd�}
xPt|�D]D\}}x&t|�D]\}}
d|	||||
f<q�Wd|
||||f<q�Wt	�}|j
tdd||fd��|j
td	��|j
tdd
d��|j
td	��|j
t
|��|j
td��|jd
dd�|j|	|
d|d�|S)N�rz
nb sequences:)�dtype�rT)�return_sequences�input_shapeg�������?F)rZsoftmaxZcategorical_crossentropyZrmsprop)�lossZ	optimizer)�
batch_sizeZnb_epoch)�len�set�range�append�print�np�zeros�bool�	enumerater�addrrrr�compile�fit)�corpus�val_indices�max_lenZN_epochsZN_values�stepZ	sentencesZnext_values�i�X�yZsentence�t�val�model�r&�)/home/jovyan/work/Week 1/DeepJazz/lstm.py�build_models0r()r)�__doc__�
__future__rZkeras.modelsrZkeras.layers.corerrrZkeras.layers.recurrentr�numpyrr(r&r&r&r'�<module>	s