References:
https://rpubs.com/ppaquay/65557
https://raw.githubusercontent.com/asadoughi/stat-learning/master/ch2/answers
# Generalized Matrix Factorization | |
def GMF(num_users, num_items, k, reg): | |
"""Models the interaction between user/item LV w/ linear dot-product""" | |
print("using dot-product interaction term") | |
seed = 1 | |
uid = Input((1,), name="uid") | |
iid = Input((1,), name="iid") | |
item_bias = Embedding( |
def bpr_mf(user_count, item_count, hidden_dim): | |
u = tf.placeholder(tf.int32, [None]) | |
i = tf.placeholder(tf.int32, [None]) | |
j = tf.placeholder(tf.int32, [None]) | |
with tf.device("/cpu:0"): | |
user_emb_w = tf.get_variable("user_emb_w", [user_count+1, hidden_dim], | |
initializer=tf.random_normal_initializer(0, 0.1)) | |
item_emb_w = tf.get_variable("item_emb_w", [item_count+1, hidden_dim], | |
initializer=tf.random_normal_initializer(0, 0.1)) |
import tensorflow as tf | |
from tensorflow.python.framework import ops | |
from tensorflow.python.ops import math_ops | |
from tensorflow.python.eager import context | |
def cyclic_learning_rate(global_step, | |
learning_rate=0.01, | |
max_lr=0.1, | |
step_size=20., | |
gamma=0.99994, |
import pandas as pd | |
import tensorflow as tf | |
import dask.dataframe as dd | |
from dask.distributed import Client, LocalCluster | |
from tensorflow.python.saved_model import loader | |
def encode_factory(sess, export_path:str): | |
"""Loads TF SavedModel and returns a callable""" | |
def plot_confusion_matrix(y_true, y_pred, classes, | |
normalize=False, | |
title=None, | |
cmap=plt.cm.Blues): | |
""" | |
This function prints and plots the confusion matrix. | |
Normalization can be applied by setting `normalize=True`. | |
""" | |
if not title: | |
if normalize: |
"""Checks if a set of TFRecords appear to be valid. | |
Specifically, this checks whether the provided record sizes are consistent and | |
that the file does not end in the middle of a record. It does not verify the | |
CRCs. | |
""" | |
import struct | |
from multiprocessing import Pool | |
import tensorflow as tf |
A common method to rank a set of items is to pass all items through a scoring function and then sorting the scores to get an overall rank. Traditionally this space has been domianted by ordinal regression techniques on point-wise data. However, there are serious advantages to exploit by learning a scoring function on pair-wise data instead. This technique commonly called RankNet was originally explored by the seminal Learning to Rank by Gradient Descent[^1] paper by Microsoft.
In this talk we will discuss:
Theory behind point-wise and pair-wise data
Ordinal Regression: ranking point-wise data
how to crowd-source pair-wise data
The saved model CLI can't handle string input w/ the input_examples
flag RE: tensorflow/tensorflow#27662 :
saved_model_cli run \
--dir . \
--tag_set serve \
--signature_def predict \
--input_examples 'examples=[{"menu_item":["this is a sentence"]}]'
import org.tensorflow.Graph; | |
import org.tensorflow.Session; | |
import org.tensorflow.Tensor; | |
import org.tensorflow.Tensors; | |
import org.tensorflow.TensorFlow; | |
import org.tensorflow.SavedModelBundle; | |
import org.tensorflow.SavedModelBundle.Loader; | |
import org.tensorflow.framework.SignatureDef; | |
import org.tensorflow.framework.MetaGraphDef; | |
import org.tensorflow.framework.TensorInfo; |