Last active
November 21, 2016 20:59
-
-
Save DeNeutoy/f0491419382ca3a53564b3cce313e19a to your computer and use it in GitHub Desktop.
Parameter Bottlenecks
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
import tensorflow as tf | |
def mix_models_scalar(linear_outputs, rnn_outputs, lstm_outputs): | |
# Generate scalar valued weights to combine outputs of a | |
# Linear RNN, vanilla RNN and LSTM. Each of the inputs to | |
# this function is a list of outputs from the respective model. | |
context_window_size = 20 | |
all_model_outputs = [linear_outputs, rnn_outputs, lstm_outputs] | |
# Get scalar valued weights for each model. | |
mixing_weights = [tf.get_variable(model, [1.0],trainable=True) | |
for model in ['linear_weight', 'rnn_weight', 'lstm_weight']] | |
all_weighted_outputs = [] | |
# Multiply the relevant weight with every model's states | |
for weight, model_output in zip(weights, all_model_outputs): | |
weighted_output = [weight * model_output[i] for i in range(context_window_size)] | |
all_weighted_outputs.append(weighted_output) | |
# Add relevant weighted states from each model together. | |
combined_outputs = [tf.add_n(*context_step) for context_step in zip(*all_weighted_outputs)] | |
# This is a list of 20 (batch_size, hidden_dimension) tensors, | |
# having combined the weighted outputs of all three models. | |
return combined_outputs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment