
    6biH                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJs  Jr	  SSK
Jr  SSKJr  SSKJr  SS	KJr  \" S
/S9 " S S\R&                  5      5       rg)zHA layer that produces a dense `Tensor` based on given `feature_columns`.    )absolute_import)division)print_functionN)backend)base_feature_layer)
json_utils)keras_exportzkeras.layers.DenseFeatures)v1c                   l   ^  \ rS rSrSr   S	U 4S jjr\S 5       r\U 4S j5       rS r	S
S jr
SrU =r$ )DenseFeatures!   a  A layer that produces a dense `Tensor` based on given `feature_columns`.

Generally a single example in training data is described with
FeatureColumns.  At the first layer of the model, this column-oriented data
should be converted to a single `Tensor`.

This layer can be called multiple times with different features.

This is the V1 version of this layer that uses variable_scope's or
partitioner to create variables which works well with PartitionedVariables.
Variable scopes are deprecated in V2, so the V2 version uses name_scopes
instead. But currently that lacks support for partitioned variables. Use
this if you need partitioned variables. Use the partitioner argument if you
have a TF-Keras model and uses
`tf.compat.v1.keras.estimator.model_to_estimator` for training.

Example:

```python
price = tf.feature_column.numeric_column('price')
keywords_embedded = tf.feature_column.embedding_column(
    tf.feature_column.categorical_column_with_hash_bucket("keywords", 10K),
    dimension=16)
columns = [price, keywords_embedded, ...]
partitioner = tf.compat.v1.fixed_size_partitioner(num_shards=4)
feature_layer = tf.compat.v1.keras.layers.DenseFeatures(
    feature_columns=columns, partitioner=partitioner)

features = tf.io.parse_example(
    ..., features=tf.feature_column.make_parse_example_spec(columns))
dense_tensor = feature_layer(features)
for units in [128, 64, 32]:
  dense_tensor = tf.compat.v1.keras.layers.Dense(
                     units, activation='relu')(dense_tensor)
prediction = tf.compat.v1.keras.layers.Dense(1)(dense_tensor)
```
c           	      v   > [         TU ]  " SUUUU[        R                  R                  R
                  S.UD6  g)a  Constructs a DenseFeatures layer.

Args:
  feature_columns: An iterable containing the FeatureColumns to use as
    inputs to your model. All items should be instances of classes
    derived from `DenseColumn` such as `numeric_column`,
    `embedding_column`, `bucketized_column`, `indicator_column`. If you
    have categorical features, you can wrap them with an
    `embedding_column` or `indicator_column`.
  trainable:  Boolean, whether the layer's variables will be updated via
    gradient descent during training.
  name: Name to give to the DenseFeatures.
  partitioner: Partitioner for input layer. Defaults to `None`.
  **kwargs: Keyword arguments to construct a layer.

Raises:
  ValueError: if an item in `feature_columns` is not a `DenseColumn`.
)feature_columns	trainablenamepartitionerexpected_column_typeN )super__init__tf__internal__feature_columnDenseColumn)selfr   r   r   r   kwargs	__class__s         d/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/feature_column/dense_features.pyr   DenseFeatures.__init__I   s@    4 	 	
+#!#!?!?!K!K	
 	
    c                     g)NTr   )r   s    r   _is_feature_layerDenseFeatures._is_feature_layerl   s    r    c                    > [         R                  " [        TU ]  5      nSUS'   [         R                  " U[
        R                  S9$ )zString stored in metadata field in the SavedModel proto.

Returns:
  A serialized JSON storing information necessary for recreating this
  layer.
Tr"   )default)jsonloadsr   _tracking_metadatadumpsr   get_json_type)r   metadatar   s     r   r(    DenseFeatures._tracking_metadatap   s:     ::eg89(,$%zz(J,D,DEEr    c                     US   U4$ )Nr   r   )r   input_shapetotal_elementss      r   _target_shapeDenseFeatures._target_shape|   s    A//r    c                 h   Uc  [         R                  " 5       n[        U[        5      (       d  [	        SU5      e[
        R                  R                  R                  U5      n/ nU R                   Hq  n[         R                  " UR                  5          UR                  UU R                  US9nU R                  Xg5      nUb  XU'   UR!                  U5        SSS5        Ms     U R#                  U5      $ ! [         a    UR                  X@R                  5      n Nmf = f! , (       d  f       M  = f)a>  Returns a dense tensor corresponding to the `feature_columns`.

Example usage:

>>> t1 = tf.feature_column.embedding_column(
...    tf.feature_column.categorical_column_with_hash_bucket("t1", 2),
...    dimension=8)
>>> t2 = tf.feature_column.numeric_column('t2')
>>> feature_layer = tf.compat.v1.keras.layers.DenseFeatures([t1, t2])
>>> features = {"t1": tf.constant(["a", "b"]),
...             "t2": tf.constant([1, 2])}
>>> dense_tensor = feature_layer(features, training=True)

Args:
  features: A mapping from key to tensors. `FeatureColumn`s look up via
    these keys. For example `numeric_column('price')` will look at
    'price' key in this dict. Values can be a `SparseTensor` or a
    `Tensor` depends on corresponding `FeatureColumn`.
  cols_to_output_tensors: If not `None`, this will be filled with a dict
    mapping feature columns to output tensors created.
  training: Python boolean or None, indicating whether to the layer is
    being run in training mode. This argument is passed to the call
    method of any `FeatureColumn` that takes a `training` argument. For
    example, if a `FeatureColumn` performed dropout, the column could
    expose a `training` argument to control whether the dropout should
    be applied. If `None`, becomes `tf.keras.backend.learning_phase()`.
    Defaults to `None`.


Returns:
  A `Tensor` which represents input layer of a model. Its shape
  is (batch_size, first_layer_dimension) and its dtype is `float32`.
  first_layer_dimension is determined based on given `feature_columns`.

Raises:
  ValueError: If features are not a dictionary.
Nz/We expected a dictionary here. Instead we got: )training)r   learning_phase
isinstancedict
ValueErrorr   r   r   FeatureTransformationCache_feature_columns
name_scoper   get_dense_tensor_state_manager	TypeError_process_dense_tensorappend_verify_and_concat_tensors)	r   featurescols_to_output_tensorsr3   transformation_cacheoutput_tensorscolumntensorprocessed_tensorss	            r   callDenseFeatures.call   s'   L --/H(D))A8  OO**EEhO 	 ++F##FKK0	#44,++!) 5 F %)$>$>v$N!)55F62%%&78 10 ,  ..~>> ! #44,.A.AF 10s0   D"C71)D"7%DD"DD""
D1	r   )TNN)NN)__name__
__module____qualname____firstlineno____doc__r   propertyr"   r(   r0   rH   __static_attributes____classcell__)r   s   @r   r   r   !   sU    $R !
F   	F 	F0@? @?r    r   )rN   
__future__r   r   r   r&   tensorflow.compat.v2compatv2r   tf_keras.srcr   tf_keras.src.feature_columnr   kfc&tf_keras.src.saving.legacy.saved_modelr    tensorflow.python.util.tf_exportr	   _BaseFeaturesLayerr   r   r    r   <module>r\      sX    O &  %  ! !   A = : ./0]?C** ]? 1]?r    