Skip to content

Instantly share code, notes, and snippets.

View JasonTam's full-sized avatar
🍣
⊂(´・◡・⊂ )∘˚˳°

Jason Tam JasonTam

🍣
⊂(´・◡・⊂ )∘˚˳°
View GitHub Profile
@JasonTam
JasonTam / neg_samp.py
Last active February 28, 2018 03:37
vectorized negative sampling for sparse positive interactions
"""
Pretty efficient way to sample negatives using binary search.
Imagine `pos_inds` are items a user has interacted with,
and we want a vectorized approach to uniformly sample many negative items.
This is better than (in the case where `n_samp` is large)
sampling from the entire catalog and then checking if it's a positive item.
Ahem... negative sampling for sparse interaction matrices.
"""
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JasonTam
JasonTam / tf_inspect_checkpoint_example.py
Created May 30, 2018 18:17
exmaple of how to inspect the contents of a tensorflow V2 checkpoint
from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file
print_tensors_in_checkpoint_file(
file_name='/tmp/tensorboard-logs/tophat-movielens/20180530T140423/model.ckpt',
tensor_name=None, all_tensors=False,
all_tensor_names=True,
)
@JasonTam
JasonTam / printer_shit
Created June 23, 2018 21:00
brother hl-2140 printer struggles
Brother HL-2140 Foomatic/hpijs-pcl5e
sudo apt-get install hpijs-ppds printer-driver-hpijs
@JasonTam
JasonTam / spark_date_filter.scala
Created July 31, 2018 18:19
filter by days prior to today
val nDays = 450
df
.withColumn("date_merge", concat_ws("-", $"year", $"month", $"day"))
.withColumn("date", to_date(unix_timestamp($"date_merge", "yyyy-MM-dd").cast("timestamp")))
.drop("date_merge")
.where($"date" >= date_add(current_date(), -nDays)))
@JasonTam
JasonTam / tf_serving.conf
Created August 27, 2018 19:42
example of a config file for tensorflow-serving to serve up multiple models
model_config_list: {
config: {
name: "bag",
base_path: "s3://.../bag_model",
model_platform: "tensorflow",
model_version_policy: {
all: {}
}
},
config: {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JasonTam
JasonTam / shap_order.ipynb
Created November 5, 2018 02:08
custom strftime xticks and ordering keys for shap forceplot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
["a1", "a2", "a3", "a4", "a5", "a6"]
["b1", "b2", "b3", "b4", "b5", "b6"]