
    ##h9                     r   d Z ddlZddlZddlZddlZddlZd Zd Zd Zd Z	dZ
dZd	 Zd
 Zd7d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dZeeeeeeeeeeeeee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!e ee$e"e%e#e&e'e(e)d'Z*d(Z+d)Z,d(Z-d*Z.d+Z/d,Z0d-Z1e-e,e+e0e.e/e1d.Z2d/ Z3ddddd0d1d2ddddddd3d4Z4d8d5Z5d6 Z6y)9z3
Doc utilities: Utilities related to documentation
    Nc                     t        j                  |       ryt        j                  |       }|j                         d   }t	        |      t	        |j                               z
  }d|z   S )z^Return the indentation level of the start of the docstring of a class or function (or method).   r   )inspectisclass	getsource
splitlineslenlstrip)funcsource
first_linefunction_def_levels       S/var/www/html/sandstorm/venv/lib/python3.12/site-packages/transformers/utils/doc.pyget_docstring_indentation_levelr      s_     tt$F""$Q'JZ3z/@/@/B+CC!!!    c                        fd}|S )Nc                 j    dj                        | j                  | j                  ndz   | _        | S N )join__doc__fndocstrs    r   docstring_decoratorz1add_start_docstrings.<locals>.docstring_decorator%   s,    WWV_bjj6L

RTU
	r    r   r   s   ` r   add_start_docstringsr   $        r   c                        fd}|S )Nc                 t   d| j                   j                  d      d    d}d| d}t        |       }| j                  | j                  nd}	 t	        d |j                         D              }t        |      t        |j                               z
  }
}|d	|z   k(  re
D cg c].  }t        j                  t        j                  |      d
|z        0 }}t        j                  t        j                  |      d
|z        }dj                  |      |z   }	||	z   | _        | S # t        $ r |}Y w xY wc c}w )Nz[`.r   z`]z    The aa   forward method, overrides the `__call__` special method.

    <Tip>

    Although the recipe for forward pass needs to be defined within this function, one should call the [`Module`]
    instance afterwards instead of this since the former takes care of running the pre and post processing steps while
    the latter silently ignores them.

    </Tip>
r   c              3   H   K   | ]  }|j                         d k7  s|  yw)r   N)strip).0lines     r   	<genexpr>zUadd_start_docstrings_to_model_forward.<locals>.docstring_decorator.<locals>.<genexpr>=   s"     "cDPTPZPZP\`bPb4"cs   ""r    )__qualname__splitr   r   nextr   r	   r
   StopIterationtextwrapindentdedentr   )r   
class_nameintrocorrect_indentationcurrent_docfirst_non_emptydoc_indentationdocsdoc	docstringr   s             r   r   zBadd_start_docstrings_to_model_forward.<locals>.docstring_decorator-   s7   "////4Q78;
j\ 	* 	 >bA$&JJ$:bjj	2""cK4J4J4L"ccO!/2S9O9O9Q5RRO  a"555`fgY\HOOHOOC$8#@S:STgDgOOHOOE$:CBU<UVEGGDMK/	Y&
	  	21O	2 hs   AD$ #3D5$D21D2r   r   s   ` r   %add_start_docstrings_to_model_forwardr9   ,   s    @ r   c                        fd}|S )Nc                 j    | j                   | j                   nddj                        z   | _         | S r   )r   r   r   s    r   r   z/add_end_docstrings.<locals>.docstring_decoratorQ   s+    $&JJ$:bjjbggfoU
	r   r   r   s   ` r   add_end_docstringsr<   P   r   r   a:  
    Returns:
        [`{full_output_type}`] or `tuple(torch.FloatTensor)`: A [`{full_output_type}`] or a tuple of
        `torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
        elements depending on the configuration ([`{config_class}`]) and inputs.

a*  
    Returns:
        [`{full_output_type}`] or `tuple(tf.Tensor)`: A [`{full_output_type}`] or a tuple of `tf.Tensor` (if
        `return_dict=False` is passed or when `config.return_dict=False`) comprising various elements depending on the
        configuration ([`{config_class}`]) and inputs.

