This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow.contrib import rnn | |
| class RNNGenerator: | |
| def create_LSTM(self, inputs, weights, biases, seq_size, num_units): | |
| # Reshape input to [1, sequence_size] and split it into sequences | |
| inputs = tf.reshape(inputs, [-1, seq_size]) | |
| inputs = tf.split(inputs, seq_size, 1) | |
| # LSTM with 2 layers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| import random | |
| import numpy as np | |
| class SessionRunner(): | |
| training_iters = 50000 | |
| def __init__(self, optimizer, accuracy, cost, lstm, initilizer, writer): | |
| self.optimizer = optimizer | |
| self.accuracy = accuracy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from DataHandler import DataHandler | |
| from RNN_generator import RNNGenerator | |
| from session_runner import SessionRunner | |
| log_path = '/output/tensorflow/' | |
| writer = tf.summary.FileWriter(log_path) | |
| # Load and prepare data | |
| data_handler = DataHandler() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.preprocessing import sequence | |
| from keras.models import Sequential | |
| from keras.layers import Dense, Dropout, Embedding, LSTM | |
| from keras.datasets import imdb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| num_words = 1000 | |
| (X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=num_words) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| X_train = sequence.pad_sequences(X_train, maxlen=200) | |
| X_test = sequence.pad_sequences(X_test, maxlen=200) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define network architecture and compile | |
| model = Sequential() | |
| model.add(Embedding(num_words, 50, input_length=200)) | |
| model.add(Dropout(0.2)) | |
| model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2)) | |
| model.add(Dense(250, activation='relu')) | |
| model.add(Dropout(0.2)) | |
| model.add(Dense(1, activation='sigmoid')) | |
| model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model.fit(X_train, y_train, batch_size=64, epochs=10) | |
| print('\nAccuracy: {}'. format(model.evaluate(X_test, y_test)[1])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Blog | |
| { | |
| private readonly ICollection<IBlogItem> _items; | |
| public Blog(ICollection<IBlogItem> items) | |
| { | |
| _items = items; | |
| } | |
| public void Expand() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IBlogItem | |
| { | |
| void Expand(); | |
| } | |
| public class Article : IBlogItem | |
| { | |
| public void Expand() | |
| { | |
| // Article expand implementation. |