
    6biu                          S r SSKrSSKrSSKJr  SSKJr  SSKJ	r
  SSKJr  \" S5               SS j5       r\" S	5      SS
 j5       r\" S5      S 5       rg)z%Reuters topic classification dataset.    N)_remove_long_seq)get_file)
tf_logging)keras_exportz keras.datasets.reuters.load_datac	           
      :   SU	;   a'  [         R                  " S5        U	R                  S5      nU	(       a  [        S[	        U	5       35      eSn
[        U U
S-   SS9n [        R                  " U SS	9 nUS
   US   pSSS5        [        R                  R                  U5      n[        R                  " [        W5      5      nUR                  U5        X   nWU   nUb-  U VVs/ s H  nU/U Vs/ s H  nUU-   PM
     sn-   PM     nnnO/U(       a(  U VVs/ s H  nU Vs/ s H  nUU-   PM
     snPM     nnnU(       a  [        X<U5      u  pU(       d  [        S U 5       5      nUb8  U VVs/ s H(  nU Vs/ s H  nUUs=::  a  U:  a  O  OUOUPM     snPM*     nnnO8U VVs/ s H)  nU Vs/ s H  nUUs=::  a  U:  d  M  O  M  UPM     snPM+     nnn[        [        U5      SU-
  -  5      n[        R                   " USU SS9[        R                   " USU 5      nn[        R                   " UUS SS9[        R                   " UUS 5      nnUU4UU44$ ! , (       d  f       GN= fs  snf s  snnf s  snf s  snnf s  snf s  snnf s  snf s  snnf )a_  Loads the Reuters newswire classification dataset.

This is a dataset of 11,228 newswires from Reuters, labeled over 46 topics.

This was originally generated by parsing and preprocessing the classic
Reuters-21578 dataset, but the preprocessing code is no longer packaged
with TF-Keras. See this
[GitHub discussion](https://github.com/keras-team/tf-keras/issues/12072)
for more info.

Each newswire is encoded as a list of word indexes (integers).
For convenience, words are indexed by overall frequency in the dataset,
so that for instance the integer "3" encodes the 3rd most frequent word in
the data. This allows for quick filtering operations such as:
"only consider the top 10,000 most
common words, but eliminate the top 20 most common words".

As a convention, "0" does not stand for a specific word, but instead is used
to encode any unknown word.

Args:
  path: where to cache the data (relative to `~/.keras/dataset`).
  num_words: integer or None. Words are
      ranked by how often they occur (in the training set) and only
      the `num_words` most frequent words are kept. Any less frequent word
      will appear as `oov_char` value in the sequence data. If None,
      all words are kept. Defaults to `None`.
  skip_top: skip the top N most frequently occurring words
      (which may not be informative). These words will appear as
      `oov_char` value in the dataset. 0 means no words are
      skipped. Defaults to `0`.
  maxlen: int or None. Maximum sequence length.
      Any longer sequence will be truncated. None means no truncation.
      Defaults to `None`.
  test_split: Float between `0.` and `1.`. Fraction of the dataset to be
    used as test data. `0.2` means that 20% of the dataset is used as
    test data. Defaults to `0.2`.
  seed: int. Seed for reproducible data shuffling.
  start_char: int. The start of a sequence will be marked with this
      character. 0 is usually the padding character. Defaults to `1`.
  oov_char: int. The out-of-vocabulary character.
      Words that were cut out because of the `num_words` or
      `skip_top` limits will be replaced with this character.
  index_from: int. Index actual words with this index and higher.
  **kwargs: Used for backwards compatibility.

Returns:
  Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`.

**x_train, x_test**: lists of sequences, which are lists of indexes
  (integers). If the num_words argument was specific, the maximum
  possible index value is `num_words - 1`. If the `maxlen` argument was
  specified, the largest possible sequence length is `maxlen`.

**y_train, y_test**: lists of integer labels (1 or 0).

Note: The 'out of vocabulary' character is only used for
words that were present in the training set but are not included
because they're not making the `num_words` cut here.
Words that were not seen in the training set but are in the test set
have simply been skipped.
nb_wordszDThe `nb_words` argument in `load_data` has been renamed `num_words`.z Unrecognized keyword arguments: <https://storage.googleapis.com/tensorflow/tf-keras-datasets/reuters.npz@d6586e694ee56d7a4e65172e12b3e987c03096cb01eab99753921ef915959916origin	file_hashT)allow_picklexyNc              3   8   #    U  H  n[        U5      v   M     g 7f)N)max).0r   s     W/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/datasets/reuters.py	<genexpr>load_data.<locals>.<genexpr>   s     +1As      object)dtype)loggingwarningpop	TypeErrorstrr   nploadrandomRandomStatearangelenshuffler   r   intarray)path	num_wordsskip_topmaxlen
test_splitseed
start_charoov_char
index_fromkwargsorigin_folderfxslabelsrngindicesr   widxx_trainy_trainx_testy_tests                          r   	load_datar?      s   X V,	
 JJz*	:3v;-HII 	G  },N	D 
D	)QsVQsVF 
* ))


%CiiB GKK	BG_FBDE"Qzla8aa*na88"E	3562aq)q!q:~q)26%f&9
+++	
  
 DEE1a(a+)+Q91E 	 

 DFF2a!9!Qx18y8q8q!92F
c"gZ(
)Cxx4C9288t<WG XXbhh7&,9OFFW///K 
*	) 9E)6 F

 :Fsx   1
I#I6/I1>	I6
J!I<0J0
J:JJ(
J2JJJJ
I.1I6<JJJz%keras.datasets.reuters.get_word_indexc                     Sn[        U US-   SS9n [        U 5       n[        R                  " U5      sSSS5        $ ! , (       d  f       g= f)a0  Retrieves a dict mapping words to their index in the Reuters dataset.

Actual word indices starts from 3, with 3 indices reserved for:
0 (padding), 1 (start), 2 (oov).

E.g. word index of 'the' is 1, but the in the actual training data, the
index of 'the' will be 1 + 3 = 4. Vice versa, to translate word indices in
training data back to words using this mapping, indices need to substract 3.

Args:
    path: where to cache the data (relative to `~/.keras/dataset`).

Returns:
    The word index dictionary. Keys are word strings, values are their
    index.
r	   reuters_word_index.json 4d44cc38712099c9e383dc6e5f11a921r   N)r   openjsonr!   )r)   r3   r4   s      r   get_word_indexrE      sH    & 	G  884D
 
dqyy| 
s	   <
A
z&keras.datasets.reuters.get_label_namesc                      g)zReturns labels as a list of strings with indices matching training data.

Reference:

- [Reuters Dataset](https://martin-thoma.com/nlp-reuters/)
).cocoagrainzveg-oilearnacqwheatcopperhousingzmoney-supplycoffeesugartradereservesshipcottoncarcasscrudeznat-gascpizmoney-fxinterestgnpz	meal-feedalumoilseedgoldtinzstrategic-metal	livestockretailipiz
iron-steelrubberheatjobsleibopzincorangezpet-chemdlrgassilverwpihoglead rm       r   get_label_namesro      s    /rn   )	r
   Nr   Ng?q   r         )rA   )__doc__rD   numpyr    #tf_keras.src.preprocessing.sequencer   tf_keras.src.utils.data_utilsr   tensorflow.python.platformr   r    tensorflow.python.util.tf_exportr   r?   rE   ro   rm   rn   r   <module>ry      s    ,   @ 2 = 9 01		C0 2C0L 56 7: 676 86rn   