c                 \    t        j                  d|       }|dS |j                         d   S )z.Returns the indentation in the first line of tz^(\s*)\Sr   r   )researchgroups)tr?   s     r   _get_indentrB   j   s,    YY{A&F27V]]_Q%77r   c                    t        |       }g }d}| j                  d      D ]C  }t        |      |k(  r(t        |      dkD  r|j                  |dd        | d}9||dd  dz  }E |j                  |dd        t	        t        |            D ]<  }t        j                  dd||         ||<   t        j                  d	d
||         ||<   > dj                  |      S )z,Convert output_args_doc to display properly.r   
r   N   z^(\s+)(\S+)(\s+)z\1- **\2**\3z:\s*\n\s*(\S)z -- \1)rB   r*   r	   appendranger>   subr   )output_args_docr.   blockscurrent_blockr&   is         r   _convert_output_args_docrN   p   s     )FFM%%d+ 	-t&=!A%mCR01#fBKM QRz_,M	- MM-$% 3v; CFF.Kq	FF+Yq	Bq	C 99Vr   c                 h   | j                   }|j                  d      }d}|t        |      k  rFt        j                  d||         -|dz  }|t        |      k  rt        j                  d||         -|t        |      k  r#dj                  ||dz   d       }t        |      }nt        d| j                   d      | j                   d| j                   }| j                  j                  d	      rt        nt        }|j                  ||
      }||z   }	||	j                  d      }d}t        ||         dk(  r|dz  }t        ||         dk(  rt        t        ||               }
|
|k  r<d||
z
  z  }|D cg c]  }t        |      dkD  r| | n| }}dj                  |      }	|	S c c}w )zH
    Prepares the return part of the docstring using `output_type`.
    rD   r   z^\s*(Args|Parameters):\s*$N   z@No `Args` or `Parameters` section is found in the docstring of `zH`. Make sure it has docstring and contain either `Args` or `Parameters`.r"   TF)full_output_typeconfig_classr(   )r   r*   r	   r>   r?   r   rN   
ValueError__name__
__module__
startswithTF_RETURN_INTRODUCTIONPT_RETURN_INTRODUCTIONformatrB   )output_typerS   
min_indentoutput_docstringlinesrM   params_docstringrR   r1   resultr.   to_addr&   s                r   _prepare_output_docstringsrb      s    #** ""4(E	A
c%j.RYY'DeAhOW	Q c%j.RYY'DeAhOW3u:~99UAE9%5634DEN{OcOcNd eC C
 	
 &001;3G3G2HI&1&:&:&E&Ed&K"QgELL*:LVE%%F T"%(mq FA %(mq [q*+JJ/0FPUV3t9q='dBVEVYYu%FM Ws   =F/aJ  
    <Tip warning={true}>

    This example uses a random model as the real ones are all very big. To get proper results, you should use
    {real_checkpoint} instead of {fake_checkpoint}. If you get out-of-memory when loading that checkpoint, you can try
    adding `device_map="auto"` in the `from_pretrained` call.

    </Tip>
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import torch

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer(
    ...     "HuggingFace is a company based in Paris and New York", add_special_tokens=False, return_tensors="pt"
    ... )

    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits

    >>> predicted_token_class_ids = logits.argmax(-1)

    >>> # Note that tokens are classified rather then input words which means that
    >>> # there might be more predicted token classes than words.
    >>> # Multiple token classes might account for the same word
    >>> predicted_tokens_classes = [model.config.id2label[t.item()] for t in predicted_token_class_ids[0]]
    >>> predicted_tokens_classes
    {expected_output}

    >>> labels = predicted_token_class_ids
    >>> loss = model(**inputs, labels=labels).loss
    >>> round(loss.item(), 2)
    {expected_loss}
    ```
a_  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import torch

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"

    >>> inputs = tokenizer(question, text, return_tensors="pt")
    >>> with torch.no_grad():
    ...     outputs = model(**inputs)

    >>> answer_start_index = outputs.start_logits.argmax()
    >>> answer_end_index = outputs.end_logits.argmax()

    >>> predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
    >>> tokenizer.decode(predict_answer_tokens, skip_special_tokens=True)
    {expected_output}

    >>> # target is "nice puppet"
    >>> target_start_index = torch.tensor([{qa_target_start_index}])
    >>> target_end_index = torch.tensor([{qa_target_end_index}])

    >>> outputs = model(**inputs, start_positions=target_start_index, end_positions=target_end_index)
    >>> loss = outputs.loss
    >>> round(loss.item(), 2)
    {expected_loss}
    ```
a  
    Example of single-label classification:

    ```python
    >>> import torch
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")

    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits

    >>> predicted_class_id = logits.argmax().item()
    >>> model.config.id2label[predicted_class_id]
    {expected_output}

    >>> # To train a model on `num_labels` classes, you can pass `num_labels=num_labels` to `.from_pretrained(...)`
    >>> num_labels = len(model.config.id2label)
    >>> model = {model_class}.from_pretrained("{checkpoint}", num_labels=num_labels)

    >>> labels = torch.tensor([1])
    >>> loss = model(**inputs, labels=labels).loss
    >>> round(loss.item(), 2)
    {expected_loss}
    ```

    Example of multi-label classification:

    ```python
    >>> import torch
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}", problem_type="multi_label_classification")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")

    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits

    >>> predicted_class_ids = torch.arange(0, logits.shape[-1])[torch.sigmoid(logits).squeeze(dim=0) > 0.5]

    >>> # To train a model on `num_labels` classes, you can pass `num_labels=num_labels` to `.from_pretrained(...)`
    >>> num_labels = len(model.config.id2label)
    >>> model = {model_class}.from_pretrained(
    ...     "{checkpoint}", num_labels=num_labels, problem_type="multi_label_classification"
    ... )

    >>> labels = torch.sum(
    ...     torch.nn.functional.one_hot(predicted_class_ids[None, :].clone(), num_classes=num_labels), dim=1
    ... ).to(torch.float)
    >>> loss = model(**inputs, labels=labels).loss
    ```
a   
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import torch

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("The capital of France is {mask}.", return_tensors="pt")

    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits

    >>> # retrieve index of {mask}
    >>> mask_token_index = (inputs.input_ids == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]

    >>> predicted_token_id = logits[0, mask_token_index].argmax(axis=-1)
    >>> tokenizer.decode(predicted_token_id)
    {expected_output}

    >>> labels = tokenizer("The capital of France is Paris.", return_tensors="pt")["input_ids"]
    >>> # mask labels of non-{mask} tokens
    >>> labels = torch.where(inputs.input_ids == tokenizer.mask_token_id, labels, -100)

    >>> outputs = model(**inputs, labels=labels)
    >>> round(outputs.loss.item(), 2)
    {expected_loss}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import torch

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
    >>> outputs = model(**inputs)

    >>> last_hidden_states = outputs.last_hidden_state
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import torch

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> prompt = "In Italy, pizza served in formal settings, such as at a restaurant, is presented unsliced."
    >>> choice0 = "It is eaten with a fork and a knife."
    >>> choice1 = "It is eaten while held in the hand."
    >>> labels = torch.tensor(0).unsqueeze(0)  # choice0 is correct (according to Wikipedia ;)), batch size 1

    >>> encoding = tokenizer([prompt, prompt], [choice0, choice1], return_tensors="pt", padding=True)
    >>> outputs = model(**{{k: v.unsqueeze(0) for k, v in encoding.items()}}, labels=labels)  # batch size is 1

    >>> # the linear classifier still needs to be trained
    >>> loss = outputs.loss
    >>> logits = outputs.logits
    ```
a  
    Example:

    ```python
    >>> import torch
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
    >>> outputs = model(**inputs, labels=inputs["input_ids"])
    >>> loss = outputs.loss
    >>> logits = outputs.logits
    ```
aY  
    Example:

    ```python
    >>> from transformers import AutoProcessor, {model_class}
    >>> import torch
    >>> from datasets import load_dataset

    >>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True)
    >>> dataset = dataset.sort("id")
    >>> sampling_rate = dataset.features["audio"].sampling_rate

    >>> processor = AutoProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> # audio file is decoded on the fly
    >>> inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")
    >>> with torch.no_grad():
    ...     outputs = model(**inputs)

    >>> last_hidden_states = outputs.last_hidden_state
    >>> list(last_hidden_states.shape)
    {expected_output}
    ```
au  
    Example:

    ```python
    >>> from transformers import AutoProcessor, {model_class}
    >>> from datasets import load_dataset
    >>> import torch

    >>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True)
    >>> dataset = dataset.sort("id")
    >>> sampling_rate = dataset.features["audio"].sampling_rate

    >>> processor = AutoProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> # audio file is decoded on the fly
    >>> inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")
    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits
    >>> predicted_ids = torch.argmax(logits, dim=-1)

    >>> # transcribe speech
    >>> transcription = processor.batch_decode(predicted_ids)
    >>> transcription[0]
    {expected_output}

    >>> inputs["labels"] = processor(text=dataset[0]["text"], return_tensors="pt").input_ids

    >>> # compute loss
    >>> loss = model(**inputs).loss
    >>> round(loss.item(), 2)
    {expected_loss}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoFeatureExtractor, {model_class}
    >>> from datasets import load_dataset
    >>> import torch

    >>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True)
    >>> dataset = dataset.sort("id")
    >>> sampling_rate = dataset.features["audio"].sampling_rate

    >>> feature_extractor = AutoFeatureExtractor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> # audio file is decoded on the fly
    >>> inputs = feature_extractor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")

    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits

    >>> predicted_class_ids = torch.argmax(logits, dim=-1).item()
    >>> predicted_label = model.config.id2label[predicted_class_ids]
    >>> predicted_label
    {expected_output}

    >>> # compute loss - target_label is e.g. "down"
    >>> target_label = model.config.id2label[0]
    >>> inputs["labels"] = torch.tensor([model.config.label2id[target_label]])
    >>> loss = model(**inputs).loss
    >>> round(loss.item(), 2)
    {expected_loss}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoFeatureExtractor, {model_class}
    >>> from datasets import load_dataset
    >>> import torch

    >>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True)
    >>> dataset = dataset.sort("id")
    >>> sampling_rate = dataset.features["audio"].sampling_rate

    >>> feature_extractor = AutoFeatureExtractor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> # audio file is decoded on the fly
    >>> inputs = feature_extractor(dataset[0]["audio"]["array"], return_tensors="pt", sampling_rate=sampling_rate)
    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits

    >>> probabilities = torch.sigmoid(logits[0])
    >>> # labels is a one-hot array of shape (num_frames, num_speakers)
    >>> labels = (probabilities > 0.5).long()
    >>> labels[0].tolist()
    {expected_output}
    ```
a.  
    Example:

    ```python
    >>> from transformers import AutoFeatureExtractor, {model_class}
    >>> from datasets import load_dataset
    >>> import torch

    >>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True)
    >>> dataset = dataset.sort("id")
    >>> sampling_rate = dataset.features["audio"].sampling_rate

    >>> feature_extractor = AutoFeatureExtractor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> # audio file is decoded on the fly
    >>> inputs = feature_extractor(
    ...     [d["array"] for d in dataset[:2]["audio"]], sampling_rate=sampling_rate, return_tensors="pt", padding=True
    ... )
    >>> with torch.no_grad():
    ...     embeddings = model(**inputs).embeddings

    >>> embeddings = torch.nn.functional.normalize(embeddings, dim=-1).cpu()

    >>> # the resulting embeddings can be used for cosine similarity-based retrieval
    >>> cosine_sim = torch.nn.CosineSimilarity(dim=-1)
    >>> similarity = cosine_sim(embeddings[0], embeddings[1])
    >>> threshold = 0.7  # the optimal threshold is dataset-dependent
    >>> if similarity < threshold:
    ...     print("Speakers are not the same!")
    >>> round(similarity.item(), 2)
    {expected_output}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoImageProcessor, {model_class}
    >>> import torch
    >>> from datasets import load_dataset

    >>> dataset = load_dataset("huggingface/cats-image", trust_remote_code=True)
    >>> image = dataset["test"]["image"][0]

    >>> image_processor = AutoImageProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = image_processor(image, return_tensors="pt")

    >>> with torch.no_grad():
    ...     outputs = model(**inputs)

    >>> last_hidden_states = outputs.last_hidden_state
    >>> list(last_hidden_states.shape)
    {expected_output}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoImageProcessor, {model_class}
    >>> import torch
    >>> from datasets import load_dataset

    >>> dataset = load_dataset("huggingface/cats-image", trust_remote_code=True)
    >>> image = dataset["test"]["image"][0]

    >>> image_processor = AutoImageProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = image_processor(image, return_tensors="pt")

    >>> with torch.no_grad():
    ...     logits = model(**inputs).logits

    >>> # model predicts one of the 1000 ImageNet classes
    >>> predicted_label = logits.argmax(-1).item()
    >>> print(model.config.id2label[predicted_label])
    {expected_output}
    ```
)SequenceClassificationQuestionAnsweringTokenClassificationMultipleChoiceMaskedLMLMHead	BaseModelSpeechBaseModelCTCAudioClassificationAudioFrameClassificationAudioXVectorVisionBaseModelImageClassificationaI  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import tensorflow as tf

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer(
    ...     "HuggingFace is a company based in Paris and New York", add_special_tokens=False, return_tensors="tf"
    ... )

    >>> logits = model(**inputs).logits
    >>> predicted_token_class_ids = tf.math.argmax(logits, axis=-1)

    >>> # Note that tokens are classified rather then input words which means that
    >>> # there might be more predicted token classes than words.
    >>> # Multiple token classes might account for the same word
    >>> predicted_tokens_classes = [model.config.id2label[t] for t in predicted_token_class_ids[0].numpy().tolist()]
    >>> predicted_tokens_classes
    {expected_output}
    ```

    ```python
    >>> labels = predicted_token_class_ids
    >>> loss = tf.math.reduce_mean(model(**inputs, labels=labels).loss)
    >>> round(float(loss), 2)
    {expected_loss}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import tensorflow as tf

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"

    >>> inputs = tokenizer(question, text, return_tensors="tf")
    >>> outputs = model(**inputs)

    >>> answer_start_index = int(tf.math.argmax(outputs.start_logits, axis=-1)[0])
    >>> answer_end_index = int(tf.math.argmax(outputs.end_logits, axis=-1)[0])

    >>> predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
    >>> tokenizer.decode(predict_answer_tokens)
    {expected_output}
    ```

    ```python
    >>> # target is "nice puppet"
    >>> target_start_index = tf.constant([{qa_target_start_index}])
    >>> target_end_index = tf.constant([{qa_target_end_index}])

    >>> outputs = model(**inputs, start_positions=target_start_index, end_positions=target_end_index)
    >>> loss = tf.math.reduce_mean(outputs.loss)
    >>> round(float(loss), 2)
    {expected_loss}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import tensorflow as tf

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="tf")

    >>> logits = model(**inputs).logits

    >>> predicted_class_id = int(tf.math.argmax(logits, axis=-1)[0])
    >>> model.config.id2label[predicted_class_id]
    {expected_output}
    ```

    ```python
    >>> # To train a model on `num_labels` classes, you can pass `num_labels=num_labels` to `.from_pretrained(...)`
    >>> num_labels = len(model.config.id2label)
    >>> model = {model_class}.from_pretrained("{checkpoint}", num_labels=num_labels)

    >>> labels = tf.constant(1)
    >>> loss = model(**inputs, labels=labels).loss
    >>> round(float(loss), 2)
    {expected_loss}
    ```
a4  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import tensorflow as tf

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("The capital of France is {mask}.", return_tensors="tf")
    >>> logits = model(**inputs).logits

    >>> # retrieve index of {mask}
    >>> mask_token_index = tf.where((inputs.input_ids == tokenizer.mask_token_id)[0])
    >>> selected_logits = tf.gather_nd(logits[0], indices=mask_token_index)

    >>> predicted_token_id = tf.math.argmax(selected_logits, axis=-1)
    >>> tokenizer.decode(predicted_token_id)
    {expected_output}
    ```

    ```python
    >>> labels = tokenizer("The capital of France is Paris.", return_tensors="tf")["input_ids"]
    >>> # mask labels of non-{mask} tokens
    >>> labels = tf.where(inputs.input_ids == tokenizer.mask_token_id, labels, -100)

    >>> outputs = model(**inputs, labels=labels)
    >>> round(float(outputs.loss), 2)
    {expected_loss}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import tensorflow as tf

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="tf")
    >>> outputs = model(inputs)

    >>> last_hidden_states = outputs.last_hidden_state
    ```
a#  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import tensorflow as tf

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> prompt = "In Italy, pizza served in formal settings, such as at a restaurant, is presented unsliced."
    >>> choice0 = "It is eaten with a fork and a knife."
    >>> choice1 = "It is eaten while held in the hand."

    >>> encoding = tokenizer([prompt, prompt], [choice0, choice1], return_tensors="tf", padding=True)
    >>> inputs = {{k: tf.expand_dims(v, 0) for k, v in encoding.items()}}
    >>> outputs = model(inputs)  # batch size is 1

    >>> # the linear classifier still needs to be trained
    >>> logits = outputs.logits
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}
    >>> import tensorflow as tf

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="tf")
    >>> outputs = model(inputs)
    >>> logits = outputs.logits
    ```
