
    BVhq                         d 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
 ddl	mZ dd	lmZ dd
lmZ ddlmZ  G d dej$                        Z ed       ej(                  dd      dd              Zy)z/Experimental `dataset` API for parsing example.    )dataset_ops)	structure)dtypes)sparse_tensor)tensor_spec)gen_experimental_dataset_ops)parsing_ops)ragged_tensor)deprecation)	tf_exportc                   2     e Zd ZdZ fdZed        Z xZS )_ParseExampleDatasetz@A `Dataset` that parses `example` dataset into a `dict` dataset.c           	      n   || _         t        j                  |j                  t	        j
                  d gt        j                              st        d|j                   d      || _	        |d| _
        n|rd| _
        nd| _
        t        j                  |      | _        t        j                  j                  | j                  t        j                   t        j"                  t        j$                  t        j&                  t        j(                  g      }|j*                  | _        |j.                  | _        |j2                  | _        |j6                  | _        |j:                  | _        |j>                  | _         |jB                  | _"        |jF                  | _$        |jJ                  | _&        tO        jP                  | j                         }i | _)        tU        |j*                  |j.                        D ]8  \  }}tW        jX                  |j[                  d g      |      | jR                  |<   : tU        |j>                  |jJ                  |j\                        D ]8  \  }}}	t	        j
                  |j[                  |	      |      | jR                  |<   : tU        |j2                  |j6                  |j:                        D ];  \  }}}
t_        j`                  |j[                  d g      |d|
      | jR                  |<   = tc        jd                  | j                   jf                  | j                  | jD                  | j,                  | j@                  | j0                  | jH                  f| j                  | j4                  | j8                  | j<                  d| jh                  }tj        tl        |   ||       y )NzHInput dataset should be a dataset of vectors of strings. Instead it is `z`.defaulttruefalse   )deterministicragged_keysragged_value_typesragged_split_types)8_input_datasetr   are_compatibleelement_specr   
TensorSpecr   string	TypeError_num_parallel_calls_deterministicr	   _prepend_none_dimension	_features_ParseOpParamsfrom_featuresVarLenFeatureSparseFeatureFixedLenFeatureFixedLenSequenceFeatureRaggedFeaturesparse_keys_sparse_keyssparse_types_sparse_typesr   _ragged_keysr   _ragged_value_typesr   _ragged_split_types
dense_keys_dense_keysdense_defaults_vec_dense_defaultsdense_shapes_as_proto_dense_shapesdense_types_dense_typesr   get_legacy_output_shapes_element_speczipr   SparseTensorSpecconcatenatedense_shapesr
   RaggedTensorSpecr   parse_example_dataset_v2_variant_tensor_flat_structuresuperr   __init__)selfinput_datasetfeaturesnum_parallel_callsr   paramsinput_dataset_shapekey
value_typedense_shapesplits_typevariant_tensor	__class__s               c/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/data/experimental/ops/parsing_ops.pyrC   z_ParseExampleDataset.__init__   sa   'D##""vv}}57  11>1K1K0LBP Q Q1D%d	"d#d 88BDN''55dnn!!;#<#<##[%H%H!!G F **D,,D**D%88D%88D((D!44D55D**D%>> D !3!3V5H5HI ?j - > >

)
)4&
1:!?d? +.f.?.?.4.@.@.4.A.A+C D&j+ !, 6 6

)
)+
6
!DdD +.f.@.@.4.G.G.4.G.G+I O&j+ !. > >

)
)4&
1:q+!OdO 	%==//$$  	$ --))#77#77	$ ""	$  

.}nM    c                     | j                   S N)r9   )rD   s    rP   r   z!_ParseExampleDataset.element_specd   s    rQ   )__name__
__module____qualname____doc__rC   propertyr   __classcell__)rO   s   @rP   r   r      s"    HCNJ  rQ   r   z'data.experimental.parse_example_datasetNz<Use `tf.data.Dataset.map(tf.io.parse_example(...))` instead.c                 4      t        d       fd}|S )a9  A transformation that parses `Example` protos into a `dict` of tensors.

  Parses a number of serialized `Example` protos given in `serialized`. We refer
  to `serialized` as a batch with `batch_size` many entries of individual
  `Example` protos.

  This op parses serialized examples into a dictionary mapping keys to `Tensor`,
  `SparseTensor`, and `RaggedTensor` objects. `features` is a dict from keys to
  `VarLenFeature`, `RaggedFeature`, `SparseFeature`, and `FixedLenFeature`
  objects. Each `VarLenFeature` and `SparseFeature` is mapped to a
  `SparseTensor`; each `RaggedFeature` is mapped to a `RaggedTensor`; and each
  `FixedLenFeature` is mapped to a `Tensor`. See `tf.io.parse_example` for more
  details about feature dictionaries.

  Args:
   features: A `dict` mapping feature keys to `FixedLenFeature`,
     `VarLenFeature`, `RaggedFeature`, and `SparseFeature` values.
   num_parallel_calls: (Optional.) A `tf.int32` scalar `tf.Tensor`,
      representing the number of parsing processes to call in parallel.
   deterministic: (Optional.) A boolean controlling whether determinism
      should be traded for performance by allowing elements to be produced out
      of order if some parsing calls complete faster than others. If
      `deterministic` is `None`, the
      `tf.data.Options.deterministic` dataset option (`True` by default) is used
      to decide whether to produce elements deterministically.

  Returns:
    A dataset transformation function, which can be passed to
    `tf.data.Dataset.apply`.

  Raises:
    ValueError: if features argument is None.
  z3Argument `features` is required, but not specified.c                     t        |       }t        d j                         D              r|j                  fd      }|S )zEFunction from `Dataset` to `Dataset` that applies the transformation.c              3      K   | ]:  }t        |t        j                        xs t        |t        j                         < y wrS   )
isinstancer	   r%   r(   ).0features     rP   	<genexpr>z;parse_example_dataset.<locals>._apply_fn.<locals>.<genexpr>   sA      *  	7K556 	77K556	7*s   A Ac                 0    t        j                  |       S rS   )r	   )_construct_tensors_for_composite_features)xrF   s    rP   <lambda>z:parse_example_dataset.<locals>._apply_fn.<locals>.<lambda>   s    KII rQ   )rG   )r   anyvaluesmap)datasetout_datasetr   rF   rG   s     rP   	_apply_fnz(parse_example_dataset.<locals>._apply_fn   sZ    &w:L'46K
 *  (* *  OO/ $ 1k rQ   )
ValueError)rF   rG   r   rj   s   ``` rP   parse_example_datasetrl   i   s%    J 
J
KK  
rQ   )r   N)rW   tensorflow.python.data.opsr   tensorflow.python.data.utilr   tensorflow.python.frameworkr   r   r   tensorflow.python.opsr   r	   tensorflow.python.ops.raggedr
   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   UnaryDatasetr   
deprecatedrl    rQ   rP   <module>rw      st    6 2 1 . 5 3 > - 6 . 6J;33 JZ 45
HJ5J 65rQ   