Skip to content

Instantly share code, notes, and snippets.

View eggie5's full-sized avatar
💭
Working on TensorFlow Ranking

Alex Egg eggie5

💭
Working on TensorFlow Ranking
View GitHub Profile
@eggie5
eggie5 / fm.py
Created September 27, 2018 13:20
import numpy as np
from sklearn.base import BaseEstimator
from keras.layers import Input, Embedding, Dense,Flatten ,Activation, Add, Dot
from keras.models import Model
from keras.regularizers import l2 as l2_reg
from keras import initializers
import itertools
def build_model(max_features,K=8,solver='adam',l2=0.0,l2_fm = 0.0):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
## WARNING: This file is generated
#!/usr/bin/env python
"""Create a "virtual" Python installation
"""
# If you change the version here, change it in setup.py
# and docs/conf.py as well.
__version__ = "1.7.2" # following best practices
virtualenv_version = __version__ # legacy, again
@eggie5
eggie5 / tensorflow_finetune.py
Created December 11, 2017 16:15 — forked from omoindrot/tensorflow_finetune.py
Example TensorFlow script for fine-tuning a VGG model (uses tf.contrib.data)
"""
Example TensorFlow script for finetuning a VGG model on your own data.
Uses tf.contrib.data module which is in release v1.2
Based on PyTorch example from Justin Johnson
(https://gist.github.com/jcjohnson/6e41e8512c17eae5da50aebef3378a4c)
Required packages: tensorflow (v1.2)
Download the weights trained on ImageNet for VGG:
```
wget http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz
### We will try to seralize and desearlaize a graph that is using the new `get_single_element` function of the Dataset API
### You will see that it does not desearlize gracefully.
#### Part 1: Build arbitrary graph using Dataset API and new get_single_element function
import numpy as np
import tensorflow as tf
from tensorflow.contrib.data import Dataset, Iterator
# Helps visualize the steps of Viterbi.
def print_dptable(V):
print "",
for i in range(len(V)): print "%7d" % i,
print
for y in V[0].keys():
print "%.5s: " % y,
for t in range(len(V)):
print "%.7s" % ("%f" % V[t][y]),
INFO 2017-02-27 09:29:43 -0800 master-replica-0 Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla K80, pci bus id: 0000:00:04.0)
INFO 2017-02-27 10:51:58 -0800 master-replica-0 max_u_id: 6040
INFO 2017-02-27 10:51:58 -0800 master-replica-0 max_i_id: 3952
INFO 2017-02-27 10:51:58 -0800 master-replica-0 epoch: 1
INFO 2017-02-27 10:51:58 -0800 master-replica-0 bpr_loss: 0.718087361238
INFO 2017-02-27 10:51:58 -0800 master-replica-0 test_loss: 0.941205 test_auc: 0.633492314296
INFO 2017-02-27 10:51:58 -0800 master-replica-0 epoch: 2
INFO 2017-02-27 10:51:58 -0800 master-replica-0 bpr_loss: 0.706146094591
INFO 2017-02-27 10:51:58 -0800 master-replica-0 test_loss: 0.933789 test_auc: 0.701774210244
INFO 2017-02-27 10:51:58 -0800 master-replica-0 epoch: 3
@eggie5
eggie5 / recsys.md
Last active February 1, 2017 14:38

Background

Let's start by pointing out that the method usually referred to as "SVD" that is used in the context of recommendations is not strictly speaking the mathematical Singular Value Decomposition of a matrix but rather an approximate way to compute the low-rank approximation of the matrix by minimizing the squared error loss. A more accurate, albeit more generic, way to call this would be Matrix Factorization. 

SVD

The basic idea is that we want to decompose our original and very sparse matrix into two low-rank matrices that represent user factors and item factors. This is done by using an iterative approach to minimize the loss function. The most common way to do this is by using Stochastic Gradient Descent, but others such as ALS are also possible. The actual loss function to minimize includes a general bias term and  two bias for both the user and the item. 

Data

{
"expand": "full",
"id": 650669458,
"title": "Running: Trail",
"sport": 0,
"start_time": "2015-12-31T13:32:17.000Z",
"local_start_time": "2015-12-31T14:32:17.000+01:00",
"distance": 6.08037,
"duration": 2209.303,
"speed_avg": 9.90779988077688,