For details please check this blog post
keywords: learning to rank | tensorflow | keras | custom training loop | ranknet | lambdaRank | recommendation
For details please check this blog post
keywords: learning to rank | tensorflow | keras | custom training loop | ranknet | lambdaRank | recommendation
By Adam Anderson
This write-up assumes you have an general understanding of the TensorFlow programming model, but maybe you haven't kept up to date with the latest library features/standard practices.
| import numpy as np | |
| import tensorflow as tf | |
| from tensorflow.python.layers import core as layers_core | |
| hparams = tf.contrib.training.HParams( | |
| batch_size=3, | |
| encoder_length=4, | |
| decoder_length=5, | |
| num_units=6, | |
| src_vocab_size=7, |
| """Script to illustrate usage of tf.estimator.Estimator in TF v1.3""" | |
| import tensorflow as tf | |
| from tensorflow.examples.tutorials.mnist import input_data as mnist_data | |
| from tensorflow.contrib import slim | |
| from tensorflow.contrib.learn import ModeKeys | |
| from tensorflow.contrib.learn import learn_runner | |
| # Show debugging output |
| import argparse | |
| import psutil | |
| import tensorflow as tf | |
| from typing import Dict, Any, Callable, Tuple | |
| ## Data Input Function | |
| def data_input_fn(data_param, | |
| batch_size:int=None, | |
| shuffle=False) -> Callable[[], Tuple]: | |
| """Return the input function to get the test data. |
| """Script to illustrate usage of tf.estimator.Estimator in TF v1.3""" | |
| import tensorflow as tf | |
| from tensorflow.examples.tutorials.mnist import input_data as mnist_data | |
| from tensorflow.contrib import slim | |
| from tensorflow.contrib.learn import ModeKeys | |
| from tensorflow.contrib.learn import learn_runner | |
| # Show debugging output |
| 7 | |
| 2 | |
| 1 | |
| 0 | |
| 4 | |
| 1 | |
| 4 | |
| 9 | |
| 5 | |
| 9 |
| import tensorflow as tf | |
| tf.GraphKeys.USEFUL = 'useful' | |
| saver = tf.train.import_meta_graph("./model_ex1.meta") | |
| sess = tf.Session() | |
| saver.restore(sess, "./model_ex1") | |
| var_list = tf.get_collection(tf.GraphKeys.USEFUL) | |
| v1 = var_list[0] |
| #!/usr/bin/python3 | |
| from cnn import cnn | |
| import hyperopt | |
| def objective(args): | |
| params = cnn.ExperimentParameters() |
| """Short and sweet LSTM implementation in Tensorflow. | |
| Motivation: | |
| When Tensorflow was released, adding RNNs was a bit of a hack - it required | |
| building separate graphs for every number of timesteps and was a bit obscure | |
| to use. Since then TF devs added things like `dynamic_rnn`, `scan` and `map_fn`. | |
| Currently the APIs are decent, but all the tutorials that I am aware of are not | |
| making the best use of the new APIs. | |
| Advantages of this implementation: |