
    ~Wh|p                        d Z ddlmc mZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddlmZ ddlmZ  ed	 e            d
          Z G d d          Z G d d          Z edg            G d dej                              ZdS )z>FeatureSpace structured data preprocessing & encoding utility.    N)backend)
base_layer)
saving_lib)serialization_lib)
LazyLoader)keras_exportlayerszkeras.layersc                   H    e Zd ZddZed             Zd Zed             ZdS )Crossone_hotc                 v    |dvrt          d|           t          |          | _        || _        || _        d S )N>   intr   zdInvalid value for argument `output_mode`. Expected one of {'int', 'one_hot'}. Received: output_mode=)
ValueErrortuplefeature_namescrossing_dimoutput_mode)selfr   r   r   s       _/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/keras/utils/feature_space.py__init__zCross.__init__    sZ    0007)47 7  
 #=11(&    c                 6    d                     | j                  S )N_X_)joinr   r   s    r   namez
Cross.name+   s    zz$,---r   c                 ,    | j         | j        | j        dS )Nr   r   r   r   r   s    r   
get_configzCross.get_config/   s#    !/ -+
 
 	
r   c                      | di |S N r"   clsconfigs     r   from_configzCross.from_config6       s}}V}}r   Nr   )	__name__
__module____qualname__r   propertyr   r   classmethodr&   r"   r   r   r   r      sm        	' 	' 	' 	' . . X.
 
 
   [  r   r   c                   0    e Zd Zd Zd Zed             ZdS )Featurec                     |dvrt          d|           || _        t          |t                    rt	          j        |          }|| _        || _        d S )N>   r   floatr   zmInvalid value for argument `output_mode`. Expected one of {'int', 'one_hot', 'float'}. Received: output_mode=)r   dtype
isinstancedictr   deserialize_keras_objectpreprocessorr   )r   r2   r6   r   s       r   r   zFeature.__init__<   sz    9997)47 7  
 
lD)) 	,E L )&r   c                 P    | j         t          j        | j                  | j        dS )Nr2   r6   r   )r2   r   serialize_keras_objectr6   r   r   s    r   r   zFeature.get_configK   s4    Z-D!   +
 
 	
r   c                      | di |S r!   r"   r#   s     r   r&   zFeature.from_configT   r'   r   N)r)   r*   r+   r   r   r-   r&   r"   r   r   r/   r/   ;   sM        ' ' '
 
 
   [  r   r/   zkeras.utils.FeatureSpace)v1c                      e Zd ZdZed(d            Zed             Zed)d            Zed*d	            Zed)d
            Z	e	 d+d            Z
e	 	 	 	 d,d            Ze	 	 	 	 d,d            Zed-d            Zed-d            Z	 	 	 	 	 d.dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd  Zd! Zed"             Zd# Zd$ Z d% Z!d& Z"d' Z#dS )/FeatureSpacea  One-stop utility for preprocessing and encoding structured data.

    Arguments:
        feature_names: Dict mapping the names of your features to their
            type specification, e.g. `{"my_feature": "integer_categorical"}`
            or `{"my_feature": FeatureSpace.integer_categorical()}`.
            For a complete list of all supported types, see
            "Available feature types" paragraph below.
        output_mode: One of `"concat"` or `"dict"`. In concat mode, all
            features get concatenated together into a single vector.
            In dict mode, the FeatureSpace returns a dict of individually
            encoded features (with the same keys as the input dict keys).
        crosses: List of features to be crossed together, e.g.
            `crosses=[("feature_1", "feature_2")]`. The features will be
            "crossed" by hashing their combined value into
            a fixed-length vector.
        crossing_dim: Default vector size for hashing crossed features.
            Defaults to 32.
        hashing_dim: Default vector size for hashing features of type
            `"integer_hashed"` and `"string_hashed"`. Defaults to 32.
        num_discretization_bins: Default number of bins to be used for
            discretizing features of type `"float_discretized"`.
            Defaults to 32.

    **Available feature types:**

    Note that all features can be referred to by their string name,
    e.g. `"integer_categorical"`. When using the string name, the default
    argument values are used.

    ```python
    # Plain float values.
    FeatureSpace.float(name=None)

    # Float values to be preprocessed via featurewise standardization
    # (i.e. via a `keras.layers.Normalization` layer).
    FeatureSpace.float_normalized(name=None)

    # Float values to be preprocessed via linear rescaling
    # (i.e. via a `keras.layers.Rescaling` layer).
    FeatureSpace.float_rescaled(scale=1., offset=0., name=None)

    # Float values to be discretized. By default, the discrete
    # representation will then be one-hot encoded.
    FeatureSpace.float_discretized(
        num_bins, bin_boundaries=None, output_mode="one_hot", name=None)

    # Integer values to be indexed. By default, the discrete
    # representation will then be one-hot encoded.
    FeatureSpace.integer_categorical(
        max_tokens=None, num_oov_indices=1, output_mode="one_hot", name=None)

    # String values to be indexed. By default, the discrete
    # representation will then be one-hot encoded.
    FeatureSpace.string_categorical(
        max_tokens=None, num_oov_indices=1, output_mode="one_hot", name=None)

    # Integer values to be hashed into a fixed number of bins.
    # By default, the discrete representation will then be one-hot encoded.
    FeatureSpace.integer_hashed(num_bins, output_mode="one_hot", name=None)

    # String values to be hashed into a fixed number of bins.
    # By default, the discrete representation will then be one-hot encoded.
    FeatureSpace.string_hashed(num_bins, output_mode="one_hot", name=None)
    ```

    Examples:

    **Basic usage with a dict of input data:**

    ```python
    raw_data = {
        "float_values": [0.0, 0.1, 0.2, 0.3],
        "string_values": ["zero", "one", "two", "three"],
        "int_values": [0, 1, 2, 3],
    }
    dataset = tf.data.Dataset.from_tensor_slices(raw_data)

    feature_space = FeatureSpace(
        features={
            "float_values": "float_normalized",
            "string_values": "string_categorical",
            "int_values": "integer_categorical",
        },
        crosses=[("string_values", "int_values")],
        output_mode="concat",
    )
    # Before you start using the FeatureSpace,
    # you must `adapt()` it on some data.
    feature_space.adapt(dataset)

    # You can call the FeatureSpace on a dict of data (batched or unbatched).
    output_vector = feature_space(raw_data)
    ```

    **Basic usage with `tf.data`:**

    ```python
    # Unlabeled data
    preprocessed_ds = unlabeled_dataset.map(feature_space)

    # Labeled data
    preprocessed_ds = labeled_dataset.map(lambda x, y: (feature_space(x), y))
    ```

    **Basic usage with the Keras Functional API:**

    ```python
    # Retrieve a dict Keras Input objects
    inputs = feature_space.get_inputs()
    # Retrieve the corresponding encoded Keras tensors
    encoded_features = feature_space.get_encoded_features()
    # Build a Functional model
    outputs = keras.layers.Dense(1, activation="sigmoid")(encoded_features)
    model = keras.Model(inputs, outputs)
    ```

    **Customizing each feature or feature cross:**

    ```python
    feature_space = FeatureSpace(
        features={
            "float_values": FeatureSpace.float_normalized(),
            "string_values": FeatureSpace.string_categorical(max_tokens=10),
            "int_values": FeatureSpace.integer_categorical(max_tokens=10),
        },
        crosses=[
            FeatureSpace.cross(("string_values", "int_values"), crossing_dim=32)
        ],
        output_mode="concat",
    )
    ```

    **Returning a dict of integer-encoded features:**

    ```python
    feature_space = FeatureSpace(
        features={
            "string_values": FeatureSpace.string_categorical(output_mode="int"),
            "int_values": FeatureSpace.integer_categorical(output_mode="int"),
        },
        crosses=[
            FeatureSpace.cross(
                feature_names=("string_values", "int_values"),
                crossing_dim=32,
                output_mode="int",
            )
        ],
        output_mode="dict",
    )
    ```

    **Specifying your own Keras preprocessing layer:**

    ```python
    # Let's say that one of the features is a short text paragraph that
    # we want to encode as a vector (one vector per paragraph) via TF-IDF.
    data = {
        "text": ["1st string", "2nd string", "3rd string"],
    }

    # There's a Keras layer for this: TextVectorization.
    custom_layer = layers.TextVectorization(output_mode="tf_idf")

    # We can use FeatureSpace.feature to create a custom feature
    # that will use our preprocessing layer.
    feature_space = FeatureSpace(
        features={
            "text": FeatureSpace.feature(
                preprocessor=custom_layer, dtype="string", output_mode="float"
            ),
        },
        output_mode="concat",
    )
    feature_space.adapt(tf.data.Dataset.from_tensor_slices(data))
    output_vector = feature_space(data)
    ```

    **Retrieving the underlying Keras preprocessing layers:**

    ```python
    # The preprocessing layer of each feature is available in `.preprocessors`.
    preprocessing_layer = feature_space.preprocessors["feature1"]

    # The crossing layer of each feature cross is available in `.crossers`.
    # It's an instance of keras.layers.HashedCrossing.
    crossing_layer = feature_space.crossers["feature1_X_feature2"]
    ```

    **Saving and reloading a FeatureSpace:**

    ```python
    feature_space.save("myfeaturespace.keras")
    reloaded_feature_space = keras.models.load_model("myfeaturespace.keras")
    ```
    r   c                 &    t          |||          S )N)r   )r   )r$   r   r   r   s       r   crosszFeatureSpace.cross   s    ]LkJJJJr   c                 $    t          |||          S N)r/   )r$   r2   r6   r   s       r   featurezFeatureSpace.feature$  s    ulK888r   Nc                     ddl m} |pt          j        d          }|                    d| d          }t          d|d          S )Nr   )identityr1   float32_preprocessor)r2   r   r8   )keras.layers.corerD   r   unique_object_nameIdentityr/   )r$   r   rD   r6   s       r   r1   zFeatureSpace.float(  sq    ......:w1'::((T"8"8"8 ) 
 
 ,G
 
 
 	
r         ?        c                     |pt          j        d          }t                              ||| d          }t	          d|d          S )Nfloat_rescaledrF   )scaleoffsetr   rE   r1   r8   )r   rH   r	   	Rescalingr/   )r$   rN   rO   r   r6   s        r   rM   zFeatureSpace.float_rescaled4  sb    Cw12BCC''-C-C-C ( 
 
 ,G
 
 
 	
r   c                     |pt          j        d          }t                              d| d          }t	          d|d          S )Nfloat_normalizedrF   )axisr   rE   r1   r8   )r   rH   r	   Normalizationr/   )r$   r   r6   s      r   rR   zFeatureSpace.float_normalized>  s`    Ew12DEE++T000 , 
 
 ,G
 
 
 	
r   c                     |pt          j        d          }t                              ||| d          }t	          d||          S )Nfloat_discretizedrF   )num_binsbin_boundariesr   rE   r8   )r   rH   r	   Discretizationr/   )r$   rX   rY   r   r   r6   s         r   rW   zFeatureSpace.float_discretizedH  sf     Fw12EFF,,)''' - 
 

 ,K
 
 
 	
r      c                     |pt          j        d          }t                              | d||          }t	          d||          S )Ninteger_categoricalrF   r   
max_tokensnum_oov_indicesint64r8   )r   rH   r	   IntegerLookupr/   r$   r_   r`   r   r   r6   s         r   r]   z FeatureSpace.integer_categoricalV  sf     Hw12GHH++'''!+ , 
 

 +
 
 
 	
r   c                     |pt          j        d          }t                              | d||          }t	          d||          S )Nstring_categoricalrF   r^   stringr8   )r   rH   r	   StringLookupr/   rc   s         r   re   zFeatureSpace.string_categoricalh  sf     Gw12FGG**'''!+ + 
 

 ;
 
 
 	