a"  
    Example:

    ```python
    >>> from transformers import AutoProcessor, {model_class}
    >>> from datasets import load_dataset

    >>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True)
    >>> dataset = dataset.sort("id")
    >>> sampling_rate = dataset.features["audio"].sampling_rate

    >>> processor = AutoProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> # audio file is decoded on the fly
    >>> inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="tf")
    >>> outputs = model(**inputs)

    >>> last_hidden_states = outputs.last_hidden_state
    >>> list(last_hidden_states.shape)
    {expected_output}
    ```
aw  
    Example:

    ```python
    >>> from transformers import AutoProcessor, {model_class}
    >>> from datasets import load_dataset
    >>> import tensorflow as tf

    >>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True)
    >>> dataset = dataset.sort("id")
    >>> sampling_rate = dataset.features["audio"].sampling_rate

    >>> processor = AutoProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> # audio file is decoded on the fly
    >>> inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="tf")
    >>> logits = model(**inputs).logits
    >>> predicted_ids = tf.math.argmax(logits, axis=-1)

    >>> # transcribe speech
    >>> transcription = processor.batch_decode(predicted_ids)
    >>> transcription[0]
    {expected_output}
    ```

    ```python
    >>> inputs["labels"] = processor(text=dataset[0]["text"], return_tensors="tf").input_ids

    >>> # compute loss
    >>> loss = model(**inputs).loss
    >>> round(float(loss), 2)
    {expected_loss}
    ```
aq  
    Example:

    ```python
    >>> from transformers import AutoImageProcessor, {model_class}
    >>> from datasets import load_dataset

    >>> dataset = load_dataset("huggingface/cats-image", trust_remote_code=True)
    >>> image = dataset["test"]["image"][0]

    >>> image_processor = AutoImageProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = image_processor(image, return_tensors="tf")
    >>> outputs = model(**inputs)

    >>> last_hidden_states = outputs.last_hidden_state
    >>> list(last_hidden_states.shape)
    {expected_output}
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoImageProcessor, {model_class}
    >>> import tensorflow as tf
    >>> from datasets import load_dataset

    >>> dataset = load_dataset("huggingface/cats-image", trust_remote_code=True)
    >>> image = dataset["test"]["image"][0]

    >>> image_processor = AutoImageProcessor.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = image_processor(image, return_tensors="tf")
    >>> logits = model(**inputs).logits

    >>> # model predicts one of the 1000 ImageNet classes
    >>> predicted_label = int(tf.math.argmax(logits, axis=-1))
    >>> print(model.config.id2label[predicted_label])
    {expected_output}
    ```
)rc   rd   re   rf   rg   rh   ri   rj   rk   ro   rp   ar  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="jax")

    >>> outputs = model(**inputs)
    >>> logits = outputs.logits
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
    >>> inputs = tokenizer(question, text, return_tensors="jax")

    >>> outputs = model(**inputs)
    >>> start_scores = outputs.start_logits
    >>> end_scores = outputs.end_logits
    ```
a}  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("The capital of France is {mask}.", return_tensors="jax")

    >>> outputs = model(**inputs)
    >>> logits = outputs.logits
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="jax")
    >>> outputs = model(**inputs)

    >>> last_hidden_states = outputs.last_hidden_state
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> prompt = "In Italy, pizza served in formal settings, such as at a restaurant, is presented unsliced."
    >>> choice0 = "It is eaten with a fork and a knife."
    >>> choice1 = "It is eaten while held in the hand."

    >>> encoding = tokenizer([prompt, prompt], [choice0, choice1], return_tensors="jax", padding=True)
    >>> outputs = model(**{{k: v[None, :] for k, v in encoding.items()}})

    >>> logits = outputs.logits
    ```
a  
    Example:

    ```python
    >>> from transformers import AutoTokenizer, {model_class}

    >>> tokenizer = AutoTokenizer.from_pretrained("{checkpoint}")
    >>> model = {model_class}.from_pretrained("{checkpoint}")

    >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="np")
    >>> outputs = model(**inputs)

    >>> # retrieve logts for next token
    >>> next_token_logits = outputs.logits[:, -1]
    ```
)rc   rd   re   rf   rg   ri   rh   c                     |j                         D ]+  \  }}|	d|z   dz   }t        j                  d| dd|       } - | S )zo
    Removes the lines testing an output with the doctest syntax in a code sample when it's set to `None`.
    {}z\n([^\n]+)\n\s+z\nrD   )itemsr>   rI   )r8   kwargskeyvaluedoc_keys        r   filter_outputs_from_examplery   5  sX     lln L
U)c/FFogYb94K	L r   z[MASK]      )processor_class
checkpointr[   rS   maskqa_target_start_indexqa_target_end_index	model_clsmodalityexpected_outputexpected_lossreal_checkpointrevisionc                 F    	
 
	 fd}|S )Nc                    | j                   j                  d      d   n}|d d dk(  rt        }n|d d dk(  rt        }nt        }|dd}d	|v sd
|v rdk(  r|d
   }nd	|v r|d	   }nd|v r|d   }nd|v r|d   }nd|v r|d   }nd|v s|dv r|d   }nud|v sd|v r|d   }ngd|v r|d   }n]d|v r|d   }nSd|v rdk(  r|d   }nDd|v rdk(  r|d   }n5d|v rdk(  r|d   }n&d|v sd|v r|d   }nd|v r|d   }nt        d|       t        |      }	t        |z   }| j                  xs d d j                  
      z   }d nt        	      } |j                  d'i |}Bt        j                  d!      rt        d" d#      |j                  d$ d%d$ d& d%      }||z   |z   | _        | S )(Nr"   r   rF   rQ   r   Flaxz{true})model_classr|   r}   r~   r   r   r   r   r   fake_checkpointtruerc   rl   audiord   re   rf   rg   )FlaubertWithLMHeadModelXLMWithLMHeadModelrh   CausalLMrk   rm   XVectorrn   Modelrj   visionro   Encoderri   rp   z#Docstring can't be built for model )r   r   r   z^refs/pr/\\d+zThe provided revision 'zW' is incorrect. It should point to a pull request reference on the hub like 'refs/pr/6'zfrom_pretrained("z")z", revision="r   )r)   r*   TF_SAMPLE_DOCSTRINGSFLAX_SAMPLE_DOCSTRINGSPT_SAMPLE_DOCSTRINGSrT   ry   FAKE_MODEL_DISCLAIMERr   r   rb   rZ   r>   matchreplace)r   r   sample_docstrings
doc_kwargscode_samplefunc_doc
output_doc	built_docr}   rS   r   r   r   r~   r   r   r[   r|   r   r   r   r   s           r   r   z7add_code_sample_docstrings.<locals>.docstring_decoratorS  s   7@7Hboo++C03ir?d" 4!_& 6 4 '.$%:#6.*.)

 %37LP[7[aimtat+,ABK%4+,DEK K/+,?@K"k1+,ABK,+,<=K;&+9j*j+J7K$
k(A+H5Kk!+E2K';6+,FGK+%(g*=+N;K#G(;+,=>K#H(<+,=>K#yK'?+K8K"k1+,ABKB;-PQQ1
 &/+=KJJ$"7&.R4N{\h4i
&K&&44	xx((3 -hZ 8L L  "))#J<r26G
|S`ai`jjl4mI 
*Y6
	r   r   )r|   r}   r[   rS   r~   r   r   r   r   r   r   r   r   r   r   s   `````````````` r   add_code_sample_docstringsr   C  s     N N N` r   c                       fd}|S )Nc                    | j                   }|j                  d      }d}|t        |      k  rFt        j                  d||         -|dz  }|t        |      k  rt        j                  d||         -|t        |      k  r:t        t        ||               }t        |      ||<   dj                  |      }nt        d|  d|       || _         | S )NrD   r   z^\s*Returns?:\s*$rP   )r\   zThe function ze should have an empty 'Return:' or 'Returns:' in its docstring as placeholder, current docstring is:
)	r   r*   r	   r>   r?   rB   rb   r   rT   )r   r   r^   rM   r.   rS   r[   s        r   r   z6replace_return_docstrings.<locals>.docstring_decorator  s    ::t$#e*n+?q!J!RFA #e*n+?q!J!Rs5z>U1X./F1+|X^_E!Hyy'Ht $**25  
	r   r   )r[   rS   r   s   `` r   replace_return_docstringsr     s    $ r   c                     t        j                  | j                  | j                  | j                  | j
                  | j                        }t        j                  ||       }| j                  |_	        |S )zReturns a copy of a function f.)nameargdefsclosure)
typesFunctionType__code____globals__rU   __defaults____closure__	functoolsupdate_wrapper__kwdefaults__)fgs     r   	copy_funcr     sX     	1::q}}1::q~~ghgtgtuA  A&A''AHr   )N)NN)7r   r   r   r>   r-   r   r   r   r9   r<   rY   rX   rB   rN   rb   r   PT_TOKEN_CLASSIFICATION_SAMPLEPT_QUESTION_ANSWERING_SAMPLE!PT_SEQUENCE_CLASSIFICATION_SAMPLEPT_MASKED_LM_SAMPLEPT_BASE_MODEL_SAMPLEPT_MULTIPLE_CHOICE_SAMPLEPT_CAUSAL_LM_SAMPLEPT_SPEECH_BASE_MODEL_SAMPLEPT_SPEECH_CTC_SAMPLEPT_SPEECH_SEQ_CLASS_SAMPLEPT_SPEECH_FRAME_CLASS_SAMPLEPT_SPEECH_XVECTOR_SAMPLEPT_VISION_BASE_MODEL_SAMPLEPT_VISION_SEQ_CLASS_SAMPLEr   TF_TOKEN_CLASSIFICATION_SAMPLETF_QUESTION_ANSWERING_SAMPLE!TF_SEQUENCE_CLASSIFICATION_SAMPLETF_MASKED_LM_SAMPLETF_BASE_MODEL_SAMPLETF_MULTIPLE_CHOICE_SAMPLETF_CAUSAL_LM_SAMPLETF_SPEECH_BASE_MODEL_SAMPLETF_SPEECH_CTC_SAMPLETF_VISION_BASE_MODEL_SAMPLETF_VISION_SEQ_CLASS_SAMPLEr    FLAX_TOKEN_CLASSIFICATION_SAMPLEFLAX_QUESTION_ANSWERING_SAMPLE#FLAX_SEQUENCE_CLASSIFICATION_SAMPLEFLAX_MASKED_LM_SAMPLEFLAX_BASE_MODEL_SAMPLEFLAX_MULTIPLE_CHOICE_SAMPLEFLAX_CAUSAL_LM_SAMPLEr   ry   r   r   r   r   r   r   <module>r      s#     	  "!H  84(V " B   D8% !t @ " 0 " 4! F! H  :! F 2 8 @59/#!%25 <,25 $" B!  F% !> B " .   0" H , 2 @59/#!%225 $   " $' #      ( $ B7;1%'#   	`F,r   