Code stringlengths 103 85.9k | Summary listlengths 0 94 |
|---|---|
Please provide a description of the function:def gumbel_softmax_discrete_bottleneck(x,
bottleneck_bits,
beta=0.25,
decay=0.999,
epsilon=1e-5,
... | [
"VQ-VAE using Gumbel-Softmax.\n\n Different from `gumbel_softmax()` function as\n this function calculates the KL by using the discrete entropy\n instead of taking the argmax, and it also uses an exponential moving average\n to update the codebook while the `gumbel_softmax()` function includes no\n codebook up... |
Please provide a description of the function:def tanh_discrete_bottleneck(x, bottleneck_bits, bottleneck_noise,
discretize_warmup_steps, mode):
x = tf.layers.dense(x, bottleneck_bits, name="tanh_discrete_bottleneck")
d0 = tf.stop_gradient(2.0 * tf.to_float(tf.less(0.0, x))) - 1.0
i... | [
"Simple discretization through tanh, flip bottleneck_noise many bits."
] |
Please provide a description of the function:def tanh_discrete_unbottleneck(x, hidden_size):
x = tf.layers.dense(x, hidden_size, name="tanh_discrete_unbottleneck")
return x | [
"Simple un-discretization from tanh."
] |
Please provide a description of the function:def isemhash_bottleneck(x,
bottleneck_bits,
bottleneck_noise,
discretize_warmup_steps,
mode,
isemhash_noise_dev=0.5,
isemhash_mix_p... | [
"Improved semantic hashing bottleneck."
] |
Please provide a description of the function:def isemhash_unbottleneck(x, hidden_size, isemhash_filter_size_multiplier=1.0):
filter_size = int(hidden_size * isemhash_filter_size_multiplier)
x = 0.5 * (x - 1.0) # Move from [-1, 1] to [0, 1].
with tf.variable_scope("isemhash_unbottleneck"):
h1a = tf.layers.... | [
"Improved semantic hashing un-bottleneck."
] |
Please provide a description of the function:def parametrized_bottleneck(x, hparams):
if hparams.bottleneck_kind == "tanh_discrete":
d, _ = tanh_discrete_bottleneck(
x, hparams.bottleneck_bits, hparams.bottleneck_noise * 0.5,
hparams.discretize_warmup_steps, hparams.mode)
return d, 0.0
if... | [
"Meta-function calling all the above bottlenecks with hparams."
] |
Please provide a description of the function: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,
... | [
"Meta-function calling all the above un-bottlenecks with hparams."
] |
Please provide a description of the function:def iaf_hparams(hidden_size=512, filter_size=4096):
hparams = common_hparams.basic_params1()
# Attention hyperparameters.
hparams.hidden_size = hidden_size
hparams.add_hparam("attention_key_channels", None)
hparams.add_hparam("attention_value_channels", None)
... | [
"Create hyperpameters for inverse autoregressive flows.\n\n Args:\n hidden_size: Width of attention layers and neural network output layer.\n filter_size: Hidden layer width for neural network.\n\n Returns:\n hparams: Hyperpameters with basic presets for inverse autoregressive flows.\n "
] |
Please provide a description of the function:def _original_vocab(tmp_dir):
vocab_url = ("http://download.tensorflow.org/models/LM_LSTM_CNN/"
"vocab-2016-09-10.txt")
vocab_filename = os.path.basename(vocab_url + ".en")
vocab_filepath = os.path.join(tmp_dir, vocab_filename)
if not os.path.exists... | [
"Returns a set containing the original vocabulary.\n\n This is important for comparing with published results.\n\n Args:\n tmp_dir: directory containing dataset.\n\n Returns:\n a set of strings\n "
] |
Please provide a description of the function:def _replace_oov(original_vocab, line):
return u" ".join(
[word if word in original_vocab else u"UNK" for word in line.split()]) | [
"Replace out-of-vocab words with \"UNK\".\n\n This maintains compatibility with published results.\n\n Args:\n original_vocab: a set of strings (The standard vocabulary for the dataset)\n line: a unicode string - a space-delimited sequence of words.\n\n Returns:\n a unicode string - a space-delimited se... |
Please provide a description of the function:def _maybe_download_corpus(tmp_dir):
corpus_url = ("http://www.statmt.org/lm-benchmark/"
"1-billion-word-language-modeling-benchmark-r13output.tar.gz")
corpus_filename = os.path.basename(corpus_url)
corpus_filepath = os.path.join(tmp_dir, corpus_file... | [
"Download and unpack the corpus.\n\n Args:\n tmp_dir: directory containing dataset.\n "
] |
Please provide a description of the function:def lossfn(real_input, fake_input, compress, hparams, lsgan, name):
eps = 1e-12
with tf.variable_scope(name):
d1 = discriminator(real_input, compress, hparams, "discriminator")
d2 = discriminator(fake_input, compress, hparams, "discriminator",
... | [
"Loss function."
] |
Please provide a description of the function:def cycle_gan_internal(inputs, targets, _, hparams):
with tf.variable_scope("cycle_gan"):
# Embed inputs and targets.
inputs_orig, targets_orig = tf.to_int32(inputs), tf.to_int32(targets)
inputs = common_layers.embedding(
inputs_orig, hparams.vocab_s... | [
"Cycle GAN, main step used for training."
] |
Please provide a description of the function:def cycle_gan_small():
hparams = transformer_vae.transformer_ae_small()
hparams.batch_size = 2048
hparams.bottom = {
"inputs": modalities.identity_bottom,
"targets": modalities.identity_bottom,
}
hparams.top = {
"targets": modalities.identity_t... | [
"Set of hyperparameters."
] |
Please provide a description of the function:def decode_hparams(overrides=""):
hparams = decoding.decode_hparams()
# Number of interpolations between [0.0, 1.0].
hparams.add_hparam("num_interp", 11)
# Which level(s) to interpolate.
hparams.add_hparam("level_interp", [0, 1, 2])
# "all" or "ranked", interp... | [
"Hparams for decoding."
] |
Please provide a description of the function:def preprocess_frame(frame):
# Normalize from [0.0, 1.0] -> [-0.5, 0.5]
frame = common_layers.convert_rgb_to_real(frame)
frame = frame - 0.5
frame, _ = glow_ops.uniform_binning_correction(frame)
return frame | [
"Preprocess frame.\n\n 1. Converts [0, 255] to [-0.5, 0.5]\n 2. Adds uniform noise.\n\n Args:\n frame: 3-D Tensor representing pixels.\n Returns:\n frame: 3-D Tensor with values in between [-0.5, 0.5]\n "
] |
Please provide a description of the function:def frame_to_latents(frame, hparams):
# Preprocess
frame = preprocess_frame(frame)
# Encode [X_t] to [z^1_t, z^2_t .. z^l_t]
glow_vals = glow_ops.encoder_decoder(
"codec", frame, hparams, eps=None, reverse=False)
z_top, _, level_eps, _, _ = glow_vals
re... | [
"Encode frames to latents."
] |
Please provide a description of the function:def latents_to_frames(z_top_interp, level_eps_interp, hparams):
# Decode [z^1_t, z^2_t .. z^l_t] to [X_t]
images, _, _, _ = glow_ops.encoder_decoder(
"codec", z_top_interp, hparams, eps=level_eps_interp, reverse=True)
images = glow_ops.postprocess(images)
re... | [
"Decodes latents to frames."
] |
Please provide a description of the function:def interpolate(features, hparams, decode_hp):
inputs, targets = features["inputs"], features["targets"]
inputs = tf.unstack(inputs, axis=1)
targets = tf.unstack(targets, axis=1)
coeffs = np.linspace(0.0, 1.0, decode_hp.num_interp)
# (X_1, X_t) -> (z_1, z_t)
... | [
"Interpolate between the first input frame and last target frame.\n\n Args:\n features: dict of tensors\n hparams: HParams, training hparams.\n decode_hp: HParams, decode hparams.\n Returns:\n images: interpolated images, 4-D Tensor, shape=(num_interp, H, W, C)\n first_frame: image, 3-D Tensor, sha... |
Please provide a description of the function:def get_summaries_log_dir(decode_hp, output_dir, dataset_split):
child_dir = decode_hp.summaries_log_dir
level_dir = "".join([str(level) for level in decode_hp.level_interp])
if decode_hp.channel_interp == "all":
rank_dir = "all"
else:
rank_dir = "rank_%d"... | [
"Get nested summaries_log_dir based on decode_hp."
] |
Please provide a description of the function:def interpolations_to_summary(sample_ind, interpolations, first_frame,
last_frame, hparams, decode_hp):
parent_tag = "sample_%d" % sample_ind
frame_shape = hparams.problem.frame_shape
interp_shape = [hparams.batch_size, decode_hp.num_in... | [
"Converts interpolated frames into tf summaries.\n\n The summaries consists of:\n 1. Image summary corresponding to the first frame.\n 2. Image summary corresponding to the last frame.\n 3. The interpolated frames as a gif summary.\n\n Args:\n sample_ind: int\n interpolations: Numpy array, shape=(n... |
Please provide a description of the function:def next_frame_epva():
hparams = basic_deterministic_params.next_frame_basic_deterministic()
hparams.video_num_input_frames = 4
hparams.video_num_target_frames = 4
hparams.bottom = {
"inputs": modalities.video_raw_bottom,
"targets": modalities.video_ra... | [
"EPVA hparams."
] |
Please provide a description of the function:def _create_slots(self, var_list):
super(MultistepAdamOptimizer, self)._create_slots(var_list)
first_var = min(var_list, key=lambda x: x.name)
self._create_non_slot_variable(initial_value=0 if self._n == 1 else 1,
name="ite... | [
"Create slot variables for Adam with accumulated gradients."
] |
Please provide a description of the function:def _apply_cond(self, apply_fn, grad, var, *args, **kwargs):
grad_acc = self.get_slot(var, "grad_acc")
def apply_adam(grad_acc, apply_fn, grad, var, *args, **kwargs):
total_grad = (grad_acc + grad) / tf.cast(self._n_t, grad.dtype)
adam_op = apply_fn... | [
"Apply conditionally if counter is zero."
] |
Please provide a description of the function:def _finish(self, update_ops, name_scope):
iter_ = self._get_iter_variable()
beta1_power, beta2_power = self._get_beta_accumulators()
with tf.control_dependencies(update_ops):
with tf.colocate_with(iter_):
def update_beta_op():
updat... | [
"Updates beta_power variables every n batches and incrs counter."
] |
Please provide a description of the function:def transformer_revnet_encoder(encoder_input,
encoder_self_attention_bias,
hparams,
name="encoder"):
def f(x, side_input):
encoder_self_attention_bias = side_input[0]
... | [
"A stack of transformer layers.\n\n Args:\n encoder_input: a Tensor\n encoder_self_attention_bias: bias Tensor for self-attention\n (see common_attention.attention_bias())\n hparams: hyperparameters for model\n name: a string\n\n Returns:\n y: a Tensors\n ",
"f(x) for reversible layer, sel... |
Please provide a description of the function:def transformer_revnet_decoder(decoder_input,
encoder_output,
decoder_self_attention_bias,
encoder_decoder_attention_bias,
hparams,
... | [
"A stack of transformer layers.\n\n Args:\n decoder_input: a Tensor\n encoder_output: a Tensor\n decoder_self_attention_bias: bias Tensor for self-attention\n (see common_attention.attention_bias())\n encoder_decoder_attention_bias: bias Tensor for encoder-decoder attention\n (see common_atte... |
Please provide a description of the function:def transformer_revnet_base():
hparams = transformer.transformer_big()
# Use settings from transformer_n_da
hparams.layer_preprocess_sequence = "n"
hparams.layer_postprocess_sequence = "da"
hparams.learning_rate = 0.4
return hparams | [
"Base hparams for TransformerRevnet."
] |
Please provide a description of the function:def transformer_revnet_big():
hparams = transformer_revnet_base()
# The TransformerRevnet uses significantly less memory than the Transformer.
# Increase batch size and model size.
hparams.batch_size *= 2
hparams.hidden_size *= 2
hparams.num_heads *= 2
hpar... | [
"Base hparams for TransformerRevnet."
] |
Please provide a description of the function:def data_parallelism_from_flags(daisy_chain_variables=True, all_workers=False):
dp_arg_names = inspect.getargspec(data_parallelism).args
blacklist = ["daisy_chain_variables", "all_workers"]
kwargs = {}
for arg in dp_arg_names:
if arg in blacklist:
cont... | [
"Over which devices do we split each training batch.\n\n In old-fashioned async mode, we split the batch over all GPUs on the\n current worker.\n\n In sync mode, we split the batch over all the parameter server GPUs.\n\n This function returns an expert_utils.Parallelism object, which can be used\n to build the... |
Please provide a description of the function:def data_parallelism(daisy_chain_variables=True,
all_workers=False,
ps_replicas=0,
ps_job="/job:ps",
ps_gpu=0,
schedule="continuous_train_and_eval",
... | [
"See data_parallelism_from_flags.",
"List of ps devices (where to put the experts).\n\n Args:\n all_workers: whether the list is for all async workers or just this one.\n\n Returns:\n a list of device names\n "
] |
Please provide a description of the function:def concat_generator(filename, up_threshold, low_threshold=10):
txt = ""
for line in tf.gfile.Open(filename):
line = line.strip()
if len(txt) + len(line) + 1 >= up_threshold:
ret = txt
txt = ""
# We don't yield very short long parts to preven... | [
"Generate concatenated lines from file upto up_threshold characters."
] |
Please provide a description of the function:def mix_generators(generator_list):
i = 0
l = len(generator_list)
stopiters_seen = 0
while stopiters_seen <= l:
try:
yield six.next(generator_list[i % l])
i += 1
stopiters_seen = 0
except StopIteration:
i += 1
stopiters_seen +... | [
"Given python generators, generate from one, then from another, etc."
] |
Please provide a description of the function:def compute_bleu_summaries(hook_args):
decode_hparams = hook_args.decode_hparams
if not (decode_hparams.decode_reference and decode_hparams.decode_to_file):
return None
values = []
bleu = 100 * bleu_hook.bleu_wrapper(
decode_hparams.decode_reference, d... | [
"Compute BLEU core summaries using the decoder output.\n\n Args:\n hook_args: DecodeHookArgs namedtuple\n Returns:\n A list of tf.Summary values if hook_args.hparams contains the\n reference file and the translated file.\n "
] |
Please provide a description of the function:def _preprocess_sgm(line, is_sgm):
if not is_sgm:
return line
# In SGM files, remove <srcset ...>, <p>, <doc ...> lines.
if line.startswith("<srcset") or line.startswith("</srcset"):
return ""
if line.startswith("<doc") or line.startswith("</doc"):
ret... | [
"Preprocessing to strip tags in SGM files."
] |
Please provide a description of the function:def compile_data(tmp_dir, datasets, filename, datatypes_to_clean=None):
datatypes_to_clean = datatypes_to_clean or []
filename = os.path.join(tmp_dir, filename)
lang1_fname = filename + ".lang1"
lang2_fname = filename + ".lang2"
if tf.gfile.Exists(lang1_fname) a... | [
"Concatenates all `datasets` and saves to `filename`."
] |
Please provide a description of the function:def get_or_create_vocab(self, data_dir, tmp_dir, force_get=False):
# We assume that vocab file is present in data_dir directory where the
# data generated will be stored.
vocab_filepath = os.path.join(data_dir, self.vocab_filename)
encoder = text_encoder... | [
"Get vocab for distill problems."
] |
Please provide a description of the function:def set_hparams_from_args(args):
if not args:
return
hp_prefix = "--hp_"
tf.logging.info("Found unparsed command-line arguments. Checking if any "
"start with %s and interpreting those as hparams "
"settings.", hp_prefix)
... | [
"Set hparams overrides from unparsed args list."
] |
Please provide a description of the function:def create_hparams():
if FLAGS.use_tpu and "tpu" not in FLAGS.hparams_set:
tf.logging.warn("Not all hyperparameter sets work on TPU. "
"Prefer hparams_sets with a '_tpu' suffix, "
"e.g. transformer_tpu, if available for your m... | [
"Create hparams."
] |
Please provide a description of the function:def create_run_config(hp, output_dir=None):
save_ckpt_steps = max(FLAGS.iterations_per_loop, FLAGS.local_eval_frequency)
save_ckpt_secs = FLAGS.save_checkpoints_secs or None
if save_ckpt_secs:
save_ckpt_steps = None
assert FLAGS.output_dir or FLAGS.checkpoint_... | [
"Create a run config.\n\n Args:\n hp: model hyperparameters\n output_dir: model's output directory, defaults to output_dir flag.\n\n Returns:\n a run config\n "
] |
Please provide a description of the function:def save_metadata(hparams):
output_dir = os.path.expanduser(FLAGS.output_dir)
if not tf.gfile.Exists(output_dir):
tf.gfile.MakeDirs(output_dir)
# Save FLAGS in txt file
if hasattr(FLAGS, "flags_into_string"):
flags_str = FLAGS.flags_into_string()
t2t_... | [
"Saves FLAGS and hparams to output_dir."
] |
Please provide a description of the function:def residual_block(x, hparams):
k = (hparams.kernel_height, hparams.kernel_width)
dilations_and_kernels = [((1, 1), k) for _ in range(3)]
y = common_layers.subseparable_conv_block(
x,
hparams.hidden_size,
dilations_and_kernels,
padding="SAME"... | [
"A stack of convolution blocks with residual connection."
] |
Please provide a description of the function:def xception_internal(inputs, hparams):
with tf.variable_scope("xception"):
cur = inputs
if cur.get_shape().as_list()[1] > 200:
# Large image, Xception entry flow
cur = xception_entry(cur, hparams.hidden_size)
else:
# Small image, conv
... | [
"Xception body."
] |
Please provide a description of the function:def xception_entry(inputs, hidden_dim):
with tf.variable_scope("xception_entry"):
def xnet_resblock(x, filters, res_relu, name):
with tf.variable_scope(name):
y = common_layers.separable_conv_block(
x,
filters, [((1, 1),... | [
"Xception entry flow.",
"Resblock."
] |
Please provide a description of the function:def xception_exit(inputs):
with tf.variable_scope("xception_exit"):
x = inputs
x_shape = x.get_shape().as_list()
if x_shape[1] is None or x_shape[2] is None:
length_float = tf.to_float(tf.shape(x)[1])
length_float *= tf.to_float(tf.shape(x)[2])
... | [
"Xception exit flow."
] |
Please provide a description of the function:def get_text_from_html(html):
try:
soup = bs4.BeautifulSoup(html, "html.parser")
except: # pylint: disable=bare-except
# Some docs don't parse
return ""
# Remove script and style tags
for s in soup(["script", "style"]):
s.decompose()
return "\n... | [
"Returns a plaintext representation of HTML content."
] |
Please provide a description of the function:def _soup_strings(soup):
paragraph_tags = set([
"caption", "details", "h1", "h2", "h3", "h4", "h5", "h6", "li", "p", "td",
"div", "span"
])
skip_children = None
for descendant in soup.descendants:
# If we've treated a tag as a contiguous paragraph... | [
"Return text strings in soup."
] |
Please provide a description of the function:def image_transformer_base():
hparams = common_hparams.basic_params1()
hparams.hidden_size = 512
hparams.batch_size = 4
hparams.max_length = 3075
hparams.dropout = 0.0
hparams.clip_grad_norm = 0. # i.e. no gradient clipping
hparams.optimizer_adam_epsilon = ... | [
"Set of hyperparameters."
] |
Please provide a description of the function:def imagetransformer_cifar10_base():
hparams = image_transformer_base()
hparams.batch_size = 4
hparams.num_heads = 4
hparams.num_decoder_layers = 12
hparams.block_length = 256
hparams.hidden_size = 512
hparams.filter_size = 2048
hparams.learning_rate = 0.5... | [
"Best config for 2.90 bits/dim on CIFAR10 using cross entropy."
] |
Please provide a description of the function:def imagetransformer_cifar10_base_dmol():
hparams = image_transformer_base()
hparams.likelihood = cia.DistributionType.DMOL
hparams.num_channels = 1
hparams.bottom["targets"] = modalities.image_channel_compress_targets_bottom
hparams.top["targets"] = modalities.... | [
"Best config for 2.90 bits/dim on CIFAR10 using DMOL."
] |
Please provide a description of the function: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 # heads are expensive on tpu
hparams.num_decoder_layers = 12
hparams.block_length = 128... | [
"Transformer base params for cifar-10."
] |
Please provide a description of the function:def imagetransformer_base_imagenet_tpu():
hparams = imagetransformer_base_tpu()
hparams.batch_size = 4
hparams.num_heads = 4 # heads are expensive on tpu
hparams.num_decoder_layers = 12
hparams.block_length = 128
hparams.layer_preprocess_sequence = "none"
... | [
"Transformer base params for cifar-10."
] |
Please provide a description of the function:def imagetransformer_sep_channels():
hparams = imagetransformer_base()
hparams.num_heads = 4
hparams.attention_key_channels = hparams.attention_value_channels = 0
hparams.hidden_size = 256
hparams.filter_size = 512
hparams.num_hidden_layers = 6
return hparam... | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformer_sep_channels_8l():
hparams = imagetransformer_base()
hparams.num_heads = 4
hparams.attention_key_channels = hparams.attention_value_channels = 0
hparams.hidden_size = 256
hparams.filter_size = 256
hparams.num_hidden_layers = 8
hparams.sa... | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformer_base_8l_8h_big_cond_dr03_dan():
hparams = imagetransformer_sep_channels_8l()
hparams.block_width = 256
hparams.block_length = 256
hparams.hidden_size = 512
hparams.num_heads = 8
hparams.filter_size = 2048
hparams.batch_size = 4
hparams... | [
"big 1d model for conditional image generation.2.99 on cifar10."
] |
Please provide a description of the function: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... | [
"big 1d model for unconditional generation on imagenet."
] |
Please provide a description of the function:def imagetransformerpp_sep_channels_8l_8h():
hparams = imagetransformer_base()
hparams.likelihood = cia.DistributionType.DMOL
hparams.num_channels = 1
hparams.bottom["targets"] = modalities.image_channel_compress_targets_bottom
hparams.top["targets"] = modalitie... | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformerpp_base_8l_8h_big_cond_dr03_dan():
hparams = imagetransformerpp_sep_channels_8l_8h()
hparams.hidden_size = 512
hparams.num_heads = 8
hparams.filter_size = 2048
hparams.batch_size = 4
hparams.max_length = 3075
hparams.layer_prepostprocess_... | [
"big 1d model for conditional image generation.2.99 on cifar10."
] |
Please provide a description of the function:def imagetransformerpp_base_14l_8h_big_uncond_dr03_dan_p():
hparams = imagetransformerpp_base_12l_8h_big_uncond_dr03_dan_l()
hparams.num_decoder_layers = 14
hparams.batch_size = 8
hparams.layer_prepostprocess_dropout = 0.2
return hparams | [
"Gets to 2.92 in just under 4 days on 8 p100s."
] |
Please provide a description of the function:def imagetransformerpp_base_5l_8h_big_uncond_dr00_dan_g_bs1():
hparams = imagetransformerpp_base_10l_8h_big_uncond_dr03_dan_g()
# TODO(trandustin): I forgot to set this in the runs! Maybe it's not used in
# image transformer training implementation?
# hparams.img_... | [
"For 256x256."
] |
Please provide a description of the function:def imagetransformer_base_8l_8h_big_cond_dr03_dan_dilated():
hparams = imagetransformer_base_8l_8h_big_cond_dr03_dan()
hparams.gap_sizes = [0, 16, 64, 0, 16, 64, 128, 0]
hparams.dec_attention_type = cia.AttentionType.DILATED
hparams.block_length = 128
hparams.bl... | [
"Dilated hparams."
] |
Please provide a description of the function:def imagetransformer_base_12l_8h_big():
hparams = imagetransformer_sep_channels_8l_8h()
hparams.filter_size = 1024
hparams.num_decoder_layers = 12
hparams.batch_size = 1
hparams.hidden_size = 512
hparams.learning_rate_warmup_steps = 4000
hparams.sampling_met... | [
"big 1d model for conditional image generation."
] |
Please provide a description of the function:def imagetransformer1d_base_8l_64by64():
hparams = image_transformer_base()
hparams.num_heads = 8
hparams.hidden_size = 512
hparams.filter_size = 2048
hparams.num_decoder_layers = 8
hparams.batch_size = 1
hparams.block_length = 512
hparams.block_width = 76... | [
"hparams fo 12 layer big 1d model for imagenet 64x64."
] |
Please provide a description of the function:def imagetransformer_sep_channels_12l_16h_imagenet_large():
hparams = imagetransformer_sep_channels_8l_8h()
hparams.num_hidden_layers = 12
hparams.batch_size = 1
hparams.filter_size = 2048
hparams.num_heads = 16
hparams.learning_rate_warmup_steps = 16000
hpa... | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformer_sep_channels_16l_16h_imgnet_lrg_loc():
hparams = imagetransformer_sep_channels_12l_16h_imagenet_large()
hparams.num_hidden_layers = 16
hparams.local_attention = True
hparams.batch_size = 1
hparams.block_length = 256
return hparams | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformer_sep_channels_16l_16h_imgnet_lrg_loc_128():
hparams = imagetransformer_sep_channels_12l_16h_imagenet_large()
hparams.num_hidden_layers = 16
hparams.local_attention = True
hparams.batch_size = 1
hparams.block_length = 128
return hparams | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformer_base_10l_16h_big_uncond_dr01_imgnet():
hparams = imagetransformer_base_14l_8h_big_dr01()
# num_hidden_layers
hparams.num_decoder_layers = 10
hparams.num_heads = 16
hparams.hidden_size = 1024
hparams.filter_size = 4096
hparams.batch_size ... | [
"big 1d model for conditional image generation."
] |
Please provide a description of the function:def imagetransformer_base_10l_16h_big_dr01_imgnet():
hparams = imagetransformer_base_14l_8h_big_dr01()
# num_hidden_layers
hparams.num_decoder_layers = 10
hparams.num_heads = 16
hparams.hidden_size = 1024
hparams.filter_size = 4096
hparams.batch_size = 1
h... | [
"big 1d model for conditional image generation."
] |
Please provide a description of the function:def imagetransformer_sep_channels_8l_8h():
hparams = imagetransformer_base()
hparams.num_heads = 8
hparams.batch_size = 1
hparams.attention_key_channels = hparams.attention_value_channels = 0
hparams.hidden_size = 512
hparams.filter_size = 512
hparams.num_hi... | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformer_sep_channels_8l_8h_local_and_global_att():
hparams = imagetransformer_sep_channels_8l_8h()
hparams.num_heads = 8
hparams.batch_size = 1
hparams.attention_key_channels = hparams.attention_value_channels = 0
hparams.hidden_size = 256
hparams... | [
"separate rgb embeddings."
] |
Please provide a description of the function:def imagetransformer_bas8l_8h_big_uncond_dr03_imgnet():
hparams = imagetransformer_base_14l_8h_big_dr01()
# num_hidden_layers
hparams.num_decoder_layers = 8
hparams.num_heads = 8
hparams.hidden_size = 512
hparams.filter_size = 2048
hparams.layer_prepostproce... | [
"big 1d model for conditional image generation."
] |
Please provide a description of the function:def imagetransformer_base_10l_16h_big_dr01_moe_imgnet():
hparams = imagetransformer_base_10l_16h_big_dr01_imgnet()
hparams.initializer = "orthogonal"
hparams.learning_rate_warmup_steps = 16000
hparams.add_hparam("moe_layers_decoder", "2,7") # Which layer is MoE.
... | [
"big 1d model for conditional image generation."
] |
Please provide a description of the function:def imagetransformer_moe_tiny():
hparams = imagetransformer_tiny()
hparams.hidden_size = 64
hparams.batch_size = 1
hparams.num_hidden_layers = 3
hparams.dec_attention_type = cia.AttentionType.MOE_LOCAL_1D
hparams.add_hparam("moe_layers_decoder", "1") # Which ... | [
"Set of hyperparameters for a very small imagetransformer with MoE."
] |
Please provide a description of the function:def imagetransformer_sep_channels_8l_tpu():
hparams = imagetransformer_sep_channels_8l()
update_hparams_for_tpu(hparams)
hparams.batch_size = 4
hparams.num_heads = 4 # heads are expensive on tpu
hparams.shared_embedding_and_softmax_weights = False
return hpa... | [
"Hparams for training imagetransformer on tpu."
] |
Please provide a description of the function: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 # heads are expensive on tpu
hparams.num_decoder_layers = 10
hparams... | [
"Small model for tpu cifar 10."
] |
Please provide a description of the function:def imagetransformer_b10l_dr03_moe_tpu():
hparams = imagetransformer_b10l_4h_big_uncond_dr03_tpu()
update_hparams_for_tpu(hparams)
hparams.batch_size = 4
hparams.num_heads = 4 # heads are expensive on tpu
hparams.num_decoder_layers = 10
hparams.layer_preproc... | [
"Moe tpu params."
] |
Please provide a description of the function: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 # heads are expensive on tpu
hparams.num_decoder_layers = 10
h... | [
"TPU related small model."
] |
Please provide a description of the function:def imagetransformer_b12l_4h_b256_uncond_dr03_tpu():
hparams = imagetransformer_bas8l_8h_big_uncond_dr03_imgnet()
update_hparams_for_tpu(hparams)
hparams.batch_size = 4
hparams.num_heads = 4 # heads are expensive on tpu
hparams.num_decoder_layers = 12
hparam... | [
"works very well on 4x4."
] |
Please provide a description of the function: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 | [
"works very well on 4x4."
] |
Please provide a description of the function:def imagetransformer_cifar_tpu_range(rhp):
# After starting from base, set intervals for some parameters.
rhp.set_float("learning_rate", 0.01, 1.0, scale=rhp.LOG_SCALE)
rhp.set_discrete("num_decoder_layers", [8, 10, 12, 14, 16])
rhp.set_discrete("hidden_size", [25... | [
"Range of hyperparameters for vizier."
] |
Please provide a description of the function: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.lea... | [
"TPU related imagenet model."
] |
Please provide a description of the function:def imagetransformer_b12l_4h_uncond_dr03_tpu():
hparams = imagetransformer_b12l_4h_b256_uncond_dr03_tpu()
hparams.learning_rate = 0.2
hparams.learning_rate_warmup_steps = 4000
hparams.layer_preprocess_sequence = "none"
hparams.layer_postprocess_sequence = "dan"
... | [
"TPU related small model."
] |
Please provide a description of the function: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 # heads are expensive on tpu
hparams.num_decoder_layers = 12
hparam... | [
"TPU config for cifar 10."
] |
Please provide a description of the function: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 # heads are expensive on tpu
hparams.num_decoder_layers = 12
hparam... | [
"TPU related 12 layer 8 heads model."
] |
Please provide a description of the function:def imagetransformer_b10l_4h_big_uncond_dr01_tpu():
hparams = imagetransformer_b12l_4h_big_uncond_dr03_tpu()
# num_hidden_layers
hparams.num_decoder_layers = 10
hparams.num_heads = 4
hparams.hidden_size = 1024
hparams.filter_size = 4096
hparams.batch_size = ... | [
"big 1d model for conditional image generation."
] |
Please provide a description of the function:def training_loop(self):
if not self.restarting:
self._write_counters(self._local_step_at_start, self._global_step)
tf.logging.info(
"Training %s up to %d, %d to go", self.model_mode,
self.target_local_step, self.steps_to_go
)
yie... | [
"Context manager wrapping the training loop, updates step counters."
] |
Please provide a description of the function:def _read_words(filename):
with tf.gfile.GFile(filename, "r") as f:
if sys.version_info[0] >= 3:
return f.read().replace("\n", " %s " % EOS).split()
else:
return f.read().decode("utf-8").replace("\n", " %s " % EOS).split() | [
"Reads words from a file."
] |
Please provide a description of the function:def _build_vocab(filename, vocab_path, vocab_size):
data = _read_words(filename)
counter = collections.Counter(data)
count_pairs = sorted(counter.items(), key=lambda x: (-x[1], x[0]))
words, _ = list(zip(*count_pairs))
words = words[:vocab_size]
with open(voca... | [
"Reads a file to build a vocabulary of `vocab_size` most common words.\n\n The vocabulary is sorted by occurrence count and has one word per line.\n Originally from:\n https://github.com/tensorflow/models/blob/master/tutorials/rnn/ptb/reader.py\n\n Args:\n filename: file to read list of words from.\n v... |
Please provide a description of the function:def _get_token_encoder(vocab_dir, vocab_name, filename):
vocab_path = os.path.join(vocab_dir, vocab_name)
if not tf.gfile.Exists(vocab_path):
_build_vocab(filename, vocab_path, 10000)
return text_encoder.TokenTextEncoder(vocab_path) | [
"Reads from file and returns a `TokenTextEncoder` for the vocabulary."
] |
Please provide a description of the function:def _maybe_download_corpus(tmp_dir, vocab_type):
filename = os.path.basename(PTB_URL)
compressed_filepath = generator_utils.maybe_download(
tmp_dir, filename, PTB_URL)
ptb_files = []
ptb_char_files = []
with tarfile.open(compressed_filepath, "r:gz") as tg... | [
"Download and unpack the corpus.\n\n Args:\n tmp_dir: directory containing dataset.\n vocab_type: which vocabulary are we using.\n\n Returns:\n The list of names of files.\n "
] |
Please provide a description of the function:def resize(att_mat, max_length=None):
for i, att in enumerate(att_mat):
# Add extra batch dim for viz code to work.
if att.ndim == 3:
att = np.expand_dims(att, axis=0)
if max_length is not None:
# Sum across different attention values for each to... | [
"Normalize attention matrices and reshape as necessary."
] |
Please provide a description of the function:def _get_attention(inp_text, out_text, enc_atts, dec_atts, encdec_atts):
def get_full_attention(layer):
enc_att = enc_atts[layer][0]
dec_att = dec_atts[layer][0]
encdec_att = encdec_atts[layer][0]
enc_att = np.transpose(enc_att, [0, 2, 1])
dec_a... | [
"Compute representation of the attention ready for the d3 visualization.\n\n Args:\n inp_text: list of strings, words to be displayed on the left of the vis\n out_text: list of strings, words to be displayed on the right of the vis\n enc_atts: numpy array, encoder self-attentions\n [num_layers, bat... |
Please provide a description of the function:def decode(tokens):
token_is_alnum = [t[0] in _ALPHANUMERIC_CHAR_SET for t in tokens]
ret = []
for i, token in enumerate(tokens):
if i > 0 and token_is_alnum[i - 1] and token_is_alnum[i]:
ret.append(u" ")
ret.append(token)
return "".join(ret) | [
"Decode a list of tokens to a unicode string.\n\n Args:\n tokens: a list of Unicode strings\n Returns:\n a unicode string\n "
] |
Please provide a description of the function:def _read_filepattern(filepattern, max_lines=None, split_on_newlines=True):
filenames = sorted(tf.gfile.Glob(filepattern))
lines_read = 0
for filename in filenames:
with tf.gfile.Open(filename) as f:
if split_on_newlines:
for line in f:
y... | [
"Reads files matching a wildcard pattern, yielding the contents.\n\n Args:\n filepattern: A wildcard pattern matching one or more files.\n max_lines: If set, stop reading after reading this many lines.\n split_on_newlines: A boolean. If true, then split files by lines and strip\n leading and traili... |
Please provide a description of the function:def corpus_token_counts(
text_filepattern, corpus_max_lines, split_on_newlines=True):
counts = collections.Counter()
for doc in _read_filepattern(
text_filepattern,
max_lines=corpus_max_lines,
split_on_newlines=split_on_newlines):
counts.upda... | [
"Read the corpus and compute a dictionary of token counts.\n\n Args:\n text_filepattern: A pattern matching one or more files.\n corpus_max_lines: An integer; maximum total lines to read.\n split_on_newlines: A boolean. If true, then split files by lines and strip\n leading and trailing whitespace ... |
Please provide a description of the function:def vocab_token_counts(text_filepattern, max_lines):
ret = {}
for i, line in enumerate(
_read_filepattern(text_filepattern, max_lines=max_lines)):
if "," not in line:
tf.logging.warning("Malformed vocab line #%d '%s'", i, line)
continue
toke... | [
"Read a vocab file and return a dictionary of token counts.\n\n Reads a two-column CSV file of tokens and their frequency in a dataset. The\n tokens are presumed to be generated by encode() or the equivalent.\n\n Args:\n text_filepattern: A pattern matching one or more files.\n max_lines: An integer; maxim... |
Please provide a description of the function:def _make_example(input_ids, problem, input_feature_name="inputs"):
features = {
input_feature_name:
tf.train.Feature(int64_list=tf.train.Int64List(value=input_ids))
}
# Fill in dummy values for any other required features that presumably
# will n... | [
"Make a tf.train.Example for the problem.\n\n features[input_feature_name] = input_ids\n\n Also fills in any other required features with dummy values.\n\n Args:\n input_ids: list<int>.\n problem: Problem.\n input_feature_name: name of feature for input_ids.\n\n Returns:\n tf.train.Example\n "
] |
Please provide a description of the function:def make_grpc_request_fn(servable_name, server, timeout_secs):
stub = _create_stub(server)
def _make_grpc_request(examples):
request = predict_pb2.PredictRequest()
request.model_spec.name = servable_name
request.inputs["input"].CopyFrom(
tf.m... | [
"Wraps function to make grpc requests with runtime args.",
"Builds and sends request to TensorFlow model server."
] |
Please provide a description of the function:def make_cloud_mlengine_request_fn(credentials, model_name, version):
def _make_cloud_mlengine_request(examples):
api = discovery.build("ml", "v1", credentials=credentials)
parent = "projects/%s/models/%s/versions/%s" % (cloud.default_project(),
... | [
"Wraps function to make CloudML Engine requests with runtime args.",
"Builds and sends requests to Cloud ML Engine."
] |
Please provide a description of the function:def predict(inputs_list, problem, request_fn):
assert isinstance(inputs_list, list)
fname = "inputs" if problem.has_inputs else "targets"
input_encoder = problem.feature_info[fname].encoder
input_ids_list = [
_encode(inputs, input_encoder, add_eos=problem.ha... | [
"Encodes inputs, makes request to deployed TF model, and decodes outputs."
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.