r   c                     |pt          j        d          }t                              | d|          }t	          d||          S )Nstring_hashedrF   r   rX   rf   r8   r   rH   r	   Hashingr/   r$   rX   r   r   r6   s        r   ri   zFeatureSpace.string_hashedz  s]    Bw1/BB~~'''( & 
 
 ;
 
 
 	
r   c                     |pt          j        d          }t                              | d|          }t	          d||          S )Ninteger_hashedrF   rj   ra   r8   rk   rm   s        r   ro   zFeatureSpace.integer_hashed  s^    Cw12BCC~~'''( & 
 
 +
 
 
 	
r   concat    c                     |st          d          | _        | _        | _         fd|                                D              _        g  _        |rt          |                                          }|D ]}t          |t                    rt          j        |          }t          |t                    r j                            |           [|st          d          |D ]}	|	|vrt          d|            j                            t          ||                     d  j        D              _        |dvrt          d|           | _         fd	 j                                        D              _        d
  j                                        D              _        d  _         fd j        D              _        i  _        d _        d _        d  _        d  _        d  _        d S )Nz0The `features` argument cannot be None or empty.c                 D    i | ]\  }}|                     ||          S r"   )_standardize_feature.0r   valuer   s      r   
<dictcomp>z)FeatureSpace.__init__.<locals>.<dictcomp>  s?     
 
 
e $++D%88
 
 
r   zzWhen specifying `crosses`, the argument `crossing_dim` (dimensionality of the crossing space) should be specified as well.zwAll features referenced in the `crosses` argument should be present in the `features` dict. Received unknown features: )r   c                     i | ]
}|j         |S r"   r   )rv   r?   s     r   rx   z)FeatureSpace.__init__.<locals>.<dictcomp>  s    LLLe
ELLLr   >   r4   rp   zdInvalid value for argument `output_mode`. Expected one of {'dict', 'concat'}. Received: output_mode=c                 D    i | ]\  }}|                     ||          S r"   )_feature_to_inputru   s      r   rx   z)FeatureSpace.__init__.<locals>.<dictcomp>  s?     
 
 
e $((u55
 
 
r   c                 $    i | ]\  }}||j         S r"   )r6   )rv   r   rw   s      r   rx   z)FeatureSpace.__init__.<locals>.<dictcomp>  s.     
 
 
)4uD%$
 
 
r   c                 F    i | ]}|j                             |          S r"   )r   _cross_to_crosser)rv   r?   r   s     r   rx   z)FeatureSpace.__init__.<locals>.<dictcomp>  s8     
 
 
:?EJ..u55
 
 
r   F)r   r   hashing_dimnum_discretization_binsitemsfeaturescrossessetkeysr3   r4   r   r5   r   appendcrosses_by_namer   inputspreprocessorsencoded_featurescrossersone_hot_encodersbuilt_is_adaptedrp   _preprocessed_features_names_crossed_features_names)
r   r   r   r   r   r   r   feature_setr?   keys
   `         r   r   zFeatureSpace.__init__  s     	QOPPP(&'>$
 
 
 
'~~//
 
 
  	Qhmmoo..K  Q QeT** N-FuMMEeU++ QL''....' (;    %  k11",!F ?D!F !F# #  2 L''e,(O(O(OPPPPLLt|LLL0007)47 7  
 '
 
 
 
#}2244
 
 

 
8<8K8K8M8M
 
 
 !%
 
 
 
CG<
 
 
 !#
 ,0)'+$$$r   c                 F    t                               d|j        |          S )N)r[   )shaper2   r   )r	   Inputr2   r   r   rB   s      r   r|   zFeatureSpace._feature_to_input  s    ||$gm$|GGGr   c                    t          |t                    r|S t          |t                    rt          j        |          S |dk    r|                     |          S |dk    r|                     |          S |dk    r|                     |          S |dk    r|                     || j	                  S |dk    r| 
                    |          S |dk    r|                     |          S |d	k    r|                     | j        |          S |d
k    r|                     | j        |          S t          d|           )Nr1   rz   rR   rM   rW   rj   r]   re   ro   ri   zInvalid feature type: )r3   r/   r4   r   r5   r1   rR   rM   rW   r   r]   re   ro   r   ri   r   r   s      r   rt   z!FeatureSpace._standardize_feature  s   gw'' 	Ngt$$ 	G$=gFFFg::4:(((***((d(333(((&&D&111+++))D$@ *    ---+++666,,,***555(((&&t'7d&CCC''%%d&6T%BBB?g??@@@r   c                 N    t                               |j        |j                  S )Nrz   )r	   HashedCrossingr   r   )r   r?   s     r   r   zFeatureSpace._cross_to_crosser  s     $$U%7ej$IIIr   c                     g }| j                                         D ]V}| j        |         }t          |t          j                  r|j        1t          |d          r|                    |           W|S )Nadapt)	r   r   r   r3   r	   rU   
input_meanhasattrr   )r   adaptable_preprocessorsr   r6   s       r   _list_adaptable_preprocessorsz*FeatureSpace._list_adaptable_preprocessors  s    "$M&&(( 	5 	5D-d3L ,(<== *6|W-- 5'..t444&&r   c                 4   t          |t          j        j                  s#t	          d| dt          |           d          |                                 D ]|                    fd          }| j                 }|	                    d          D ]}|j
        j        dk    r|                    d          }|j
        j        dv r|                    d	           }|                    |           d
| _        |                                  d
| _        d S )NzE`adapt()` can only be called on a tf.data.Dataset. Received instead: 
 (of type )c                     |          S rA   r"   )xr   s    r   <lambda>z$FeatureSpace.adapt.<locals>.<lambda>  s    AdG r   r[   r   rq   >   r   r[   c                 ,    t          j        | d          S )NrS   )tfexpand_dims)r   s    r   r   z$FeatureSpace.adapt.<locals>.<lambda>!  s    bnQ33 r   T)r3   r   dataDatasetr   typer   mapr   taker   rankbatchr   r   get_encoded_featuresr   )r   datasetfeature_datasetr6   r   r   s        @r   r   zFeatureSpace.adapt  sP   '27?33 	I%,I I8<WI I I  
 6688 	0 	0D &kk*;*;*;*;<<O-d3L %))!,,  w|q  "1"7"7";";w|v%% #2"5"533# # ////!!###


r   c                 8    |                                   | j        S rA   )_check_if_builtr   r   s    r   
get_inputszFeatureSpace.get_inputs(  s    {r   c                     |                                   | j        L|                     | j                  }|                     |          }|                     ||          }|| _        | j        S rA   )_check_if_adaptedr   _preprocess_featuresr   _cross_features_merge_features)r   preprocessed_featurescrossed_featuresmerged_featuress       r   r   z!FeatureSpace.get_encoded_features,  sv        ($($=$=dk$J$J!#334IJJ"22%'7 O %4D!$$r   c                 H      fd                                 D             S )Nc                 J    i | ]}| j         |         |                    S r"   )r   )rv   r   r   r   s     r   rx   z5FeatureSpace._preprocess_features.<locals>.<dictcomp>9  sB     
 
 
 *$$T*8D>::
 
 
r   )r   )r   r   s   ``r   r   z!FeatureSpace._preprocess_features8  s<    
 
 
 
 
 
 
 
 	
r   c                     i }| j         D ]:}fd|j        D             } | j        |j                 |          }|||j        <   ;|S )Nc                      g | ]
}|         S r"   r"   )rv   r   r   s     r   
<listcomp>z0FeatureSpace._cross_features.<locals>.<listcomp>A  s    EEEhtnEEEr   )r   r   r   r   )r   r   all_outputsr?   r   outputss    `    r   r   zFeatureSpace._cross_features>  sb    \ 	. 	.EEEEE1DEEEF/dmEJ/77G&-K
##r   c                      j         sLt                                                     _         t                                                     _         j          j        z   }fd j         D             fd j        D             z   } j        dk    ri }ng } j        rt          ||          D ]S\  }} j                            |d           }	|	r |	|          } j        dk    r|||<   >|	                    |           T j        dk    r|S  
                    |          S  fd j         D              fd j        D             z   }
