Last active
June 23, 2018 19:12
-
-
Save DavidRdgz/4c0ffc32cc42610cb8ef8d2825b5e2d3 to your computer and use it in GitHub Desktop.
Another toy (binary) mixture of experts model with 4 experts and a gating network.
This file contains 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.models import Model | |
from keras.layers import Input, Dense, concatenate, dot | |
from numpy.random import randint | |
import numpy as np | |
def my_model(n=20): | |
inputs = Input(shape=(n,)) | |
m1 = Dense(1)(inputs) | |
m2 = Dense(1)(inputs) | |
m3 = Dense(1)(inputs) | |
m4 = Dense(1)(inputs) | |
gates = Dense( | |
4, activation="sigmoid" | |
)(inputs) | |
models = concatenate([m1, m2, m3, m4]) | |
output = dot([models, gates], 1) | |
model = Model([inputs], output) | |
model.compile( | |
loss='binary_crossentropy', | |
optimizer="sgd" | |
) | |
return model | |
def test_data(m=1000, n=20): | |
x = np.random.random((m, n)) | |
y = randint(2, size=(m, 1)) | |
return y, x | |
if __name__ == '__main__': | |
y_train, x_train = test_data() | |
model = my_model() | |
model.fit([x_train], y_train) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment