This file contains hidden or 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
| # Read more about SSH config files: https://linux.die.net/man/5/ssh_config | |
| Host snarto_kaggle_cpu | |
| # update the instance IP under console.cloud.google.com/compute/instances -> more (...) -> network details | |
| HostName 34.170.120.99 | |
| # add the public part under console.cloud.google.com/compute/metadata | |
| IdentityFile ~/.ssh/id_rsa | |
| # match the name under the SSH key | |
| User maciej.skorski | |
| Port 22 |
This file contains hidden or 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
| # wrap the TF code to be profiled with <start> and <stop> methods as below | |
| tf.profiler.experimental.start('logs/profile') | |
| for (x,y) in data: | |
| train_step(x,y) | |
| tf.profiler.experimental.stop() |
This file contains hidden or 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
| ## train a logistic regression (images 28x28 and 10 classes) | |
| w = tf.Variable(tf.random.normal(shape=(28*28,10),stddev=0.1),trainable=True) | |
| optimizer = tf.optimizers.SGD(0.01) | |
| @tf.function | |
| def train_step(x, y): | |
| with tf.GradientTape() as tape: | |
| all_logits = tf.matmul(x,w) # (n_batch,n_class) | |
| y_logits = tf.gather(all_logits,y,batch_dims=1) # (n_batch,) |
This file contains hidden or 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 SparseCategoricalCrossentropy(labels,logits): | |
| ''' labels: shape [n_batch] contains true classes as numbers from 0 to n_classes-1 | |
| logits: shape [n_batch,n_classes], predicted log probabilities ''' | |
| Z = tf.reduce_logsumexp(logits,axis=-1) | |
| lookup_labels = tf.stack([tf.range(tf.shape(labels)[0]),tf.cast(labels,tf.int32)],1) | |
| true_logits = tf.gather_nd(logits,lookup_labels,batch_dims=0) | |
| return -true_logits + Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from itertools import islice,chain | |
| from collections import deque | |
| def gen_skipgrams(itr,window=1,symmetric=False,Q=None): | |
| itr = iter(itr) | |
| if not Q: | |
| Q = deque(islice(itr,window-1),maxlen=window) | |
| append = Q.append | |
| for i in itr: | |
| for j in Q: |
NewerOlder