Skip to content

Instantly share code, notes, and snippets.

View hackintoshrao's full-sized avatar
📚
Exploring AI agents on code search and understanding

Karthic Rao hackintoshrao

📚
Exploring AI agents on code search and understanding
View GitHub Profile
@hackintoshrao
hackintoshrao / tensorflow_nn_msnit.py
Created June 21, 2018 04:38
MNSIT prediction building Neural Network in Tensorflow
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets(".", one_hot=True, reshape=False)
import tensorflow as tf
# Parameters
learning_rate = 0.001
training_epochs = 20
batch_size = 128 # Decrease batch size if you don't have enough memory
display_step = 1
@hackintoshrao
hackintoshrao / relu.py
Created June 21, 2018 04:35
Using RELU activation with hidden layer for tensorflow
# Quiz Solution
# Note: You can't run code in this tab
import tensorflow as tf
output = None
hidden_layer_weights = [
[0.1, 0.2, 0.4],
[0.4, 0.6, 0.6],
[0.5, 0.9, 0.1],
[0.8, 0.2, 0.8]]
@hackintoshrao
hackintoshrao / sk_one_hot.py
Created June 19, 2018 16:36
one hot encoding in sklearn
import numpy as np
from sklearn import preprocessing
# Example labels
labels = np.array([1,5,3,2,1,4,2,1,3])
# Create the encoder
lb = preprocessing.LabelBinarizer()
# Here the encoder finds the classes and assigns one-hot vectors
lb.fit(labels)
# And finally, transform the labels into one-hot encoded vectors
lb.transform(labels)
@hackintoshrao
hackintoshrao / tf_softmax.py
Last active June 19, 2018 16:42
Tensorflow softmax functions
import tensorflow as tf
output = None
logit_data = [2.0, 1.0, 0.1]
logits = tf.placeholder(tf.float32)
softmax = tf.nn.softmax(logits)
with tf.Session() as sess:
output = sess.run(softmax, feed_dict={logits: logit_data})
import numpy as np
a = np.random.randn(8)
print(a)
# Rank 1 vectors
# (8,)
print(a.shape)
@hackintoshrao
hackintoshrao / vectorize.py
Created June 9, 2018 14:06
Vectorization vs Non-vectorized dot product
import time
import numpy as np
a = np.random.randn(1000000)
b = np.random.randn(1000000)
tic = time.time()
c = np.dot(a, b)
toc = time.time()
@hackintoshrao
hackintoshrao / nginx.conf
Created May 30, 2018 05:23
Nginx config for routing
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
@hackintoshrao
hackintoshrao / istio-ingress.yaml
Created May 30, 2018 01:23
exposing the front end service via istio-ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: istio-ingress
annotations:
kubernetes.io/ingress.class: istio
spec:
rules:
- http:
paths:
def sum(values):
if not isinstance(values, collections.Iterable):
raise TypeError( parameter must be an iterable type )
total = 0
for v in values:
if not isinstance(v, (int, float)):
raise TypeError( elements must be numeric )
total = total+ v
return total
@hackintoshrao
hackintoshrao / exception_1.py
Created May 23, 2018 13:02
example for using exception
def sqrt(x):
if not isinstance(x, (int, float)):
raise TypeError( x must be numeric )
elif x < 0:
raise ValueError( x cannot be negative ) # do the real work here...