elmo_model = hub.Module("https://tfhub.dev/google/elmo/2", trainable=False)
def ElmoEmbedding(x):
return elmo_model(tf.squeeze(tf.cast(x, tf.string)),
signature="default", as_dict=True)["default"]
sequence_input = Input(shape=(1,), dtype=tf.string)
embedded_sequences = Lambda(ElmoEmbedding, output_shape=(1024,))(sequence_input)
...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
import gym | |
from gym import wrappers, logger | |
class RandomAgent(object): | |
"""The world's simplest agent!""" | |
def __init__(self, action_space): | |
self.action_space = action_space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Set Jetson to Max Clocks" | |
jetson_clocks | |
echo "Clear RAM" | |
sync; echo 3 > /proc/sys/vm/drop_caches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tensorflow as tf | |
gpus = tf.config.experimental.list_physical_devices('GPU') | |
if gpus: | |
for gpu in gpus: | |
tf.config.experimental.set_memory_growth(gpu, True) | |
import tensorflow_datasets | |
from transformers import BertTokenizer, TFBertForSequenceClassification, glue_convert_examples_to_features#, BertForSequenceClassification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 50.012 network lab 1 | |
# Adapted from K & R's original code | |
from socket import * | |
import sys | |
import _thread as thread | |
import os | |
import functools | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def function(arg_1, arg_2, arg_3=default_value): | |
return something |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import cv2 | |
import tensorflow as tf | |
tf.enable_eager_execution() | |
import tensorflow.keras as keras | |
from tensorflow.keras.preprocessing import image | |
import tensorflow_datasets as tfds |
Enable mixed precision via a graph rewrite.
Mixed precision is the use of both float32 and float16 data types when training a model to improve performance. This is achieved via a graph rewrite operation and a loss-scale optimizer.
Performing arithmetic operations in float16 takes advantage of specialized processing units, such as NVIDIA Tensor Cores for much higher arithmetic throughput. However, due to the smaller representable range, performing the entire training with float16 can result in gradient underflow, that is, small
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import tf.keras as keras | |
# Configure a model for categorical classification. | |
model.compile(optimizer=tf.train.RMSPropOptimizer(0.01), | |
loss=keras.losses.categorical_crossentropy, | |
metrics=[keras.metrics.categorical_accuracy]) | |
estimator = keras.estimator.model_to_estimator(model) |