Skip to content

Instantly share code, notes, and snippets.

aaa
aarp
abb
abbott
abogado
ac
academy
accenture
accountant
accountants
@DerekChia
DerekChia / gist:46a92aaf5119a1f73190454e440753e0
Created July 31, 2017 18:25 — forked from casschin/gist:1990245
Python webdriver api quick sheet
### Locating UI elements ###
# By ID
<div id="coolestWidgetEvah">...</div>
element = driver.find_element_by_id("coolestWidgetEvah")
or
from selenium.webdriver.common.by import By
element = driver.find_element(by=By.ID, value="coolestWidgetEvah")
# By class name:
@DerekChia
DerekChia / install-chrome-chromedriver-selenium-ubuntu.sh
Last active August 15, 2024 17:50
Install Chromium, ChromeDriver and Selenium on Ubuntu
#!/usr/bin/env bash
# Reference : https://gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5#file-install-sh
# Versions (Update SELENIUM_STANDALONE_VERSION to the version of your choice)
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
SELENIUM_STANDALONE_VERSION=3.13.0
SELENIUM_SUBDIR=$(echo "$SELENIUM_STANDALONE_VERSION" | cut -d"." -f-2)
# Remove existing downloads and binaries so we can start from scratch.
sudo apt-get remove google-chrome-stable
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
def generate_dataset():
x_batch = np.linspace(0, 2, 100)
y_batch = 1.5 * x_batch + np.random.randn(*x_batch.shape) * 0.2 + 0.5
return x_batch, y_batch
def linear_regression():
x = tf.placeholder(tf.float32, shape=(None, ), name='x')
y = tf.placeholder(tf.float32, shape=(None, ), name='y')
with tf.variable_scope('lreg') as scope:
w = tf.Variable(np.random.normal(), name='W')
b = tf.Variable(np.random.normal(), name='b')
y_pred = tf.add(tf.multiply(w, x), b)
@DerekChia
DerekChia / run.py
Last active November 14, 2021 23:51
def run():
x_batch, y_batch = generate_dataset()
x, y, y_pred, loss = linear_regression()
optimizer = tf.train.GradientDescentOptimizer(0.1)
train_op = optimizer.minimize(loss)
with tf.Session() as session:
session.run(tf.global_variables_initializer())
feed_dict = {x: x_batch, y: y_batch}
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
def generate_dataset():
x_batch = np.linspace(0, 2, 100)
y_batch = 1.5 * x_batch + np.random.randn(*x_batch.shape) * 0.2 + 0.5
return x_batch, y_batch
def linear_regression():
a = tf.constant([10, 20])
b = tf.constant([1.0, 2.0])
# 'fetches' can be a singleton
v = session.run(a)
# v is the numpy array [10, 20]
# 'fetches' can be a list.
v = session.run([a, b])
# v is a Python list with 2 numpy arrays: the 1-D array [10, 20] and the
# 1-D array [1.0, 2.0]
# 'fetches' can be arbitrary lists, tuples, namedtuple, dicts:
settings = {
'window_size': 2 # context window +- center word
'n': 10, # dimensions of word embeddings, also refer to size of hidden layer
'epochs': 50, # number of training epochs
'learning_rate': 0.01 # learning rate
}
@DerekChia
DerekChia / w2v_generate_training_data.py
Last active December 1, 2018 05:17
w2v_generate_training_data
text = "natural language processing and machine learning is fun and exciting"
# Note the .lower() as upper and lowercase does not matter in our implementation
# [['natural', 'language', 'processing', 'and', 'machine', 'learning', 'is', 'fun', 'and', 'exciting']]
corpus = [[word.lower() for word in text.split()]]