t          |||
          D ]\  }}}|j        j        }|j        dk    r^ j                            |          p j                            |          }d }|j        j                            d          st!          d| d	| d
          t#          |t$          j        t$          j        f          r|                                }nt#          |t$          j                  r|j        }nct#          |t$          j                  r|j        }nAt#          |t$          j        t$          j        f          r|j        }nt!          d| d          |1t$                              |d          }	|	 j        |<    |	|          } j        dk    rT|j        j        }|                    d          s|dk    rt!          d| d| d          |	                    |           |||<    j        dk    r5t$                              d           _
         
                    |          S |S )Nc                      g | ]
}|         S r"   r"   )rv   r   r   s     r   r   z0FeatureSpace._merge_features.<locals>.<listcomp>P  s.     
 
 
 "$'
 
 
r   c                      g | ]
}|         S r"   r"   )rv   r   r   s     r   r   z0FeatureSpace._merge_features.<locals>.<listcomp>S  s    MMMd#MMMr   r4   c                 *    g | ]}j         |         S r"   )r   rv   r   r   s     r   r   z0FeatureSpace._merge_features.<locals>.<listcomp>k  s-     
 
 
$(DM$
 
 
r   c                 *    g | ]}j         |         S r"   )r   r   s     r   r   z0FeatureSpace._merge_features.<locals>.<listcomp>m  s.     
 
 
+/D &
 
 
r   r   r   z	Feature 'zh' has `output_mode='one_hot'`. Thus its preprocessor should return an int64 dtype. Instead it returns a z dtype.z' has `output_mode='one_hot'`. However it isn't a standard feature and the dimensionality of its output space is not known, thus it cannot be one-hot encoded. Try using `output_mode='int'`.	multi_hot)
num_tokensr   rp   rf   z-Cannot concatenate features because feature 'z%' has not been encoded (it has dtype z'). Consider using `output_mode='dict'`.rS   rT   )r   sortedr   r   r   r   zipr   getr   rp   r2   r   r   r   
startswithr   r3   r	   rb   rg   vocabulary_sizeCategoryEncodingr   rZ   rX   r   rl   Concatenate)r   r   r   	all_namesall_featuresoutput_dictfeatures_to_concatr   rB   encoder	all_specsspecr2   r6   cardinalitys   ```            r   r   zFeatureSpace._merge_featuresF  s   0 	K06%**,,1 1D- ,22B2G2G2I2I+J+JD( -0LL 	
 
 
 
9
 
 
 NMMM0LMMMN
 v%%KK!#: 	7!$Y!=!= 7 7g/33D$?? /%gg..G#v--(/K%%&--g66666))""{{#5666
 
 
 
,0,M
 
 

 
 
 
373O
 
 

	
 $'y,	#J#J 4	, 4	,D'4M&E9,,#155     -]&&t,,  #})44U;; $?D ? ?05? ? ?    6#79L"M   #/">">"@"@KKf.EFF "."9KKf.CDD "."7KK 6#8&."I   #/"7KK$9D 9 9 9   *$55#.K 6  G 3:D)$/%gg..G8++*##E** ex.?.?$? ? ?>C? ? ?  
 #))'2222$+D!!x'' ,,",55DK;;1222r   c                 l    | j         s,|                                 s	d| _         d S t          d          d S )NTzUYou need to call `.adapt(dataset)` on the FeatureSpace before you can start using it.)r   r   r   r   s    r   r   zFeatureSpace._check_if_adapted  sP     	5577 #'    5  		 	r   c                 v    | j         s1|                                  |                                  d| _         d S d S NT)r   r   r   r   s    r   r   zFeatureSpace._check_if_built  sE    z 	""$$$%%'''DJJJ		 	r   c                 N   |                                   t          |t                    s"t          d| dt	          |                     d |                                D             }d}|                                D ]Z\  }}|j        j        dk    rt          j	        |ddg          ||<   d}2|j        j        dk    rt          j
        |d          ||<   [|                     |          }|                     |          }|                     ||          }|r| j        d	k    r)|j        d         dk    sJ t          j        |d
          S |                                D ]?\  }}|j        j        dk    r*|j        d         dk    rt          j        |d
          ||<   @|S )Nz>A FeatureSpace can only be called with a dict. Received: data=r   c                 >    i | ]\  }}|t          j        |          S r"   )r   convert_to_tensor)rv   r   rw   s      r   rx   z)FeatureSpace.__call__.<locals>.<dictcomp>  s)    PPPZS%R)%00PPPr   Fr   r[   TrS   rp   r      )r   r3   r4   r   r   r   r   r   r   reshaper   r   r   r   r   squeeze)r   r   	rebatchedr   r   preprocessed_datacrossed_datamerged_datas           r   __call__zFeatureSpace.__call__  s   $%% 	?"&? ?26t**? ?  
 QP4::<<PPP	zz|| 	3 	3GD!w|q  ZAq622T
 		""^Ar22T
 55d;;++,=>>**+<lKK 	B8++"(+q0000z+A6666*0022 B BGD!w|q((QWQZ1__,.Jqq,A,A,AD)r   c                     t          j        | j                  | j        t          j        | j                  | j        | j        | j        dS )N)r   r   r   r   r   r   )r   r9   r   r   r   r   r   r   r   s    r   r   zFeatureSpace.get_config  sI    )@OO+(?MM -+'+'C
 
 	
r   c                      | di |S r!   r"   r#   s     r   r&   zFeatureSpace.from_config  r'   r   c                 H    d | j                                         D             S )Nc                 H    i | ]\  }}||j                                          S r"   )r6   get_build_config)rv   r   rB   s      r   rx   z1FeatureSpace.get_build_config.<locals>.<dictcomp>  s=     
 
 
g '&7799
 
 
r   )r   r   r   s    r   r   zFeatureSpace.get_build_config  s1    
 
!%!4!4!6!6
 
 
 	
r   c                     |                                 D ]-}| j        |         j                            ||                    .d| _        d S r   )r   r   r6   build_from_configr   )r   r%   r   s      r   r   zFeatureSpace.build_from_config  sN    KKMM 	M 	MDM$,>>vd|LLLLr   c                 0    t          j        | |           dS )a  Save the `FeatureSpace` instance to a `.keras` file.

        You can reload it via `keras.models.load_model()`:

        ```python
        feature_space.save("myfeaturespace.keras")
        reloaded_feature_space = keras.models.load_model("myfeaturespace.keras")
        ```
        N)r   
save_model)r   filepaths     r   savezFeatureSpace.save  s     	dH-----r   c                     d S rA   r"   r   stores     r   _save_own_variablesz FeatureSpace._save_own_variables       r   c                     d S rA   r"   r   s     r   _load_own_variablesz FeatureSpace._load_own_variables  r   r   r(   rA   )rJ   rK   N)Nr   N)Nr[   r   N)r   N)rp   Nrq   rq   rq   )$r)   r*   r+   __doc__r-   r?   rB   r1   rM   rR   rW   r]   re   ri   ro   r   r|   rt   r   r   r   r   r   r   r   r   r   r   r   r   r&   r   r   r   r   r   r"   r   r   r=   r=   Y   s       C CJ K K K [K 9 9 [9 	
 	
 	
 [	
 
 
 
 [
 
 
 
 [
 HL
 
 
 [
  
 
 
 [
"  
 
 
 [
" 
 
 
 [
 
 
 
 [
  "E, E, E, E,NH H HA A A8J J J' ' '" " "H  
% 
% 
%
 
 
  d d dL      <
 
 
   [
 
 
     

. 
. 
.      r   r=   )r   tensorflow.compat.v2compatv2r   kerasr   keras.enginer   keras.savingr   r   keras.utils.generic_utilsr    tensorflow.python.util.tf_exportr   globalsr	   r   r/   Layerr=   r"   r   r   <module>r	     s^   E D ! ! ! ! ! ! ! ! !       # # # # # # # # # # # # * * * * * * 0 0 0 0 0 0 : 9 9 9 9 9	Hggii	8	8       8       < (R000j
 j
 j
 j
 j
:# j
 j
 10j
 j
 j
r   