Returns a `Tensor` for the given key. A `str` key is used to access a base feature (not-transformed). When a `_FeatureColumn` is passed, the transformed feature is returned if it already exists, otherwise the given `_FeatureColumn` is asked to provide its transformed output, which i
(self, key)
| 2193 | self._adaptive_mask_tensors = adaptive_mask_tensors |
| 2194 | |
| 2195 | def get(self, key): |
| 2196 | """Returns a `Tensor` for the given key. |
| 2197 | |
| 2198 | A `str` key is used to access a base feature (not-transformed). When a |
| 2199 | `_FeatureColumn` is passed, the transformed feature is returned if it |
| 2200 | already exists, otherwise the given `_FeatureColumn` is asked to provide its |
| 2201 | transformed output, which is then cached. |
| 2202 | |
| 2203 | Args: |
| 2204 | key: a `str` or a `_FeatureColumn`. |
| 2205 | |
| 2206 | Returns: |
| 2207 | The transformed `Tensor` corresponding to the `key`. |
| 2208 | |
| 2209 | Raises: |
| 2210 | ValueError: if key is not found or a transformed `Tensor` cannot be |
| 2211 | computed. |
| 2212 | """ |
| 2213 | if key in self._feature_tensors: |
| 2214 | # FeatureColumn is already transformed or converted. |
| 2215 | return self._feature_tensors[key] |
| 2216 | |
| 2217 | if key in self._features: |
| 2218 | feature_tensor = self._get_raw_feature_as_tensor(key) |
| 2219 | self._feature_tensors[key] = feature_tensor |
| 2220 | return feature_tensor |
| 2221 | |
| 2222 | if isinstance(key, six.string_types): |
| 2223 | raise ValueError('Feature {} is not in features dictionary.'.format(key)) |
| 2224 | |
| 2225 | if not isinstance(key, _FeatureColumn): |
| 2226 | raise TypeError('"key" must be either a "str" or "_FeatureColumn". ' |
| 2227 | 'Provided: {}'.format(key)) |
| 2228 | |
| 2229 | column = key |
| 2230 | logging.debug('Transforming feature_column %s.', column) |
| 2231 | if self._adaptive_mask_tensors is not None and column.name in self._adaptive_mask_tensors: |
| 2232 | column.set_adaptive_mask_tensor(self._adaptive_mask_tensors[column.name]) |
| 2233 | transformed = column._transform_feature(self) # pylint: disable=protected-access |
| 2234 | if transformed is None: |
| 2235 | raise ValueError('Column {} is not supported.'.format(column.name)) |
| 2236 | self._feature_tensors[column] = transformed |
| 2237 | return transformed |
| 2238 | |
| 2239 | def _get_raw_feature_as_tensor(self, key): |
| 2240 | """Gets the raw_feature (keyed by `key`) as `tensor`. |