tf.contrib.estimator.forward_features
Stay organized with collections
Save and categorize content based on your preferences.
Forward features to predictions dictionary.
tf.contrib.estimator.forward_features(
estimator, keys=None, sparse_default_values=None
)
In some cases, user wants to see some of the features in estimators prediction
output. As an example, consider a batch prediction service: The service simply
runs inference on the users graph and returns the results. Keys are essential
because there is no order guarantee on the outputs so they need to be rejoined
to the inputs via keys or transclusion of the inputs in the outputs.
Example:
def input_fn():
features, labels = ...
features['unique_example_id'] = ...
features, labels
estimator = tf.estimator.LinearClassifier(...)
estimator = tf.contrib.estimator.forward_features(
estimator, 'unique_example_id')
estimator.train(...)
assert 'unique_example_id' in estimator.predict(...)
Args:
estimator: A tf.estimator.Estimator
object.
keys: A string
or a list
of string
. If it is None
, all of the
features
in dict
is forwarded to the predictions
. If it is a
string
, only given key is forwarded. If it is a list
of strings, all
the given keys
are forwarded.
sparse_default_values: A dict of str
keys mapping the name of the sparse
features to be converted to dense, to the default value to use. Only
sparse features indicated in the dictionary are converted to dense and the
provided default value is used.
Raises |
ValueError
|
- if
keys is already part of predictions . We don't allow
override.
- if 'keys' does not exist in
features .
|
TypeError
|
if keys type is not one of string or list/tuple of string .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.estimator.forward_features\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/estimator/tree/master/tensorflow_estimator/contrib/estimator/python/estimator/extenders.py) |\n\nForward features to predictions dictionary. \n\n tf.contrib.estimator.forward_features(\n estimator, keys=None, sparse_default_values=None\n )\n\nIn some cases, user wants to see some of the features in estimators prediction\noutput. As an example, consider a batch prediction service: The service simply\nruns inference on the users graph and returns the results. Keys are essential\nbecause there is no order guarantee on the outputs so they need to be rejoined\nto the inputs via keys or transclusion of the inputs in the outputs.\nExample: \n\n def input_fn():\n features, labels = ...\n features['unique_example_id'] = ...\n features, labels\n estimator = tf.estimator.LinearClassifier(...)\n estimator = tf.contrib.estimator.forward_features(\n estimator, 'unique_example_id')\n estimator.train(...)\n assert 'unique_example_id' in estimator.predict(...)\n\nArgs:\nestimator: A [`tf.estimator.Estimator`](../../../tf/estimator/Estimator) object.\nkeys: A `string` or a `list` of `string`. If it is `None`, all of the\n`features` in `dict` is forwarded to the `predictions`. If it is a\n`string`, only given key is forwarded. If it is a `list` of strings, all\nthe given `keys` are forwarded.\nsparse_default_values: A dict of `str` keys mapping the name of the sparse\nfeatures to be converted to dense, to the default value to use. Only\nsparse features indicated in the dictionary are converted to dense and the\nprovided default value is used.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A new [`tf.estimator.Estimator`](../../../tf/estimator/Estimator) which forwards features to predictions. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | \u003cbr /\u003e - if `keys` is already part of `predictions`. We don't allow override. - if 'keys' does not exist in `features`. |\n| `TypeError` | if `keys` type is not one of `string` or list/tuple of `string`. |"]]