project_name
stringlengths
6
104
file_name
stringlengths
4
89
full_name
stringlengths
1
102
func_name
stringlengths
1
85
docstring
stringlengths
13
836
docstring_tokens
listlengths
4
122
code
stringlengths
23
39.7k
code_tokens
stringlengths
29
44.6k
url
int64
3
986k
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
split_to_discretized_mix_logistic_params
split_to_discretized_mix_logistic_params
Splits input tensor into parameters of discretized mixture logistic.
[ "Splits", "input", "tensor", "into", "parameters", "of", "discretized", "mixture", "logistic." ]
def split_to_discretized_mix_logistic_params(inputs): (batch, height, width, output_dim) = shape_list(inputs) num_mixtures = output_dim // 10 (logits, locs, log_scales, coeffs) = tf.split(inputs, num_or_size_splits=[num_mixtures, num_mixtures * 3, num_mixtures * 3, num_mixtures * 3], axis=-1) split_shap...
['def', 'split_to_discretized_mix_logistic_params(inputs):', '(batch,', 'height,', 'width,', 'output_dim)', '=', 'shape_list(inputs)', 'num_mixtures', '=', 'output_dim', '//', '10', '(logits,', 'locs,', 'log_scales,', 'coeffs)', '=', 'tf.split(inputs,', 'num_or_size_splits=[num_mixtures,', 'num_mixtures', '*', '3,', 'n...
965,305
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
sample_from_discretized_mix_logistic
sample_from_discretized_mix_logistic
Sampling from a discretized mixture of logistics.
[ "Sampling", "from", "a", "discretized", "mixture", "of", "logistics." ]
def sample_from_discretized_mix_logistic(pred, seed=None): (logits, locs, log_scales, coeffs) = split_to_discretized_mix_logistic_params(pred) num_mixtures = shape_list(logits)[-1] gumbel_noise = -tf.log(-tf.log(tf.random_uniform(tf.shape(logits), minval=1e-05, maxval=1.0 - 1e-05, seed=seed))) sel = tf....
['def', 'sample_from_discretized_mix_logistic(pred,', 'seed=None):', '(logits,', 'locs,', 'log_scales,', 'coeffs)', '=', 'split_to_discretized_mix_logistic_params(pred)', 'num_mixtures', '=', 'shape_list(logits)[-1]', 'gumbel_noise', '=', '-tf.log(-tf.log(tf.random_uniform(tf.shape(logits),', 'minval=1e-05,', 'maxval=1...
965,306
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
ones_matrix_band_part
ones_matrix_band_part
Matrix band part of ones.
[ "Matrix", "band", "part", "of", "ones." ]
def ones_matrix_band_part(rows, cols, num_lower, num_upper, out_shape=None): if all([isinstance(el, int) for el in [rows, cols, num_lower, num_upper]]): if num_lower < 0: num_lower = rows - 1 if num_upper < 0: num_upper = cols - 1 lower_mask = np.tri(cols, rows, num_l...
['def', 'ones_matrix_band_part(rows,', 'cols,', 'num_lower,', 'num_upper,', 'out_shape=None):', 'if', 'all([isinstance(el,', 'int)', 'for', 'el', 'in', '[rows,', 'cols,', 'num_lower,', 'num_upper]]):', 'if', 'num_lower', '<', '0:', 'num_lower', '=', 'rows', '-', '1', 'if', 'num_upper', '<', '0:', 'num_upper', '=', 'col...
965,327
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
summarize_video
summarize_video
Summarize the video using image summaries starting with prefix.
[ "Summarize", "the", "video", "using", "image", "summaries", "starting", "with", "prefix." ]
def summarize_video(video, prefix, max_outputs=1): video_shape = shape_list(video) if len(video_shape) != 5: raise ValueError('Assuming videos given as tensors in the format [batch, time, height, width, channels] but got one of shape: %s' % str(video_shape)) if tf.contrib.eager.in_eager_mode(): ...
['def', 'summarize_video(video,', 'prefix,', 'max_outputs=1):', 'video_shape', '=', 'shape_list(video)', 'if', 'len(video_shape)', '!=', '5:', 'raise', "ValueError('Assuming", 'videos', 'given', 'as', 'tensors', 'in', 'the', 'format', '[batch,', 'time,', 'height,', 'width,', 'channels]', 'but', 'got', 'one', 'of', 'sha...
965,341
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
time_to_channels
time_to_channels
Put time dimension on channels in an embedded video.
[ "Put", "time", "dimension", "on", "channels", "in", "an", "embedded", "video." ]
def time_to_channels(embedded_video): video_shape = shape_list(embedded_video) if len(video_shape) != 5: raise ValueError('Assuming videos given as tensors in the format [batch, time, height, width, channels] but got one of shape: %s' % str(video_shape)) transposed = tf.transpose(embedded_video, [0,...
['def', 'time_to_channels(embedded_video):', 'video_shape', '=', 'shape_list(embedded_video)', 'if', 'len(video_shape)', '!=', '5:', 'raise', "ValueError('Assuming", 'videos', 'given', 'as', 'tensors', 'in', 'the', 'format', '[batch,', 'time,', 'height,', 'width,', 'channels]', 'but', 'got', 'one', 'of', 'shape:', "%s'...
965,342
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
make_even_size
make_even_size
Pad x to be even-sized on axis 1 and 2, but only if necessary.
[ "Pad", "x", "to", "be", "even-sized", "on", "axis", "1", "and", "2,", "but", "only", "if", "necessary." ]
def make_even_size(x): x_shape = x.get_shape().as_list() assert len(x_shape) > 2, 'Only 3+-dimensional tensors supported.' shape = [dim if dim is not None else -1 for dim in x_shape] new_shape = x_shape if x_shape[1] is not None: new_shape[1] = 2 * int(math.ceil(x_shape[1] * 0.5)) if x_s...
['def', 'make_even_size(x):', 'x_shape', '=', 'x.get_shape().as_list()', 'assert', 'len(x_shape)', '>', '2,', "'Only", '3+-dimensional', 'tensors', "supported.'", 'shape', '=', '[dim', 'if', 'dim', 'is', 'not', 'None', 'else', '-1', 'for', 'dim', 'in', 'x_shape]', 'new_shape', '=', 'x_shape', 'if', 'x_shape[1]', 'is', ...
965,344
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
single_discriminator
single_discriminator
A simple single-layer convolutional discriminator.
[ "A", "simple", "single-layer", "convolutional", "discriminator." ]
def single_discriminator(x, filters=128, kernel_size=7, strides=4, pure_mean=True): with tf.variable_scope('discriminator'): net = tf.layers.conv2d(x, filters, kernel_size, strides=strides, padding='SAME', name='conv1') if pure_mean: net = tf.reduce_mean(net, [1, 2]) else: ...
['def', 'single_discriminator(x,', 'filters=128,', 'kernel_size=7,', 'strides=4,', 'pure_mean=True):', 'with', "tf.variable_scope('discriminator'):", 'net', '=', 'tf.layers.conv2d(x,', 'filters,', 'kernel_size,', 'strides=strides,', "padding='SAME',", "name='conv1')", 'if', 'pure_mean:', 'net', '=', 'tf.reduce_mean(net...
965,348
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
double_discriminator
double_discriminator
A convolutional discriminator with 2 layers and concatenated output.
[ "A", "convolutional", "discriminator", "with", "2", "layers", "and", "concatenated", "output." ]
def double_discriminator(x, filters1=128, filters2=None, kernel_size=7, strides=4, pure_mean=True): if filters2 is None: filters2 = 4 * filters1 with tf.variable_scope('discriminator'): batch_size = shape_list(x)[0] net = tf.layers.conv2d(x, filters1, kernel_size, strides=strides, paddin...
['def', 'double_discriminator(x,', 'filters1=128,', 'filters2=None,', 'kernel_size=7,', 'strides=4,', 'pure_mean=True):', 'if', 'filters2', 'is', 'None:', 'filters2', '=', '4', '*', 'filters1', 'with', "tf.variable_scope('discriminator'):", 'batch_size', '=', 'shape_list(x)[0]', 'net', '=', 'tf.layers.conv2d(x,', 'filt...
965,349
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_layers.py
td_conv
td_conv
Apply targeted dropout to the weights of a convolution.
[ "Apply", "targeted", "dropout", "to", "the", "weights", "of", "a", "convolution." ]
def td_conv(inputs, filters, kernel_size, targeting_count, targeting_fn, keep_prob, is_training, do_prune=True, strides=(1, 1), padding='valid', data_format='channels_last', dilation_rate=(1, 1), activation=None, use_bias=True, kernel_initializer=None, bias_initializer=tf.zeros_initializer(), name=None, reuse=None): ...
['def', 'td_conv(inputs,', 'filters,', 'kernel_size,', 'targeting_count,', 'targeting_fn,', 'keep_prob,', 'is_training,', 'do_prune=True,', 'strides=(1,', '1),', "padding='valid',", "data_format='channels_last',", 'dilation_rate=(1,', '1),', 'activation=None,', 'use_bias=True,', 'kernel_initializer=None,', 'bias_initia...
965,352
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_message_passing_attention.py
make_edge_vectors
make_edge_vectors
Gets edge vectors for the edge types in the adjacency matrix.
[ "Gets", "edge", "vectors", "for", "the", "edge", "types", "in", "the", "adjacency", "matrix." ]
def make_edge_vectors(adjacency_matrix, num_edge_types, depth, name=None): with tf.variable_scope(name, default_name='edge_vectors'): att_adj_vectors_shape = [num_edge_types, depth] adjacency_matrix_shape = common_layers.shape_list(adjacency_matrix) adj_vectors = tf.get_variable('adj_vectors...
['def', 'make_edge_vectors(adjacency_matrix,', 'num_edge_types,', 'depth,', 'name=None):', 'with', 'tf.variable_scope(name,', "default_name='edge_vectors'):", 'att_adj_vectors_shape', '=', '[num_edge_types,', 'depth]', 'adjacency_matrix_shape', '=', 'common_layers.shape_list(adjacency_matrix)', 'adj_vectors', '=', "tf....
965,356
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_message_passing_attention.py
dense_message_pass
dense_message_pass
Computes a_t from h_{t-1}, see bottom of page 3 in the paper.
[ "Computes", "a_t", "from", "h_{t-1},", "see", "bottom", "of", "page", "3", "in", "the", "paper." ]
def dense_message_pass(node_states, edge_matrices): (batch_size, num_nodes, node_dim) = common_layers.shape_list(node_states) h_flat = tf.reshape(node_states, [batch_size, num_nodes * node_dim, 1], name='h_flat') messages = tf.reshape(tf.matmul(edge_matrices, h_flat), [batch_size * num_nodes, node_dim], nam...
['def', 'dense_message_pass(node_states,', 'edge_matrices):', '(batch_size,', 'num_nodes,', 'node_dim)', '=', 'common_layers.shape_list(node_states)', 'h_flat', '=', 'tf.reshape(node_states,', '[batch_size,', 'num_nodes', '*', 'node_dim,', '1],', "name='h_flat')", 'messages', '=', 'tf.reshape(tf.matmul(edge_matrices,',...
965,364
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_video.py
swap_time_and_batch_axes
swap_time_and_batch_axes
Swaps time and batch axis (the first two axis).
[ "Swaps", "time", "and", "batch", "axis", "(the", "first", "two", "axis)." ]
def swap_time_and_batch_axes(inputs): transposed_axes = tf.concat([[1, 0], tf.range(2, tf.rank(inputs))], axis=0) return tf.transpose(inputs, transposed_axes)
['def', 'swap_time_and_batch_axes(inputs):', 'transposed_axes', '=', 'tf.concat([[1,', '0],', 'tf.range(2,', 'tf.rank(inputs))],', 'axis=0)', 'return', 'tf.transpose(inputs,', 'transposed_axes)']
965,365
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_video.py
decode_to_shape
decode_to_shape
Encode the given tensor to given image shape.
[ "Encode", "the", "given", "tensor", "to", "given", "image", "shape." ]
def decode_to_shape(inputs, shape, scope): with tf.variable_scope(scope, reuse=tf.AUTO_REUSE): x = inputs x = tf.contrib.layers.flatten(x) x = tfl.dense(x, shape[2], activation=None, name='dec_dense') x = tf.expand_dims(x, axis=1) return x
['def', 'decode_to_shape(inputs,', 'shape,', 'scope):', 'with', 'tf.variable_scope(scope,', 'reuse=tf.AUTO_REUSE):', 'x', '=', 'inputs', 'x', '=', 'tf.contrib.layers.flatten(x)', 'x', '=', 'tfl.dense(x,', 'shape[2],', 'activation=None,', "name='dec_dense')", 'x', '=', 'tf.expand_dims(x,', 'axis=1)', 'return', 'x']
965,367
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
common_video.py
tile_and_concat
tile_and_concat
Tile latent and concatenate to image across depth.
[ "Tile", "latent", "and", "concatenate", "to", "image", "across", "depth." ]
def tile_and_concat(image, latent, concat_latent=True): if not concat_latent: return image image_shape = common_layers.shape_list(image) latent_shape = common_layers.shape_list(latent) (height, width) = (image_shape[1], image_shape[2]) latent_dims = latent_shape[1] height_multiples = hei...
['def', 'tile_and_concat(image,', 'latent,', 'concat_latent=True):', 'if', 'not', 'concat_latent:', 'return', 'image', 'image_shape', '=', 'common_layers.shape_list(image)', 'latent_shape', '=', 'common_layers.shape_list(latent)', '(height,', 'width)', '=', '(image_shape[1],', 'image_shape[2])', 'latent_dims', '=', 'la...
965,373
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
slice_hidden
slice_hidden
Slice encoder hidden state under num_blocks.
[ "Slice", "encoder", "hidden", "state", "under", "num_blocks." ]
def slice_hidden(x, hidden_size, num_blocks): (batch_size, latent_dim, _) = common_layers.shape_list(x) block_dim = hidden_size // num_blocks x_sliced = tf.reshape(x, shape=[batch_size, latent_dim, num_blocks, block_dim]) return x_sliced
['def', 'slice_hidden(x,', 'hidden_size,', 'num_blocks):', '(batch_size,', 'latent_dim,', '_)', '=', 'common_layers.shape_list(x)', 'block_dim', '=', 'hidden_size', '//', 'num_blocks', 'x_sliced', '=', 'tf.reshape(x,', 'shape=[batch_size,', 'latent_dim,', 'num_blocks,', 'block_dim])', 'return', 'x_sliced']
965,379
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
int_to_bit_embed
int_to_bit_embed
Turn x_int into a bitwise (lower-endian) tensor and embed densly.
[ "Turn", "x_int", "into", "a", "bitwise", "(lower-endian)", "tensor", "and", "embed", "densly." ]
def int_to_bit_embed(x_int, num_bits, embedding_size, base=2): shape = common_layers.shape_list(x_int) inputs = int_to_bit(x_int, num_bits, base=base) inputs = tf.reshape(inputs, shape[:-1] + [shape[-1] * 8]) inputs = 2.0 * tf.to_float(inputs) - 1.0 return tf.layers.dense(inputs, embedding_size, nam...
['def', 'int_to_bit_embed(x_int,', 'num_bits,', 'embedding_size,', 'base=2):', 'shape', '=', 'common_layers.shape_list(x_int)', 'inputs', '=', 'int_to_bit(x_int,', 'num_bits,', 'base=base)', 'inputs', '=', 'tf.reshape(inputs,', 'shape[:-1]', '+', '[shape[-1]', '*', '8])', 'inputs', '=', '2.0', '*', 'tf.to_float(inputs)...
965,384
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
vae
vae
Simple variational autoencoder without discretization.
[ "Simple", "variational", "autoencoder", "without", "discretization." ]
def vae(x, z_size, name=None): with tf.variable_scope(name, default_name='vae'): mu = tf.layers.dense(x, z_size, name='mu') log_sigma = tf.layers.dense(x, z_size, name='log_sigma') shape = common_layers.shape_list(x) epsilon = tf.random_normal([shape[0], shape[1], 1, z_size]) ...
['def', 'vae(x,', 'z_size,', 'name=None):', 'with', 'tf.variable_scope(name,', "default_name='vae'):", 'mu', '=', 'tf.layers.dense(x,', 'z_size,', "name='mu')", 'log_sigma', '=', 'tf.layers.dense(x,', 'z_size,', "name='log_sigma')", 'shape', '=', 'common_layers.shape_list(x)', 'epsilon', '=', 'tf.random_normal([shape[0...
965,386
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
gumbel_softmax
gumbel_softmax
Gumbel softmax discretization bottleneck.
[ "Gumbel", "softmax", "discretization", "bottleneck." ]
def gumbel_softmax(x, z_size, mode, softmax_k=0, temperature_warmup_steps=150000, summary=True, name=None): with tf.variable_scope(name, default_name='gumbel_softmax'): m = tf.layers.dense(x, 2 ** z_size, name='mask') if softmax_k > 0: (m, kl) = top_k_softmax(m, softmax_k) re...
['def', 'gumbel_softmax(x,', 'z_size,', 'mode,', 'softmax_k=0,', 'temperature_warmup_steps=150000,', 'summary=True,', 'name=None):', 'with', 'tf.variable_scope(name,', "default_name='gumbel_softmax'):", 'm', '=', 'tf.layers.dense(x,', '2', '**', 'z_size,', "name='mask')", 'if', 'softmax_k', '>', '0:', '(m,', 'kl)', '='...
965,389
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
vq_body
vq_body
Discretize each x into one of codebook_size codes.
[ "Discretize", "each", "x", "into", "one", "of", "codebook_size", "codes." ]
def vq_body(x, codebook_size, beta=0.25, decay=0.999, epsilon=1e-05, soft_em=False, num_samples=10, temperature=None, do_update=True): x_shape = common_layers.shape_list(x) hidden_size = x_shape[-1] (means, ema_means, ema_count) = get_vq_codebook(codebook_size, hidden_size) x = tf.reshape(x, [-1, hidden...
['def', 'vq_body(x,', 'codebook_size,', 'beta=0.25,', 'decay=0.999,', 'epsilon=1e-05,', 'soft_em=False,', 'num_samples=10,', 'temperature=None,', 'do_update=True):', 'x_shape', '=', 'common_layers.shape_list(x)', 'hidden_size', '=', 'x_shape[-1]', '(means,', 'ema_means,', 'ema_count)', '=', 'get_vq_codebook(codebook_si...
965,393
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
vq_loss
vq_loss
Compute the loss of large vocab tensors using a VQAE codebook.
[ "Compute", "the", "loss", "of", "large", "vocab", "tensors", "using", "a", "VQAE", "codebook." ]
def vq_loss(x, targets, codebook_size, beta=0.25, decay=0.999, epsilon=1e-05, soft_em=False, num_samples=10, temperature=None, do_update=True): x_shape = common_layers.shape_list(x) target_shape = common_layers.shape_list(targets) hidden_size = x_shape[-1] (means, _, _) = get_vq_codebook(codebook_size, ...
['def', 'vq_loss(x,', 'targets,', 'codebook_size,', 'beta=0.25,', 'decay=0.999,', 'epsilon=1e-05,', 'soft_em=False,', 'num_samples=10,', 'temperature=None,', 'do_update=True):', 'x_shape', '=', 'common_layers.shape_list(x)', 'target_shape', '=', 'common_layers.shape_list(targets)', 'hidden_size', '=', 'x_shape[-1]', '(...
965,394
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
gumbel_softmax_nearest_neighbor_dvq
gumbel_softmax_nearest_neighbor_dvq
Sample from Gumbel-Softmax and compute neighbors and losses.
[ "Sample", "from", "Gumbel-Softmax", "and", "compute", "neighbors", "and", "losses." ]
def gumbel_softmax_nearest_neighbor_dvq(x, means, block_v_size, hard=False, temperature_init=1.2, num_samples=1, temperature_warmup_steps=150000, summary=True, num_flows=0, approximate_gs_entropy=False, sum_over_latents=False): (batch_size, latent_dim, num_blocks, block_dim) = common_layers.shape_list(x) x = tf...
['def', 'gumbel_softmax_nearest_neighbor_dvq(x,', 'means,', 'block_v_size,', 'hard=False,', 'temperature_init=1.2,', 'num_samples=1,', 'temperature_warmup_steps=150000,', 'summary=True,', 'num_flows=0,', 'approximate_gs_entropy=False,', 'sum_over_latents=False):', '(batch_size,', 'latent_dim,', 'num_blocks,', 'block_di...
965,396
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
tanh_discrete_bottleneck
tanh_discrete_bottleneck
Simple discretization through tanh, flip bottleneck_noise many bits.
[ "Simple", "discretization", "through", "tanh,", "flip", "bottleneck_noise", "many", "bits." ]
def tanh_discrete_bottleneck(x, bottleneck_bits, bottleneck_noise, discretize_warmup_steps, mode): x = tf.tanh(tf.layers.dense(x, bottleneck_bits, name='tanh_discrete_bottleneck')) d = x + tf.stop_gradient(2.0 * tf.to_float(tf.less(0.0, x)) - 1.0 - x) if mode == tf.estimator.ModeKeys.TRAIN: noise = ...
['def', 'tanh_discrete_bottleneck(x,', 'bottleneck_bits,', 'bottleneck_noise,', 'discretize_warmup_steps,', 'mode):', 'x', '=', 'tf.tanh(tf.layers.dense(x,', 'bottleneck_bits,', "name='tanh_discrete_bottleneck'))", 'd', '=', 'x', '+', 'tf.stop_gradient(2.0', '*', 'tf.to_float(tf.less(0.0,', 'x))', '-', '1.0', '-', 'x)'...
965,398
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
tanh_discrete_unbottleneck
tanh_discrete_unbottleneck
Simple un-discretization from tanh.
[ "Simple", "un-discretization", "from", "tanh." ]
def tanh_discrete_unbottleneck(x, hidden_size): x = tf.layers.dense(x, hidden_size, name='tanh_discrete_unbottleneck') return x
['def', 'tanh_discrete_unbottleneck(x,', 'hidden_size):', 'x', '=', 'tf.layers.dense(x,', 'hidden_size,', "name='tanh_discrete_unbottleneck')", 'return', 'x']
965,399
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
parametrized_bottleneck
parametrized_bottleneck
Meta-function calling all the above bottlenecks with hparams.
[ "Meta-function", "calling", "all", "the", "above", "bottlenecks", "with", "hparams." ]
def parametrized_bottleneck(x, hparams): if hparams.bottleneck_kind == 'tanh_discrete': return tanh_discrete_bottleneck(x, hparams.bottleneck_bits, hparams.bottleneck_noise * 0.5, hparams.discretize_warmup_steps, hparams.mode) if hparams.bottleneck_kind == 'isemhash': return isemhash_bottleneck(...
['def', 'parametrized_bottleneck(x,', 'hparams):', 'if', 'hparams.bottleneck_kind', '==', "'tanh_discrete':", 'return', 'tanh_discrete_bottleneck(x,', 'hparams.bottleneck_bits,', 'hparams.bottleneck_noise', '*', '0.5,', 'hparams.discretize_warmup_steps,', 'hparams.mode)', 'if', 'hparams.bottleneck_kind', '==', "'isemha...
965,402
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
parametrized_unbottleneck
parametrized_unbottleneck
Meta-function calling all the above un-bottlenecks with hparams.
[ "Meta-function", "calling", "all", "the", "above", "un-bottlenecks", "with", "hparams." ]
def parametrized_unbottleneck(x, hidden_size, hparams): if hparams.bottleneck_kind == 'tanh_discrete': return tanh_discrete_unbottleneck(x, hidden_size) if hparams.bottleneck_kind == 'isemhash': return isemhash_unbottleneck(x, hidden_size, hparams.isemhash_filter_size_multiplier) if hparams....
['def', 'parametrized_unbottleneck(x,', 'hidden_size,', 'hparams):', 'if', 'hparams.bottleneck_kind', '==', "'tanh_discrete':", 'return', 'tanh_discrete_unbottleneck(x,', 'hidden_size)', 'if', 'hparams.bottleneck_kind', '==', "'isemhash':", 'return', 'isemhash_unbottleneck(x,', 'hidden_size,', 'hparams.isemhash_filter_...
965,403
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
discretization.py
iaf_hparams
iaf_hparams
Create hyperpameters for inverse autoregressive flows.
[ "Create", "hyperpameters", "for", "inverse", "autoregressive", "flows." ]
def iaf_hparams(hidden_size=512, filter_size=4096): hparams = common_hparams.basic_params1() hparams.hidden_size = hidden_size hparams.add_hparam('attention_key_channels', None) hparams.add_hparam('attention_value_channels', None) hparams.add_hparam('num_heads', 4) hparams.add_hparam('attention_...
['def', 'iaf_hparams(hidden_size=512,', 'filter_size=4096):', 'hparams', '=', 'common_hparams.basic_params1()', 'hparams.hidden_size', '=', 'hidden_size', "hparams.add_hparam('attention_key_channels',", 'None)', "hparams.add_hparam('attention_value_channels',", 'None)', "hparams.add_hparam('num_heads',", '4)', "hparams...
965,404
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
ae_latent_softmax
ae_latent_softmax
Latent prediction and loss.
[ "Latent", "prediction", "and", "loss." ]
def ae_latent_softmax(latents_pred, latents_discrete_hot, vocab_size, hparams): with tf.variable_scope('latent_logits'): latents_logits = tf.layers.dense(latents_pred, vocab_size, name='logits_dense') if hparams.logit_normalization: latents_logits *= tf.rsqrt(1e-08 + tf.reduce_mean(tf.sq...
['def', 'ae_latent_softmax(latents_pred,', 'latents_discrete_hot,', 'vocab_size,', 'hparams):', 'with', "tf.variable_scope('latent_logits'):", 'latents_logits', '=', 'tf.layers.dense(latents_pred,', 'vocab_size,', "name='logits_dense')", 'if', 'hparams.logit_normalization:', 'latents_logits', '*=', 'tf.rsqrt(1e-08', '+...
965,406
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
ae_latent_sample_beam
ae_latent_sample_beam
Samples from the latent space in the autoencoder.
[ "Samples", "from", "the", "latent", "space", "in", "the", "autoencoder." ]
def ae_latent_sample_beam(latents_dense_in, inputs, ed, embed, hparams): def symbols_to_logits_fn(ids): ids = tf.expand_dims(ids, axis=2) latents_discrete = tf.pad(ids[:, 1:], [[0, 0], [0, 1], [0, 0]]) with tf.variable_scope(tf.get_variable_scope(), reuse=False): latents_dense =...
['def', 'ae_latent_sample_beam(latents_dense_in,', 'inputs,', 'ed,', 'embed,', 'hparams):', 'def', 'symbols_to_logits_fn(ids):', 'ids', '=', 'tf.expand_dims(ids,', 'axis=2)', 'latents_discrete', '=', 'tf.pad(ids[:,', '1:],', '[[0,', '0],', '[0,', '1],', '[0,', '0]])', 'with', 'tf.variable_scope(tf.get_variable_scope(),...
965,407
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
compress_encoder_1d
compress_encoder_1d
Encoder that compresses 1-D inputs by 2**num_compress_steps.
[ "Encoder", "that", "compresses", "1-D", "inputs", "by", "2**num_compress_steps." ]
def compress_encoder_1d(x, hparams, name): x = tf.expand_dims(x, axis=2) return compress_encoder(x, hparams, strides=(2, 1), kernel=(hparams.kernel_size, 1), name=name)
['def', 'compress_encoder_1d(x,', 'hparams,', 'name):', 'x', '=', 'tf.expand_dims(x,', 'axis=2)', 'return', 'compress_encoder(x,', 'hparams,', 'strides=(2,', '1),', 'kernel=(hparams.kernel_size,', '1),', 'name=name)']
965,411
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
decompress_decoder_2d
decompress_decoder_2d
Decoder that decompresses 2-D inputs by 2**num_compress_steps.
[ "Decoder", "that", "decompresses", "2-D", "inputs", "by", "2**num_compress_steps." ]
def decompress_decoder_2d(x, hparams, name): return decompress_decoder(x, hparams, strides=(2, 2), kernel=(hparams.kernel_size, hparams.kernel_size), name=name)
['def', 'decompress_decoder_2d(x,', 'hparams,', 'name):', 'return', 'decompress_decoder(x,', 'hparams,', 'strides=(2,', '2),', 'kernel=(hparams.kernel_size,', 'hparams.kernel_size),', 'name=name)']
965,413
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
decompress_decoder_1d
decompress_decoder_1d
Decoder that decompresses 1-D inputs by 2**num_compress_steps.
[ "Decoder", "that", "decompresses", "1-D", "inputs", "by", "2**num_compress_steps." ]
def decompress_decoder_1d(x, hparams, name): x = tf.expand_dims(x, axis=2) output = decompress_decoder(x, hparams, strides=(2, 1), kernel=(hparams.kernel_size, 1), name=name) return tf.squeeze(output, axis=2)
['def', 'decompress_decoder_1d(x,', 'hparams,', 'name):', 'x', '=', 'tf.expand_dims(x,', 'axis=2)', 'output', '=', 'decompress_decoder(x,', 'hparams,', 'strides=(2,', '1),', 'kernel=(hparams.kernel_size,', '1),', 'name=name)', 'return', 'tf.squeeze(output,', 'axis=2)']
965,414
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
transformer_text_encoder
transformer_text_encoder
Transformer text encoder over inputs with unmasked full attention.
[ "Transformer", "text", "encoder", "over", "inputs", "with", "unmasked", "full", "attention." ]
def transformer_text_encoder(x, space_id, hparams, name='transformer_text_encoder'): with tf.variable_scope(name): x = common_layers.flatten4d3d(x) (encoder_input, encoder_self_attention_bias, ed) = transformer.transformer_prepare_encoder(x, space_id, hparams) encoder_input = tf.nn.dropout(e...
['def', 'transformer_text_encoder(x,', 'space_id,', 'hparams,', "name='transformer_text_encoder'):", 'with', 'tf.variable_scope(name):', 'x', '=', 'common_layers.flatten4d3d(x)', '(encoder_input,', 'encoder_self_attention_bias,', 'ed)', '=', 'transformer.transformer_prepare_encoder(x,', 'space_id,', 'hparams)', 'encode...
965,415
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
transformer_image_decoder
transformer_image_decoder
Transformer image decoder over inputs with local attention.
[ "Transformer", "image", "decoder", "over", "inputs", "with", "local", "attention." ]
def transformer_image_decoder(x, encoder_output, ed_attention_bias, hparams, name='transformer_dec'): with tf.variable_scope(name): batch_size = common_layers.shape_list(x)[0] targets = tf.reshape(x, [batch_size, hparams.img_len, hparams.img_len, hparams.num_channels * hparams.hidden_size]) ...
['def', 'transformer_image_decoder(x,', 'encoder_output,', 'ed_attention_bias,', 'hparams,', "name='transformer_dec'):", 'with', 'tf.variable_scope(name):', 'batch_size', '=', 'common_layers.shape_list(x)[0]', 'targets', '=', 'tf.reshape(x,', '[batch_size,', 'hparams.img_len,', 'hparams.img_len,', 'hparams.num_channels...
965,416
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
transformer_latent_decoder
transformer_latent_decoder
Transformer decoder over latents using latent_attention_type.
[ "Transformer", "decoder", "over", "latents", "using", "latent_attention_type." ]
def transformer_latent_decoder(x, encoder_output, ed_attention_bias, hparams, name='transformer_latent_dec'): with tf.variable_scope(name): batch_size = common_layers.shape_list(x)[0] compressed_img_len = hparams.img_len / 2 ** (hparams.num_compress_steps // 2) x = tf.reshape(x, [batch_size,...
['def', 'transformer_latent_decoder(x,', 'encoder_output,', 'ed_attention_bias,', 'hparams,', "name='transformer_latent_dec'):", 'with', 'tf.variable_scope(name):', 'batch_size', '=', 'common_layers.shape_list(x)[0]', 'compressed_img_len', '=', 'hparams.img_len', '/', '2', '**', '(hparams.num_compress_steps', '//', '2)...
965,417
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
latent_layers.py
transformer_autoencoder
transformer_autoencoder
Auto-encoder using transformer decoder and prior over latents.
[ "Auto-encoder", "using", "transformer", "decoder", "and", "prior", "over", "latents." ]
def transformer_autoencoder(inputs, targets, target_space, hparams, cache=None, predict_mask=1.0): losses = {'extra': 0.0, 'latent_pred': 0.0} original_targets_shape = common_layers.shape_list(targets) batch_size = original_targets_shape[0] if len(original_targets_shape) == 4: compress_fn = comp...
['def', 'transformer_autoencoder(inputs,', 'targets,', 'target_space,', 'hparams,', 'cache=None,', 'predict_mask=1.0):', 'losses', '=', "{'extra':", '0.0,', "'latent_pred':", '0.0}', 'original_targets_shape', '=', 'common_layers.shape_list(targets)', 'batch_size', '=', 'original_targets_shape[0]', 'if', 'len(original_t...
965,420
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
modalities.py
ImageChannelEmbeddingsBottom.get_channel_embeddings
get_channel_embeddings
Get separate embedding for each of the channels.
[ "Get", "separate", "embedding", "for", "each", "of", "the", "channels." ]
def get_channel_embeddings(self, io_depth, targets, hidden_size, name='channel'): targets_split = tf.split(targets, io_depth, axis=3) rgb_embedding_var = tf.get_variable('rgb_target_emb_%s' % name, [256 * io_depth, hidden_size]) rgb_embedding_var = tf.identity(rgb_embedding_var) rgb_embedding_var *= flo...
['def', 'get_channel_embeddings(self,', 'io_depth,', 'targets,', 'hidden_size,', "name='channel'):", 'targets_split', '=', 'tf.split(targets,', 'io_depth,', 'axis=3)', 'rgb_embedding_var', '=', "tf.get_variable('rgb_target_emb_%s'", '%', 'name,', '[256', '*', 'io_depth,', 'hidden_size])', 'rgb_embedding_var', '=', 'tf....
965,425
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
modalities.py
VideoModalityL2Raw.convert_rgb_to_real
convert_rgb_to_real
Convert prediction and target from rgb to real.
[ "Convert", "prediction", "and", "target", "from", "rgb", "to", "real." ]
def convert_rgb_to_real(self, prediction, targets): prediction = tf.squeeze(prediction, axis=-1) prediction = common_layers.convert_rgb_to_real(prediction) targets = common_layers.convert_rgb_to_real(targets) return (prediction, targets)
['def', 'convert_rgb_to_real(self,', 'prediction,', 'targets):', 'prediction', '=', 'tf.squeeze(prediction,', 'axis=-1)', 'prediction', '=', 'common_layers.convert_rgb_to_real(prediction)', 'targets', '=', 'common_layers.convert_rgb_to_real(targets)', 'return', '(prediction,', 'targets)']
965,430
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
modalities.py
OneHotClassLabelModality.loss
loss
Apply softmax cross-entropy between outputs and targets.
[ "Apply", "softmax", "cross-entropy", "between", "outputs", "and", "targets." ]
def loss(self, top_out, targets): loss_scale = tf.losses.softmax_cross_entropy(onehot_labels=targets, logits=top_out) weights = self.targets_weights_fn(targets) loss_denom = tf.reduce_sum(weights) return (loss_scale, loss_denom)
['def', 'loss(self,', 'top_out,', 'targets):', 'loss_scale', '=', 'tf.losses.softmax_cross_entropy(onehot_labels=targets,', 'logits=top_out)', 'weights', '=', 'self.targets_weights_fn(targets)', 'loss_denom', '=', 'tf.reduce_sum(weights)', 'return', '(loss_scale,', 'loss_denom)']
965,434
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
modalities.py
IdentitySymbolModality.targets_bottom
targets_bottom
SymbolModality overrides targets_bottom, so need to override here too.
[ "SymbolModality", "overrides", "targets_bottom,", "so", "need", "to", "override", "here", "too." ]
def targets_bottom(self, x): return self.bottom(x)
['def', 'targets_bottom(self,', 'x):', 'return', 'self.bottom(x)']
965,435
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
vqa_layers.py
image_embedding
image_embedding
Extract image features from pretrained resnet model.
[ "Extract", "image", "features", "from", "pretrained", "resnet", "model." ]
def image_embedding(images, model_fn=resnet_v1_152, trainable=True, is_training=True, weight_decay=0.0001, batch_norm_decay=0.997, batch_norm_epsilon=1e-05, batch_norm_scale=True, add_summaries=False, reuse=False): is_resnet_training = trainable and is_training batch_norm_params = {'is_training': is_resnet_trai...
['def', 'image_embedding(images,', 'model_fn=resnet_v1_152,', 'trainable=True,', 'is_training=True,', 'weight_decay=0.0001,', 'batch_norm_decay=0.997,', 'batch_norm_epsilon=1e-05,', 'batch_norm_scale=True,', 'add_summaries=False,', 'reuse=False):', 'is_resnet_training', '=', 'trainable', 'and', 'is_training', 'batch_no...
965,437
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
convert_to_dimension
convert_to_dimension
Converts input to a Dimension.
[ "Converts", "input", "to", "a", "Dimension." ]
def convert_to_dimension(d): if d is None: return None if isinstance(d, Dimension): return d (name, size) = d if isinstance(name, str) and isinstance(size, int): return Dimension(name, size) else: raise ValueError('could not convert %s to Dimension' % (d,))
['def', 'convert_to_dimension(d):', 'if', 'd', 'is', 'None:', 'return', 'None', 'if', 'isinstance(d,', 'Dimension):', 'return', 'd', '(name,', 'size)', '=', 'd', 'if', 'isinstance(name,', 'str)', 'and', 'isinstance(size,', 'int):', 'return', 'Dimension(name,', 'size)', 'else:', 'raise', "ValueError('could", 'not', 'con...
965,446
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
convert_to_shape
convert_to_shape
Converts input to a Shape.
[ "Converts", "input", "to", "a", "Shape." ]
def convert_to_shape(x): if x is None: return None if isinstance(x, Shape): return x if isinstance(x, str): x = _parse_string_to_list_of_pairs(x, seconds_to_int=True) return Shape(x)
['def', 'convert_to_shape(x):', 'if', 'x', 'is', 'None:', 'return', 'None', 'if', 'isinstance(x,', 'Shape):', 'return', 'x', 'if', 'isinstance(x,', 'str):', 'x', '=', '_parse_string_to_list_of_pairs(x,', 'seconds_to_int=True)', 'return', 'Shape(x)']
965,447
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
convert_to_layout_rules
convert_to_layout_rules
Converts input to a LayoutRules.
[ "Converts", "input", "to", "a", "LayoutRules." ]
def convert_to_layout_rules(x): if isinstance(x, LayoutRules): return x if isinstance(x, str): x = _parse_string_to_list_of_pairs(x) return LayoutRules(x)
['def', 'convert_to_layout_rules(x):', 'if', 'isinstance(x,', 'LayoutRules):', 'return', 'x', 'if', 'isinstance(x,', 'str):', 'x', '=', '_parse_string_to_list_of_pairs(x)', 'return', 'LayoutRules(x)']
965,448
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
convert_args_to_laid_out_tensors
convert_args_to_laid_out_tensors
Convert list elements to laid-out-tensors when possible.
[ "Convert", "list", "elements", "to", "laid-out-tensors", "when", "possible." ]
def convert_args_to_laid_out_tensors(xs): ret = [] for x in xs: try: ret.append(x.to_laid_out_tensor()) except AttributeError: ret.append(x) return ret
['def', 'convert_args_to_laid_out_tensors(xs):', 'ret', '=', '[]', 'for', 'x', 'in', 'xs:', 'try:', 'ret.append(x.to_laid_out_tensor())', 'except', 'AttributeError:', 'ret.append(x)', 'return', 'ret']
965,449
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
cwise
cwise
Component-wise operation with no broadcasting.
[ "Component-wise", "operation", "with", "no", "broadcasting." ]
def cwise(tf_fn, xs, output_dtype=None, grad_function=None, name=None): return slicewise(tf_fn, xs, output_dtype=output_dtype, splittable_dims=xs[0].shape.dims, grad_function=grad_function, name=name or 'cwise')
['def', 'cwise(tf_fn,', 'xs,', 'output_dtype=None,', 'grad_function=None,', 'name=None):', 'return', 'slicewise(tf_fn,', 'xs,', 'output_dtype=output_dtype,', 'splittable_dims=xs[0].shape.dims,', 'grad_function=grad_function,', 'name=name', 'or', "'cwise')"]
965,451
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
binary_arguments_to_tensors
binary_arguments_to_tensors
Convert argument of a binary operation to Tensors.
[ "Convert", "argument", "of", "a", "binary", "operation", "to", "Tensors." ]
def binary_arguments_to_tensors(x1, x2): if not isinstance(x1, Tensor) and (not isinstance(x2, Tensor)): raise ValueError('at least one of x1 and x2 must be an mtf Tensor') elif isinstance(x1, Tensor) and isinstance(x2, Tensor): return (x1, x2) elif isinstance(x1, Tensor): return (x1...
['def', 'binary_arguments_to_tensors(x1,', 'x2):', 'if', 'not', 'isinstance(x1,', 'Tensor)', 'and', '(not', 'isinstance(x2,', 'Tensor)):', 'raise', "ValueError('at", 'least', 'one', 'of', 'x1', 'and', 'x2', 'must', 'be', 'an', 'mtf', "Tensor')", 'elif', 'isinstance(x1,', 'Tensor)', 'and', 'isinstance(x2,', 'Tensor):', ...
965,452
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
minimum
minimum
Binary minimum with broadcsting.
[ "Binary", "minimum", "with", "broadcsting." ]
def minimum(x1, x2, output_shape=None, name=None): output_shape = convert_to_shape(output_shape) with tf.name_scope(name, default_name='minimum'): (x1, x2) = binary_arguments_to_tensors(x1, x2) return MinMaxOperation(tf.minimum, x1, x2, output_shape=_infer_binary_broadcast_shape(x1.shape, x2.sha...
['def', 'minimum(x1,', 'x2,', 'output_shape=None,', 'name=None):', 'output_shape', '=', 'convert_to_shape(output_shape)', 'with', 'tf.name_scope(name,', "default_name='minimum'):", '(x1,', 'x2)', '=', 'binary_arguments_to_tensors(x1,', 'x2)', 'return', 'MinMaxOperation(tf.minimum,', 'x1,', 'x2,', 'output_shape=_infer_b...
965,453
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
maximum
maximum
Binary maximum with broadcsting.
[ "Binary", "maximum", "with", "broadcsting." ]
def maximum(x1, x2, output_shape=None, name=None): output_shape = convert_to_shape(output_shape) with tf.name_scope(name, default_name='maximum'): (x1, x2) = binary_arguments_to_tensors(x1, x2) return MinMaxOperation(tf.maximum, x1, x2, output_shape=_infer_binary_broadcast_shape(x1.shape, x2.sha...
['def', 'maximum(x1,', 'x2,', 'output_shape=None,', 'name=None):', 'output_shape', '=', 'convert_to_shape(output_shape)', 'with', 'tf.name_scope(name,', "default_name='maximum'):", '(x1,', 'x2)', '=', 'binary_arguments_to_tensors(x1,', 'x2)', 'return', 'MinMaxOperation(tf.maximum,', 'x1,', 'x2,', 'output_shape=_infer_b...
965,454
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
stack
stack
Stack multiple Tensors to make a new dimension.
[ "Stack", "multiple", "Tensors", "to", "make", "a", "new", "dimension." ]
def stack(xs, dim_name, axis, name=None): ret = StackOperation(xs, dim_name, axis, name).outputs[0] return ret
['def', 'stack(xs,', 'dim_name,', 'axis,', 'name=None):', 'ret', '=', 'StackOperation(xs,', 'dim_name,', 'axis,', 'name).outputs[0]', 'return', 'ret']
965,456
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
unstack
unstack
Split into multiple Tensors, eliminating a dimension.
[ "Split", "into", "multiple", "Tensors,", "eliminating", "a", "dimension." ]
def unstack(x, dim, name=None): return UnstackOperation(x, dim, name).outputs
['def', 'unstack(x,', 'dim,', 'name=None):', 'return', 'UnstackOperation(x,', 'dim,', 'name).outputs']
965,457
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
assign
assign
Assign a new value to a variable.
[ "Assign", "a", "new", "value", "to", "a", "variable." ]
def assign(var, new_val): if isinstance(var, Tensor): var = var.operation if not isinstance(var, Variable): raise ValueError('var must be a mtf.Variable or its output Tensor.') return Assign(var, new_val)
['def', 'assign(var,', 'new_val):', 'if', 'isinstance(var,', 'Tensor):', 'var', '=', 'var.operation', 'if', 'not', 'isinstance(var,', 'Variable):', 'raise', "ValueError('var", 'must', 'be', 'a', 'mtf.Variable', 'or', 'its', 'output', "Tensor.')", 'return', 'Assign(var,', 'new_val)']
965,459
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
depend
depend
Identity of Tensor x that dependes on operations dependencies.
[ "Identity", "of", "Tensor", "x", "that", "dependes", "on", "operations", "dependencies." ]
def depend(x, dependencies): return Depend(x, dependencies).outputs[0]
['def', 'depend(x,', 'dependencies):', 'return', 'Depend(x,', 'dependencies).outputs[0]']
965,460
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
reduce_max
reduce_max
Reduction on 1 or more axes.
[ "Reduction", "on", "1", "or", "more", "axes." ]
def reduce_max(x, disable_positional_args=None, output_shape=None, reduced_dim=None, name=None): output_shape = convert_to_shape(output_shape) reduced_dim = convert_to_dimension(reduced_dim) assert disable_positional_args is None output_shape = _reduction_output_shape(x, output_shape, reduced_dim) i...
['def', 'reduce_max(x,', 'disable_positional_args=None,', 'output_shape=None,', 'reduced_dim=None,', 'name=None):', 'output_shape', '=', 'convert_to_shape(output_shape)', 'reduced_dim', '=', 'convert_to_dimension(reduced_dim)', 'assert', 'disable_positional_args', 'is', 'None', 'output_shape', '=', '_reduction_output_s...
965,465
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
add
add
Binary addition with broadcsting.
[ "Binary", "addition", "with", "broadcsting." ]
def add(x1, x2, output_shape=None, name=None): output_shape = convert_to_shape(output_shape) if not isinstance(x2, Tensor): return ScalarAddOperation(x1, x2).outputs[0] with tf.name_scope(name, default_name='add'): (x1, x2) = binary_arguments_to_tensors(x1, x2) return AddOperation(x1...
['def', 'add(x1,', 'x2,', 'output_shape=None,', 'name=None):', 'output_shape', '=', 'convert_to_shape(output_shape)', 'if', 'not', 'isinstance(x2,', 'Tensor):', 'return', 'ScalarAddOperation(x1,', 'x2).outputs[0]', 'with', 'tf.name_scope(name,', "default_name='add'):", '(x1,', 'x2)', '=', 'binary_arguments_to_tensors(x...
965,468
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
sub
sub
Binary subtraction with broadcsting.
[ "Binary", "subtraction", "with", "broadcsting." ]
def sub(x1, x2, output_shape=None, name=None): output_shape = convert_to_shape(output_shape) if not isinstance(x2, Tensor): return ScalarAddOperation(x1, -x2).outputs[0] with tf.name_scope(name, default_name='sub'): (x1, x2) = binary_arguments_to_tensors(x1, x2) return add(x1, negati...
['def', 'sub(x1,', 'x2,', 'output_shape=None,', 'name=None):', 'output_shape', '=', 'convert_to_shape(output_shape)', 'if', 'not', 'isinstance(x2,', 'Tensor):', 'return', 'ScalarAddOperation(x1,', '-x2).outputs[0]', 'with', 'tf.name_scope(name,', "default_name='sub'):", '(x1,', 'x2)', '=', 'binary_arguments_to_tensors(...
965,469
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
multiply
multiply
Binary multiplication with broadcsting.
[ "Binary", "multiplication", "with", "broadcsting." ]
def multiply(x1, x2, output_shape=None, name=None): if not isinstance(x2, Tensor): return ScalarMultiplyOperation(x1, x2).outputs[0] with tf.name_scope(name, default_name='mul'): (x1, x2) = binary_arguments_to_tensors(x1, x2) return einsum([x1, x2], output_shape=_infer_binary_broadcast_s...
['def', 'multiply(x1,', 'x2,', 'output_shape=None,', 'name=None):', 'if', 'not', 'isinstance(x2,', 'Tensor):', 'return', 'ScalarMultiplyOperation(x1,', 'x2).outputs[0]', 'with', 'tf.name_scope(name,', "default_name='mul'):", '(x1,', 'x2)', '=', 'binary_arguments_to_tensors(x1,', 'x2)', 'return', 'einsum([x1,', 'x2],', ...
965,470
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
divide
divide
Binary division with broadcsting.
[ "Binary", "division", "with", "broadcsting." ]
def divide(x1, x2, output_shape=None, name=None): output_shape = convert_to_shape(output_shape) if not isinstance(x2, Tensor): return ScalarMultiplyOperation(x1, 1.0 / x2).outputs[0] with tf.name_scope(name, default_name='divide'): (x1, x2) = binary_arguments_to_tensors(x1, x2) retur...
['def', 'divide(x1,', 'x2,', 'output_shape=None,', 'name=None):', 'output_shape', '=', 'convert_to_shape(output_shape)', 'if', 'not', 'isinstance(x2,', 'Tensor):', 'return', 'ScalarMultiplyOperation(x1,', '1.0', '/', 'x2).outputs[0]', 'with', 'tf.name_scope(name,', "default_name='divide'):", '(x1,', 'x2)', '=', 'binary...
965,471
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
gather
gather
Shorthand for einsum([one_hot(indices, dim)], weights).
[ "Shorthand", "for", "einsum([one_hot(indices,", "dim)],", "weights)." ]
def gather(weights, indices, dim, output_shape=None): dim = convert_to_dimension(dim) output_shape = convert_to_shape(output_shape) if weights.dtype == tf.bool: return cast(gather(to_float(weights), indices, dim, output_shape), tf.bool) return einsum([one_hot(indices, dim, dtype=weights.dtype), ...
['def', 'gather(weights,', 'indices,', 'dim,', 'output_shape=None):', 'dim', '=', 'convert_to_dimension(dim)', 'output_shape', '=', 'convert_to_shape(output_shape)', 'if', 'weights.dtype', '==', 'tf.bool:', 'return', 'cast(gather(to_float(weights),', 'indices,', 'dim,', 'output_shape),', 'tf.bool)', 'return', 'einsum([...
965,472
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
gradients
gradients
Compute gradients in dtf.
[ "Compute", "gradients", "in", "dtf." ]
def gradients(ys, xs, grad_ys=None): graph = ys[0].graph if not grad_ys: grad_ys = [Constant(y.mesh, 1.0, y.shape, y.dtype).outputs[0] for y in ys] downstream = set(xs) for op in graph.operations: if op.has_gradient: if set(op.inputs) & downstream: downstream ...
['def', 'gradients(ys,', 'xs,', 'grad_ys=None):', 'graph', '=', 'ys[0].graph', 'if', 'not', 'grad_ys:', 'grad_ys', '=', '[Constant(y.mesh,', '1.0,', 'y.shape,', 'y.dtype).outputs[0]', 'for', 'y', 'in', 'ys]', 'downstream', '=', 'set(xs)', 'for', 'op', 'in', 'graph.operations:', 'if', 'op.has_gradient:', 'if', 'set(op.i...
965,473
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
is_subsequence
is_subsequence
Is short_seq a subsequence of long_seq.
[ "Is", "short_seq", "a", "subsequence", "of", "long_seq." ]
def is_subsequence(short_seq, long_seq): if not short_seq: return True pos = 0 for x in long_seq: if pos == len(short_seq): return True if short_seq[pos] == x: pos += 1 if pos == len(short_seq): return True return False
['def', 'is_subsequence(short_seq,', 'long_seq):', 'if', 'not', 'short_seq:', 'return', 'True', 'pos', '=', '0', 'for', 'x', 'in', 'long_seq:', 'if', 'pos', '==', 'len(short_seq):', 'return', 'True', 'if', 'short_seq[pos]', '==', 'x:', 'pos', '+=', '1', 'if', 'pos', '==', 'len(short_seq):', 'return', 'True', 'return', ...
965,474
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
pnum_to_processor_coordinates
pnum_to_processor_coordinates
Coordinates of a processor in the mesh.
[ "Coordinates", "of", "a", "processor", "in", "the", "mesh." ]
def pnum_to_processor_coordinates(mesh_shape, pnum): ret = [] for dimsize in mesh_shape.to_integer_list[::-1]: ret.append(pnum % dimsize) pnum //= dimsize return ret[::-1]
['def', 'pnum_to_processor_coordinates(mesh_shape,', 'pnum):', 'ret', '=', '[]', 'for', 'dimsize', 'in', 'mesh_shape.to_integer_list[::-1]:', 'ret.append(pnum', '%', 'dimsize)', 'pnum', '//=', 'dimsize', 'return', 'ret[::-1]']
965,476
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
log_variable_sizes
log_variable_sizes
Log the sizes and shapes of variables, and the total size.
[ "Log", "the", "sizes", "and", "shapes", "of", "variables,", "and", "the", "total", "size." ]
def log_variable_sizes(var_list, tag, verbose=True): if not var_list: return name_to_var = {v.name: v for v in var_list} total_size = 0 for v_name in sorted(list(name_to_var)): v = name_to_var[v_name] v_size = v.shape.size if verbose: tf.logging.info('Weight ...
['def', 'log_variable_sizes(var_list,', 'tag,', 'verbose=True):', 'if', 'not', 'var_list:', 'return', 'name_to_var', '=', '{v.name:', 'v', 'for', 'v', 'in', 'var_list}', 'total_size', '=', '0', 'for', 'v_name', 'in', 'sorted(list(name_to_var)):', 'v', '=', 'name_to_var[v_name]', 'v_size', '=', 'v.shape.size', 'if', 've...
965,483
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
Shape.rename_dimension
rename_dimension
Returns a copy where one dimension is renamed.
[ "Returns", "a", "copy", "where", "one", "dimension", "is", "renamed." ]
def rename_dimension(self, old_name, new_name): if old_name not in self.dimension_names: raise ValueError('Shape %s does not have dimension named %s' % (self, old_name)) return Shape([Dimension(new_name, d.size) if d.name == old_name else d for d in self.dims])
['def', 'rename_dimension(self,', 'old_name,', 'new_name):', 'if', 'old_name', 'not', 'in', 'self.dimension_names:', 'raise', "ValueError('Shape", '%s', 'does', 'not', 'have', 'dimension', 'named', "%s'", '%', '(self,', 'old_name))', 'return', 'Shape([Dimension(new_name,', 'd.size)', 'if', 'd.name', '==', 'old_name', '...
965,489
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
LayoutRules.tensor_dimension_to_mesh_axis
tensor_dimension_to_mesh_axis
Mesh axis associated with tensor dimension (or None).
[ "Mesh", "axis", "associated", "with", "tensor", "dimension", "(or", "None)." ]
def tensor_dimension_to_mesh_axis(self, tensor_dimension, mesh_shape): val = [i for (i, mesh_dimension) in enumerate(mesh_shape) if (tensor_dimension.name, mesh_dimension.name) in self._pairs] if len(val) > 1: raise ValueError('Tensor dimension maps to multiple mesh dimensions tensor_dimension=%s mesh_s...
['def', 'tensor_dimension_to_mesh_axis(self,', 'tensor_dimension,', 'mesh_shape):', 'val', '=', '[i', 'for', '(i,', 'mesh_dimension)', 'in', 'enumerate(mesh_shape)', 'if', '(tensor_dimension.name,', 'mesh_dimension.name)', 'in', 'self._pairs]', 'if', 'len(val)', '>', '1:', 'raise', "ValueError('Tensor", 'dimension', 'm...
965,491
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
TensorLayout.is_fully_replicated
is_fully_replicated
Whether all tensor dimensions map to None.
[ "Whether", "all", "tensor", "dimensions", "map", "to", "None." ]
def is_fully_replicated(self): return self.tensor_axis_to_mesh_axis == (None,) * len(self)
['def', 'is_fully_replicated(self):', 'return', 'self.tensor_axis_to_mesh_axis', '==', '(None,)', '*', 'len(self)']
965,494
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
Lowering.laid_out_size
laid_out_size
Total size of all slices.
[ "Total", "size", "of", "all", "slices." ]
def laid_out_size(self, tensor): return self.mesh_impl(tensor).laid_out_size(tensor.shape)
['def', 'laid_out_size(self,', 'tensor):', 'return', 'self.mesh_impl(tensor).laid_out_size(tensor.shape)']
965,497
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
MeshImpl.tensor_layout
tensor_layout
Compute TensorLayout for a Tensor or a Shape.
[ "Compute", "TensorLayout", "for", "a", "Tensor", "or", "a", "Shape." ]
def tensor_layout(self, arg): if isinstance(arg, Tensor): arg = arg.shape return self.layout_rules.tensor_layout(arg, self.shape)
['def', 'tensor_layout(self,', 'arg):', 'if', 'isinstance(arg,', 'Tensor):', 'arg', '=', 'arg.shape', 'return', 'self.layout_rules.tensor_layout(arg,', 'self.shape)']
965,499
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
MeshImpl.slicewise
slicewise
Executes a function in parallel on all slices.
[ "Executes", "a", "function", "in", "parallel", "on", "all", "slices." ]
def slicewise(self, fn, *inputs): raise NotImplementedError('Slicewise not implemented')
['def', 'slicewise(self,', 'fn,', '*inputs):', 'raise', "NotImplementedError('Slicewise", 'not', "implemented')"]
965,504
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
MeshImpl.shift_by_n_processors
shift_by_n_processors
Receive the slice from processor pcoord - offset.
[ "Receive", "the", "slice", "from", "processor", "pcoord", "-", "offset." ]
def shift_by_n_processors(self, x, mesh_axis, offset, wrap): n = self.shape[mesh_axis].size source_pcoord = [] for i in xrange(n): c = i - offset if c != c % n: if wrap: c = c % n else: c = None source_pcoord.append(c) retur...
['def', 'shift_by_n_processors(self,', 'x,', 'mesh_axis,', 'offset,', 'wrap):', 'n', '=', 'self.shape[mesh_axis].size', 'source_pcoord', '=', '[]', 'for', 'i', 'in', 'xrange(n):', 'c', '=', 'i', '-', 'offset', 'if', 'c', '!=', 'c', '%', 'n:', 'if', 'wrap:', 'c', '=', 'c', '%', 'n', 'else:', 'c', '=', 'None', 'source_pc...
965,510
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
MeshImpl.laid_out_pcoord
laid_out_pcoord
Returns a LaidOutTensor containing the processor coordinate.
[ "Returns", "a", "LaidOutTensor", "containing", "the", "processor", "coordinate." ]
def laid_out_pcoord(self, mesh_axis): divisor = list_product(self.shape.to_integer_list[mesh_axis + 1:]) modulus = self.shape[mesh_axis].size def my_fn(pnum): return pnum // divisor % modulus return self.slicewise(my_fn, self.laid_out_pnum())
['def', 'laid_out_pcoord(self,', 'mesh_axis):', 'divisor', '=', 'list_product(self.shape.to_integer_list[mesh_axis', '+', '1:])', 'modulus', '=', 'self.shape[mesh_axis].size', 'def', 'my_fn(pnum):', 'return', 'pnum', '//', 'divisor', '%', 'modulus', 'return', 'self.slicewise(my_fn,', 'self.laid_out_pnum())']
965,512
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
MeshImpl.broadcast_impl
broadcast_impl
Implementation of a broadcast operation.
[ "Implementation", "of", "a", "broadcast", "operation." ]
def broadcast_impl(self, old_slices, old_shape, new_shape): new_slice_shape = self.slice_shape(new_shape) def tf_fn(x): return tf.zeros(new_slice_shape, dtype=x.dtype) + _expand_dims(x, old_shape, new_shape) return self.slicewise(tf_fn, old_slices)
['def', 'broadcast_impl(self,', 'old_slices,', 'old_shape,', 'new_shape):', 'new_slice_shape', '=', 'self.slice_shape(new_shape)', 'def', 'tf_fn(x):', 'return', 'tf.zeros(new_slice_shape,', 'dtype=x.dtype)', '+', '_expand_dims(x,', 'old_shape,', 'new_shape)', 'return', 'self.slicewise(tf_fn,', 'old_slices)']
965,513
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mesh_tensorflow.py
MeshImpl.combine_slices
combine_slices
Turns a set of slices into a single tensor.
[ "Turns", "a", "set", "of", "slices", "into", "a", "single", "tensor." ]
def combine_slices(self, slices, tensor_shape, device=None): if tensor_shape.ndims == 0: return slices[0] ret = slices[:] tensor_layout = self.tensor_layout(tensor_shape) for (mesh_dim, tensor_axis) in zip(self.shape, tensor_layout.mesh_axis_to_tensor_axis(self.ndims)): slice_size = len(...
['def', 'combine_slices(self,', 'slices,', 'tensor_shape,', 'device=None):', 'if', 'tensor_shape.ndims', '==', '0:', 'return', 'slices[0]', 'ret', '=', 'slices[:]', 'tensor_layout', '=', 'self.tensor_layout(tensor_shape)', 'for', '(mesh_dim,', 'tensor_axis)', 'in', 'zip(self.shape,', 'tensor_layout.mesh_axis_to_tensor_...
965,515
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mtf_image_transformer.py
mtf_image_transformer_base_imagenet_mp
mtf_image_transformer_base_imagenet_mp
Model parallel ImageNet parameters.
[ "Model", "parallel", "ImageNet", "parameters." ]
def mtf_image_transformer_base_imagenet_mp(): hparams = mtf_image_transformer_base_imagenet() hparams.mesh_shape = 'model:4;batch:8' hparams.layout = 'batch:batch;d_ff:model;heads:model' hparams.batch_size = 32 hparams.num_heads = 4 hparams.d_ff = 8192 hparams.learning_rate_warmup_steps = 60...
['def', 'mtf_image_transformer_base_imagenet_mp():', 'hparams', '=', 'mtf_image_transformer_base_imagenet()', 'hparams.mesh_shape', '=', "'model:4;batch:8'", 'hparams.layout', '=', "'batch:batch;d_ff:model;heads:model'", 'hparams.batch_size', '=', '32', 'hparams.num_heads', '=', '4', 'hparams.d_ff', '=', '8192', 'hpara...
965,531
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mtf_layers.py
dense
dense
Dense layer doing (kernel*x + bias) computation.
[ "Dense", "layer", "doing", "(kernel*x", "+", "bias)", "computation." ]
def dense(x, output_dim, reduced_dims=None, expert_dims=None, use_bias=True, activation=None, name=None): if expert_dims is None: expert_dims = [] if reduced_dims is None: reduced_dims = x.shape.dims[-1:] w_shape = mtf.Shape(expert_dims + reduced_dims + [output_dim]) output_shape = mtf.S...
['def', 'dense(x,', 'output_dim,', 'reduced_dims=None,', 'expert_dims=None,', 'use_bias=True,', 'activation=None,', 'name=None):', 'if', 'expert_dims', 'is', 'None:', 'expert_dims', '=', '[]', 'if', 'reduced_dims', 'is', 'None:', 'reduced_dims', '=', 'x.shape.dims[-1:]', 'w_shape', '=', 'mtf.Shape(expert_dims', '+', 'r...
965,533
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mtf_layers.py
layer_norm
layer_norm
Layer normalization over dimension dim.
[ "Layer", "normalization", "over", "dimension", "dim." ]
def layer_norm(x, dim, epsilon=1e-06, name='layer_prepostprocess'): with tf.variable_scope(name + '/layer_norm'): scale = mtf.get_variable(x.mesh, 'layer_norm_scale', mtf.Shape([dim]), initializer=tf.ones_initializer(), activation_dtype=x.dtype) bias = mtf.get_variable(x.mesh, 'layer_norm_bias', mtf...
['def', 'layer_norm(x,', 'dim,', 'epsilon=1e-06,', "name='layer_prepostprocess'):", 'with', 'tf.variable_scope(name', '+', "'/layer_norm'):", 'scale', '=', 'mtf.get_variable(x.mesh,', "'layer_norm_scale',", 'mtf.Shape([dim]),', 'initializer=tf.ones_initializer(),', 'activation_dtype=x.dtype)', 'bias', '=', 'mtf.get_var...
965,534
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mtf_layers.py
attention_mask_same_segment
attention_mask_same_segment
Bias for attention where attention between segments is disallowed.
[ "Bias", "for", "attention", "where", "attention", "between", "segments", "is", "disallowed." ]
def attention_mask_same_segment(query_segment, memory_segment=None, dtype=tf.float32): memory_segment = rename_length_to_memory_length(memory_segment or query_segment) return mtf.cast(mtf.not_equal(query_segment, memory_segment), dtype) * -1000000000.0
['def', 'attention_mask_same_segment(query_segment,', 'memory_segment=None,', 'dtype=tf.float32):', 'memory_segment', '=', 'rename_length_to_memory_length(memory_segment', 'or', 'query_segment)', 'return', 'mtf.cast(mtf.not_equal(query_segment,', 'memory_segment),', 'dtype)', '*', '-1000000000.0']
965,543
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mtf_model.py
MtfModel.estimator_spec_eval
estimator_spec_eval
Construct EstimatorSpec for EVAL mode.
[ "Construct", "EstimatorSpec", "for", "EVAL", "mode." ]
def estimator_spec_eval(self, features, logits, labels, loss, restore_hook, use_tpu): hparams = self.hparams problem = hparams.problem if logits.get_shape().ndims == 3: logits = tf.expand_dims(tf.expand_dims(logits, 2), 3) eval_metrics_fns = metrics.create_evaluation_metrics([problem], hparams) ...
['def', 'estimator_spec_eval(self,', 'features,', 'logits,', 'labels,', 'loss,', 'restore_hook,', 'use_tpu):', 'hparams', '=', 'self.hparams', 'problem', '=', 'hparams.problem', 'if', 'logits.get_shape().ndims', '==', '3:', 'logits', '=', 'tf.expand_dims(tf.expand_dims(logits,', '2),', '3)', 'eval_metrics_fns', '=', 'm...
965,545
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mtf_model.py
MtfModel.sample
sample
Sample from the model.
[ "Sample", "from", "the", "model." ]
def sample(self, features, mesh): raise NotImplementedError('TODO(noam): write generic slow mtf sample.')
['def', 'sample(self,', 'features,', 'mesh):', 'raise', "NotImplementedError('TODO(noam):", 'write', 'generic', 'slow', 'mtf', "sample.')"]
965,546
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
mtf_toy_model_tpu.py
model_fn
model_fn
A model is called by TpuEstimator.
[ "A", "model", "is", "called", "by", "TpuEstimator." ]
def model_fn(features, labels, mode, params): del labels global_step = tf.train.get_global_step() graph = mtf.Graph() mesh = mtf.Mesh(graph, 'my_mesh') mesh_shape = mtf.convert_to_shape(FLAGS.mesh_shape) mesh_devices = [''] * mesh_shape.size mesh_impl = SimdMeshImpl(mesh_shape, mtf.convert_t...
['def', 'model_fn(features,', 'labels,', 'mode,', 'params):', 'del', 'labels', 'global_step', '=', 'tf.train.get_global_step()', 'graph', '=', 'mtf.Graph()', 'mesh', '=', 'mtf.Mesh(graph,', "'my_mesh')", 'mesh_shape', '=', 'mtf.convert_to_shape(FLAGS.mesh_shape)', 'mesh_devices', '=', "['']", '*', 'mesh_shape.size', 'm...
965,551
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
placement_mesh_impl.py
PlacementMeshImpl.LaidOutVariable.assign_to_slices
assign_to_slices
Assign to the slice variables.
[ "Assign", "to", "the", "slice", "variables." ]
def assign_to_slices(self, slices): return tf.group(mtf.parallel(self._mesh_impl.devices, tf.assign, self.laid_out_tensor.all_slices, slices))
['def', 'assign_to_slices(self,', 'slices):', 'return', 'tf.group(mtf.parallel(self._mesh_impl.devices,', 'tf.assign,', 'self.laid_out_tensor.all_slices,', 'slices))']
965,560
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
placement_mesh_impl.py
PlacementMeshImpl.allconcat
allconcat
Grouped allconcat (like MPI allgather followed by concat).
[ "Grouped", "allconcat", "(like", "MPI", "allgather", "followed", "by", "concat)." ]
def allconcat(self, x, mesh_axis, concat_axis): return self._collective_with_groups(x, [mesh_axis], functools.partial(allconcat_ring, concat_axis=concat_axis))
['def', 'allconcat(self,', 'x,', 'mesh_axis,', 'concat_axis):', 'return', 'self._collective_with_groups(x,', '[mesh_axis],', 'functools.partial(allconcat_ring,', 'concat_axis=concat_axis))']
965,563
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
experiments_moe.py
xmoe_2d
xmoe_2d
Two-dimensional hierarchical mixture of experts.
[ "Two-dimensional", "hierarchical", "mixture", "of", "experts." ]
def xmoe_2d(): hparams = xmoe_top_2() hparams.mesh_shape = 'b0:2;b1:4' hparams.outer_batch_size = 4 hparams.layout = 'outer_batch:b0;inner_batch:b1,expert_x:b1,expert_y:b0' hparams.moe_num_experts = [4, 4] hparams.feedforward_layer = 'hmoe' return hparams
['def', 'xmoe_2d():', 'hparams', '=', 'xmoe_top_2()', 'hparams.mesh_shape', '=', "'b0:2;b1:4'", 'hparams.outer_batch_size', '=', '4', 'hparams.layout', '=', "'outer_batch:b0;inner_batch:b1,expert_x:b1,expert_y:b0'", 'hparams.moe_num_experts', '=', '[4,', '4]', 'hparams.feedforward_layer', '=', "'hmoe'", 'return', 'hpar...
965,581
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
moe.py
set_default_moe_hparams
set_default_moe_hparams
Add necessary hyperparameters for mixture-of-experts.
[ "Add", "necessary", "hyperparameters", "for", "mixture-of-experts." ]
def set_default_moe_hparams(hparams): hparams.feedforward_layer = 'moe' hparams.moe_num_experts = 16 hparams.moe_loss_coef = 0.01 hparams.add_hparam('moe_gating', 'top_2') hparams.add_hparam('moe_capacity_factor_train', 1.25) hparams.add_hparam('moe_capacity_factor_eval', 2.0) hparams.add_hp...
['def', 'set_default_moe_hparams(hparams):', 'hparams.feedforward_layer', '=', "'moe'", 'hparams.moe_num_experts', '=', '16', 'hparams.moe_loss_coef', '=', '0.01', "hparams.add_hparam('moe_gating',", "'top_2')", "hparams.add_hparam('moe_capacity_factor_train',", '1.25)', "hparams.add_hparam('moe_capacity_factor_eval',"...
965,587
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
basic.py
basic_fc_small
basic_fc_small
Small fully connected model.
[ "Small", "fully", "connected", "model." ]
def basic_fc_small(): hparams = common_hparams.basic_params1() hparams.learning_rate = 0.1 hparams.batch_size = 128 hparams.hidden_size = 256 hparams.num_hidden_layers = 2 hparams.initializer = 'uniform_unit_scaling' hparams.initializer_gain = 1.0 hparams.weight_decay = 0.0 hparams.d...
['def', 'basic_fc_small():', 'hparams', '=', 'common_hparams.basic_params1()', 'hparams.learning_rate', '=', '0.1', 'hparams.batch_size', '=', '128', 'hparams.hidden_size', '=', '256', 'hparams.num_hidden_layers', '=', '2', 'hparams.initializer', '=', "'uniform_unit_scaling'", 'hparams.initializer_gain', '=', '1.0', 'h...
965,588
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_base_tpu
imagetransformer_base_tpu
Transformer base params for cifar-10.
[ "Transformer", "base", "params", "for", "cifar-10." ]
def imagetransformer_base_tpu(): hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet() update_hparams_for_tpu(hparams) hparams.batch_size = 4 hparams.num_heads = 4 hparams.num_decoder_layers = 12 hparams.block_length = 128 hparams.hidden_size = 512 hparams.filter_size = 2048 h...
['def', 'imagetransformer_base_tpu():', 'hparams', '=', 'imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '4', 'hparams.num_heads', '=', '4', 'hparams.num_decoder_layers', '=', '12', 'hparams.block_length', '=', '128', 'hparams.hidden_size', '=', '512', ...
965,593
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_base_rel
imagetransformer_base_rel
Base with relative attention.
[ "Base", "with", "relative", "attention." ]
def imagetransformer_base_rel(): hparams = imagetransformer_base() hparams.dec_attention_type = cia.AttentionType.RELATIVE_LOCAL_1D return hparams
['def', 'imagetransformer_base_rel():', 'hparams', '=', 'imagetransformer_base()', 'hparams.dec_attention_type', '=', 'cia.AttentionType.RELATIVE_LOCAL_1D', 'return', 'hparams']
965,596
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_base_10l_8h_big_uncond_dr03_dan_64
imagetransformer_base_10l_8h_big_uncond_dr03_dan_64
big 1d model for unconditional generation on imagenet.
[ "big", "1d", "model", "for", "unconditional", "generation", "on", "imagenet." ]
def imagetransformer_base_10l_8h_big_uncond_dr03_dan_64(): hparams = imagetransformer_base_10l_8h_big_cond_dr03_dan() hparams.unconditional = True hparams.max_length = 14000 hparams.batch_size = 1 hparams.img_len = 64 hparams.layer_prepostprocess_dropout = 0.1 return hparams
['def', 'imagetransformer_base_10l_8h_big_uncond_dr03_dan_64():', 'hparams', '=', 'imagetransformer_base_10l_8h_big_cond_dr03_dan()', 'hparams.unconditional', '=', 'True', 'hparams.max_length', '=', '14000', 'hparams.batch_size', '=', '1', 'hparams.img_len', '=', '64', 'hparams.layer_prepostprocess_dropout', '=', '0.1'...
965,598
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_base_10l_8h_big_uncond_dr03_dan
imagetransformer_base_10l_8h_big_uncond_dr03_dan
Best unconditional Cifar10 gen param.
[ "Best", "unconditional", "Cifar10", "gen", "param." ]
def imagetransformer_base_10l_8h_big_uncond_dr03_dan(): hparams = imagetransformer_base_10l_8h_big_cond_dr03_dan() hparams.num_decoder_layers = 10 return hparams
['def', 'imagetransformer_base_10l_8h_big_uncond_dr03_dan():', 'hparams', '=', 'imagetransformer_base_10l_8h_big_cond_dr03_dan()', 'hparams.num_decoder_layers', '=', '10', 'return', 'hparams']
965,603
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_base_14l_8h_big_dr01
imagetransformer_base_14l_8h_big_dr01
big 1d model for conditional image generation.
[ "big", "1d", "model", "for", "conditional", "image", "generation." ]
def imagetransformer_base_14l_8h_big_dr01(): hparams = imagetransformer_base_14l_8h_big() hparams.layer_prepostprocess_dropout = 0.1 return hparams
['def', 'imagetransformer_base_14l_8h_big_dr01():', 'hparams', '=', 'imagetransformer_base_14l_8h_big()', 'hparams.layer_prepostprocess_dropout', '=', '0.1', 'return', 'hparams']
965,608
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_sep_channels_8l_tpu
imagetransformer_sep_channels_8l_tpu
Hparams for training imagetransformer on tpu.
[ "Hparams", "for", "training", "imagetransformer", "on", "tpu." ]
def imagetransformer_sep_channels_8l_tpu(): hparams = imagetransformer_sep_channels_8l() update_hparams_for_tpu(hparams) hparams.batch_size = 4 hparams.num_heads = 4 hparams.shared_embedding_and_softmax_weights = False return hparams
['def', 'imagetransformer_sep_channels_8l_tpu():', 'hparams', '=', 'imagetransformer_sep_channels_8l()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '4', 'hparams.num_heads', '=', '4', 'hparams.shared_embedding_and_softmax_weights', '=', 'False', 'return', 'hparams']
965,616
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b10l_4h_big_uncond_dr03_tpu
imagetransformer_b10l_4h_big_uncond_dr03_tpu
Small model for tpu cifar 10.
[ "Small", "model", "for", "tpu", "cifar", "10." ]
def imagetransformer_b10l_4h_big_uncond_dr03_tpu(): hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet() update_hparams_for_tpu(hparams) hparams.batch_size = 4 hparams.num_heads = 4 hparams.num_decoder_layers = 10 hparams.block_length = 128 hparams.hidden_size = 512 hparams.filte...
['def', 'imagetransformer_b10l_4h_big_uncond_dr03_tpu():', 'hparams', '=', 'imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '4', 'hparams.num_heads', '=', '4', 'hparams.num_decoder_layers', '=', '10', 'hparams.block_length', '=', '128', 'hparams.hidden_...
965,617
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b10l_4h_big_uncond_dr03_lr025_tpu
imagetransformer_b10l_4h_big_uncond_dr03_lr025_tpu
TPU related small model.
[ "TPU", "related", "small", "model." ]
def imagetransformer_b10l_4h_big_uncond_dr03_lr025_tpu(): hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet() update_hparams_for_tpu(hparams) hparams.batch_size = 4 hparams.num_heads = 4 hparams.num_decoder_layers = 10 hparams.learning_rate = 0.25 hparams.learning_rate_warmup_steps ...
['def', 'imagetransformer_b10l_4h_big_uncond_dr03_lr025_tpu():', 'hparams', '=', 'imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '4', 'hparams.num_heads', '=', '4', 'hparams.num_decoder_layers', '=', '10', 'hparams.learning_rate', '=', '0.25', 'hparams...
965,618
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b12l_4h_big_uncond_dr03_tpu
imagetransformer_b12l_4h_big_uncond_dr03_tpu
TPU 12 layer model.
[ "TPU", "12", "layer", "model." ]
def imagetransformer_b12l_4h_big_uncond_dr03_tpu(): hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet() update_hparams_for_tpu(hparams) hparams.batch_size = 4 hparams.num_heads = 4 hparams.num_decoder_layers = 12 hparams.block_length = 128 hparams.hidden_size = 512 hparams.filte...
['def', 'imagetransformer_b12l_4h_big_uncond_dr03_tpu():', 'hparams', '=', 'imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '4', 'hparams.num_heads', '=', '4', 'hparams.num_decoder_layers', '=', '12', 'hparams.block_length', '=', '128', 'hparams.hidden_...
965,619
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b12l_4h_b256_uncond_dr03_rel_tpu
imagetransformer_b12l_4h_b256_uncond_dr03_rel_tpu
works very well on 4x4.
[ "works", "very", "well", "on", "4x4." ]
def imagetransformer_b12l_4h_b256_uncond_dr03_rel_tpu(): hparams = imagetransformer_b12l_4h_b256_uncond_dr03_tpu() hparams.shared_rel = True hparams.dec_attention_type = cia.AttentionType.RELATIVE_LOCAL_1D return hparams
['def', 'imagetransformer_b12l_4h_b256_uncond_dr03_rel_tpu():', 'hparams', '=', 'imagetransformer_b12l_4h_b256_uncond_dr03_tpu()', 'hparams.shared_rel', '=', 'True', 'hparams.dec_attention_type', '=', 'cia.AttentionType.RELATIVE_LOCAL_1D', 'return', 'hparams']
965,621
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b12l_4h_b128_h512_uncond_dr03_tpu
imagetransformer_b12l_4h_b128_h512_uncond_dr03_tpu
TPU related big model.
[ "TPU", "related", "big", "model." ]
def imagetransformer_b12l_4h_b128_h512_uncond_dr03_tpu(): hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet() update_hparams_for_tpu(hparams) hparams.batch_size = 4 hparams.num_heads = 4 hparams.num_decoder_layers = 12 hparams.block_length = 128 hparams.hidden_size = 512 hparams...
['def', 'imagetransformer_b12l_4h_b128_h512_uncond_dr03_tpu():', 'hparams', '=', 'imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '4', 'hparams.num_heads', '=', '4', 'hparams.num_decoder_layers', '=', '12', 'hparams.block_length', '=', '128', 'hparams.h...
965,623
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b12l_4h_b128_h512_uncond_dr01_im
imagetransformer_b12l_4h_b128_h512_uncond_dr01_im
TPU related imagenet model.
[ "TPU", "related", "imagenet", "model." ]
def imagetransformer_b12l_4h_b128_h512_uncond_dr01_im(): hparams = imagetransformer_b12l_4h_b256_uncond_dr03_tpu() update_hparams_for_tpu(hparams) hparams.batch_size = 4 hparams.optimizer = 'Adafactor' hparams.learning_rate_schedule = 'rsqrt_decay' hparams.learning_rate_warmup_steps = 6000 h...
['def', 'imagetransformer_b12l_4h_b128_h512_uncond_dr01_im():', 'hparams', '=', 'imagetransformer_b12l_4h_b256_uncond_dr03_tpu()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '4', 'hparams.optimizer', '=', "'Adafactor'", 'hparams.learning_rate_schedule', '=', "'rsqrt_decay'", 'hparams.learning_rate_wa...
965,624
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b12l_4h_b128_uncond_dr03_tpu
imagetransformer_b12l_4h_b128_uncond_dr03_tpu
TPU config for cifar 10.
[ "TPU", "config", "for", "cifar", "10." ]
def imagetransformer_b12l_4h_b128_uncond_dr03_tpu(): hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet() update_hparams_for_tpu(hparams) hparams.batch_size = 2 hparams.num_heads = 4 hparams.num_decoder_layers = 12 hparams.block_length = 128 hparams.hidden_size = 256 hparams.filt...
['def', 'imagetransformer_b12l_4h_b128_uncond_dr03_tpu():', 'hparams', '=', 'imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '2', 'hparams.num_heads', '=', '4', 'hparams.num_decoder_layers', '=', '12', 'hparams.block_length', '=', '128', 'hparams.hidden...
965,626
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer.py
imagetransformer_b12l_8h_b256_uncond_dr03_tpu
imagetransformer_b12l_8h_b256_uncond_dr03_tpu
TPU related 12 layer 8 heads model.
[ "TPU", "related", "12", "layer", "8", "heads", "model." ]
def imagetransformer_b12l_8h_b256_uncond_dr03_tpu(): hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet() update_hparams_for_tpu(hparams) hparams.batch_size = 2 hparams.num_heads = 8 hparams.num_decoder_layers = 12 hparams.block_length = 256 hparams.hidden_size = 512 hparams.filt...
['def', 'imagetransformer_b12l_8h_b256_uncond_dr03_tpu():', 'hparams', '=', 'imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()', 'update_hparams_for_tpu(hparams)', 'hparams.batch_size', '=', '2', 'hparams.num_heads', '=', '8', 'hparams.num_decoder_layers', '=', '12', 'hparams.block_length', '=', '256', 'hparams.hidden...
965,627
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer_2d.py
imagetransformer2d_base_8l_8_32_big
imagetransformer2d_base_8l_8_32_big
hparams fo 8 layer big 2d model for cifar 10.
[ "hparams", "fo", "8", "layer", "big", "2d", "model", "for", "cifar", "10." ]
def imagetransformer2d_base_8l_8_32_big(): hparams = image_transformer2d_base() hparams.num_heads = 16 hparams.hidden_size = 1024 hparams.filter_size = 2048 hparams.num_decoder_layers = 8 hparams.batch_size = 1 hparams.layer_prepostprocess_dropout = 0.3 hparams.query_shape = (8, 16) ...
['def', 'imagetransformer2d_base_8l_8_32_big():', 'hparams', '=', 'image_transformer2d_base()', 'hparams.num_heads', '=', '16', 'hparams.hidden_size', '=', '1024', 'hparams.filter_size', '=', '2048', 'hparams.num_decoder_layers', '=', '8', 'hparams.batch_size', '=', '1', 'hparams.layer_prepostprocess_dropout', '=', '0....
965,630
hongliangduan/Transformer-model-for-prediction-in-low-chemical-data-regimes
image_transformer_2d.py
img2img_transformer2d_base
img2img_transformer2d_base
Base params for img2img 2d attention.
[ "Base", "params", "for", "img2img", "2d", "attention." ]
def img2img_transformer2d_base(): hparams = image_transformer2d_base() hparams.layer_preprocess_sequence = 'n' hparams.layer_postprocess_sequence = 'da' hparams.learning_rate = 0.2 hparams.layer_prepostprocess_dropout = 0.1 hparams.learning_rate_warmup_steps = 12000 hparams.filter_size = 204...
['def', 'img2img_transformer2d_base():', 'hparams', '=', 'image_transformer2d_base()', 'hparams.layer_preprocess_sequence', '=', "'n'", 'hparams.layer_postprocess_sequence', '=', "'da'", 'hparams.learning_rate', '=', '0.2', 'hparams.layer_prepostprocess_dropout', '=', '0.1', 'hparams.learning_rate_warmup_steps', '=', '...
965,634