
    6bib                          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g)z&IMDB sentiment classification dataset.    N)_remove_long_seq)get_file)
tf_logging)keras_exportzkeras.datasets.imdb.load_datac           
         SU;   a'  [         R                  " S5        UR                  S5      nU(       a  [        S[	        U5       S35      eSn	[        U U	S-   SS9n [        R                  " U S	S
9 n
U
S   U
S   pU
S   U
S   pSSS5        [        R                  R                  U5      n[        R                  " [        W5      5      nUR                  U5        UU   nWU   n[        R                  " [        W5      5      nUR                  U5        UU   nWU   nUbY  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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OWU(       aP  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 VVs/ s H  nU Vs/ s H  nUU-   PM
     snPM     nnnU(       aB  [        X;U5      u  p[        X=U5      u  pU(       a  U(       d  [        S[	        U5       S35      eX-   n[        R                  " X/5      nU(       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      n[        R"                  " USU SS9USU nn[        R"                  " UUS SS9UUS 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 s  snf s  snnf s  snf s  snnf )aZ
  Loads the [IMDB dataset](https://ai.stanford.edu/~amaas/data/sentiment/).

This is a dataset of 25,000 movies reviews from IMDB, labeled by sentiment
(positive/negative). Reviews have been preprocessed, and each review 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 the pad token.

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. When 0, 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`.
  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).

Raises:
  ValueError: in case `maxlen` is so low
      that no input sequence could be kept.

Note that 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/imdb.npz@69664113be75683a8fe16e3ed0ab59fda8886cb3cd7ada244f7d9544e4676b9forigin	file_hashT)allow_picklex_trainy_trainx_testy_testNz2After filtering for sequences shorter than maxlen=z(, no sequence was kept. Increase maxlen.c              3   8   #    U  H  n[        U5      v   M     g 7f)N)max).0xs     T/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/datasets/imdb.py	<genexpr>load_data.<locals>.<genexpr>   s     +1As   object)dtype)loggingwarningpop	TypeErrorstrr   nploadrandomRandomStatearangelenshuffler   
ValueErrorconcatenater   array)path	num_wordsskip_topmaxlenseed
start_charoov_char
index_fromkwargsorigin_folderfr   labels_trainr   labels_testrngindicesr   wxslabelsidxr   r   s                           r   	load_datar@      sb   L V,	
 JJz*	:3v;-qIJJ 	G  z)N	D 
D	)Q !)a	lk1X; 
* ))


%CiiG%GKKgG(LiiF$GKKG_Fg&KGNOw!J<1"=1a1z>1"==wOFLMf:,!!<!Q!j.!!<<fM	8?@1A.AqA
NA.@7=>v!1-1a1z>1-v> 0, O.v{KfDv;-GI 
 
	B^^\78F+++	
  
 FGGQ8q,9,Q8;QG 	 

 DFF2a!9!Qx18y8q8q!92F
g,Cxx4C96$3<WGXXbhh7FFW///g 
*	)  #>O!<M.@->, H

 :Fs   2L(L'4L"	L'L2 L-/	L2
L=L8!L=0
M:M	M
M"M M
MM/M3M9M
L"L'-L28L=MMMz"keras.datasets.imdb.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)aV  Retrieves a dict mapping words to their index in the IMDB dataset.

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

Returns:
    The word index dictionary. Keys are word strings, values are their
    index.

Example:

```python
# Use the default parameters to keras.datasets.imdb.load_data
start_char = 1
oov_char = 2
index_from = 3
# Retrieve the training sequences.
(x_train, _), _ = keras.datasets.imdb.load_data(
    start_char=start_char, oov_char=oov_char, index_from=index_from
)
# Retrieve the word index file mapping words to indices
word_index = keras.datasets.imdb.get_word_index()
# Reverse the word index to obtain a dict mapping indices to words
# And add `index_from` to indices to sync with `x_train`
inverted_word_index = dict(
    (i + index_from, word) for (word, i) in word_index.items()
)
# Update `inverted_word_index` to include `start_char` and `oov_char`
inverted_word_index[start_char] = "[START]"
inverted_word_index[oov_char] = "[OOV]"
# Decode the first sequence in the dataset
decoded_sequence = " ".join(inverted_word_index[i] for i in x_train[0])
```
r
   imdb_word_index.json bfafd718b763782e994055a2d397834fr   N)r   openjsonr$   )r-   r6   r7   s      r   get_word_indexrF      sI    J 	G  554D
 
dqyy| 
s	   <
A
)r   Nr   Nq            )rB   )__doc__rE   numpyr#   #tf_keras.src.preprocessing.sequencer   tf_keras.src.utils.data_utilsr   tensorflow.python.platformr   r    tensorflow.python.util.tf_exportr   r@   rF        r   <module>rS      sm    -   @ 2 = 9 -.		K0 /K0\ 23, 4,rR   