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
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.
@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
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

{
"version": 1,
"variables": [{
"names": ["page_id"],
"values": [
["2-a"],
["35-a"],
["51-a"],
["54-a"],
["5-a"],
@eggie5
eggie5 / impl.rb
Created November 4, 2016 03:36
Pokemon Go
require "rspec/autorun"
require "singleton"
class Entity
attr_accessor :lat, :lng
def initialize(lat=0, lng=0)
self.lat = lat
self.lng = lng
require 'singleton'
class World
include Singleton
attr_accessor :creatures
def initialize
self.creatures=[]
end
end