> For the complete documentation index, see [llms.txt](https://boinc-ai.gitbook.io/transformers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boinc-ai.gitbook.io/transformers/api/models/multimodal-models/nougat.md).

# Nougat

## Nougat

### Overview

The Nougat model was proposed in [Nougat: Neural Optical Understanding for Academic Documents](https://arxiv.org/abs/2308.13418) by Lukas Blecher, Guillem Cucurull, Thomas Scialom, Robert Stojnic. Nougat uses the same architecture as [Donut](https://huggingface.co/docs/transformers/model_doc/donut), meaning an image Transformer encoder and an autoregressive text Transformer decoder to translate scientific PDFs to markdown, enabling easier access to them.

The abstract from the paper is the following:

*Scientific knowledge is predominantly stored in books and scientific journals, often in the form of PDFs. However, the PDF format leads to a loss of semantic information, particularly for mathematical expressions. We propose Nougat (Neural Optical Understanding for Academic Documents), a Visual Transformer model that performs an Optical Character Recognition (OCR) task for processing scientific documents into a markup language, and demonstrate the effectiveness of our model on a new dataset of scientific documents. The proposed approach offers a promising solution to enhance the accessibility of scientific knowledge in the digital age, by bridging the gap between human-readable documents and machine-readable text. We release the models and code to accelerate future work on scientific text recognition.*

![drawing](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/nougat_architecture.jpg)Nougat high-level overview. Taken from the [original paper](https://arxiv.org/abs/2308.13418).

This model was contributed by [nielsr](https://huggingface.co/nielsr). The original code can be found [here](https://github.com/facebookresearch/nougat).

Tips:

* The quickest way to get started with Nougat is by checking the [tutorial notebooks](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/Nougat), which show how to use the model at inference time as well as fine-tuning on custom data.
* Nougat is always used within the [VisionEncoderDecoder](https://huggingface.co/docs/transformers/model_doc/vision-encoder-decoder) framework. The model is identical to [Donut](https://huggingface.co/docs/transformers/model_doc/donut) in terms of architecture.

### Inference

Nougat’s `VisionEncoderDecoder` model accepts images as input and makes use of [generate()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/text_generation#transformers.GenerationMixin.generate) to autoregressively generate text given the input image.

The [NougatImageProcessor](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatImageProcessor) class is responsible for preprocessing the input image and [NougatTokenizerFast](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatTokenizerFast) decodes the generated target tokens to the target string. The [NougatProcessor](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatProcessor) wraps [NougatImageProcessor](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatImageProcessor) and [NougatTokenizerFast](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatTokenizerFast) classes into a single instance to both extract the input features and decode the predicted token ids.

* Step-by-step PDF transcription

Copied

```
>>> from boincai_hub import hf_hub_download
>>> import re
>>> from PIL import Image

>>> from transformers import NougatProcessor, VisionEncoderDecoderModel
>>> from datasets import load_dataset
>>> import torch

>>> processor = NougatProcessor.from_pretrained("facebook/nougat-base")
>>> model = VisionEncoderDecoderModel.from_pretrained("facebook/nougat-base")

>>> device = "cuda" if torch.cuda.is_available() else "cpu"
>>> model.to(device)
>>> # prepare PDF image for the model
>>> filepath = hf_hub_download(repo_id="hf-internal-testing/fixtures_docvqa", filename="nougat_paper.png", repo_type="dataset")
>>> image = Image.open(filepath)
>>> pixel_values = processor(image, return_tensors="pt").pixel_values

>>> # generate transcription (here we only generate 30 tokens)
>>> outputs = model.generate(
...     pixel_values.to(device),
...     min_length=1,
...     max_new_tokens=30,
...     bad_words_ids=[[processor.tokenizer.unk_token_id]],
... )

>>> sequence = processor.batch_decode(outputs, skip_special_tokens=True)[0]
>>> sequence = processor.post_process_generation(sequence, fix_markdown=False)
>>> # note: we're using repr here such for the sake of printing the \n characters, feel free to just print the sequence
>>> print(repr(sequence))
'\n\n# Nougat: Neural Optical Understanding for Academic Documents\n\n Lukas Blecher\n\nCorrespondence to: lblecher@'
```

See the [model hub](https://huggingface.co/models?filter=nougat) to look for Nougat checkpoints.

### NougatImageProcessor

#### class transformers.NougatImageProcessor

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/image_processing_nougat.py#L57)

( do\_crop\_margin: bool = Truedo\_resize: bool = Truesize: typing.Dict\[str, int] = Noneresample: Resampling = \<Resampling.BILINEAR: 2>do\_thumbnail: bool = Truedo\_align\_long\_axis: bool = Falsedo\_pad: bool = Truedo\_rescale: bool = Truerescale\_factor: typing.Union\[int, float] = 0.00392156862745098do\_normalize: bool = Trueimage\_mean: typing.Union\[float, typing.List\[float], NoneType] = Noneimage\_std: typing.Union\[float, typing.List\[float], NoneType] = None\*\*kwargs )

Parameters

* **do\_crop\_margin** (`bool`, *optional*, defaults to `True`) — Whether to crop the image margins.
* **do\_resize** (`bool`, *optional*, defaults to `True`) — Whether to resize the image’s (height, width) dimensions to the specified `size`. Can be overridden by `do_resize` in the `preprocess` method.
* **size** (`Dict[str, int]` *optional*, defaults to `{"height" -- 896, "width": 672}`): Size of the image after resizing. Can be overridden by `size` in the `preprocess` method.
* **resample** (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BILINEAR`) — Resampling filter to use if resizing the image. Can be overridden by `resample` in the `preprocess` method.
* **do\_thumbnail** (`bool`, *optional*, defaults to `True`) — Whether to resize the image using thumbnail method.
* **do\_align\_long\_axis** (`bool`, *optional*, defaults to `False`) — Whether to align the long axis of the image with the long axis of `size` by rotating by 90 degrees.
* **do\_pad** (`bool`, *optional*, defaults to `True`) — Whether to pad the images to the largest image size in the batch.
* **do\_rescale** (`bool`, *optional*, defaults to `True`) — Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by the `do_rescale` parameter in the `preprocess` method.
* **rescale\_factor** (`int` or `float`, *optional*, defaults to `1/255`) — Scale factor to use if rescaling the image. Can be overridden by the `rescale_factor` parameter in the `preprocess` method.
* **do\_normalize** (`bool`, *optional*, defaults to `True`) — Whether to normalize the image. Can be overridden by `do_normalize` in the `preprocess` method.
* **image\_mean** (`float` or `List[float]`, *optional*, defaults to `IMAGENET_DEFAULT_MEAN`) — Mean to use if normalizing the image. This is a float or list of floats the length of the number of channels in the image. Can be overridden by the `image_mean` parameter in the `preprocess` method.
* **image\_std** (`float` or `List[float]`, *optional*, defaults to `IMAGENET_DEFAULT_STD`) — Image standard deviation.

Constructs a Nougat image processor.

**preprocess**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/image_processing_nougat.py#L358)

( images: typing.Union\[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), typing.List\[ForwardRef('PIL.Image.Image')], typing.List\[numpy.ndarray], typing.List\[ForwardRef('torch.Tensor')]]do\_crop\_margin: bool = Nonedo\_resize: bool = Nonesize: typing.Dict\[str, int] = Noneresample: Resampling = Nonedo\_thumbnail: bool = Nonedo\_align\_long\_axis: bool = Nonedo\_pad: bool = Nonedo\_rescale: bool = Nonerescale\_factor: typing.Union\[int, float] = Nonedo\_normalize: bool = Noneimage\_mean: typing.Union\[float, typing.List\[float], NoneType] = Noneimage\_std: typing.Union\[float, typing.List\[float], NoneType] = Nonereturn\_tensors: typing.Union\[str, transformers.utils.generic.TensorType, NoneType] = Nonedata\_format: typing.Optional\[transformers.image\_utils.ChannelDimension] = \<ChannelDimension.FIRST: 'channels\_first'>input\_data\_format: typing.Union\[str, transformers.image\_utils.ChannelDimension, NoneType] = None\*\*kwargs )

Parameters

* **images** (`ImageInput`) — Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255.
* **do\_crop\_margin** (`bool`, *optional*, defaults to `self.do_crop_margin`) — Whether to crop the image margins.
* **do\_resize** (`bool`, *optional*, defaults to `self.do_resize`) — Whether to resize the image.
* **size** (`Dict[str, int]`, *optional*, defaults to `self.size`) — Size of the image after resizing. Shortest edge of the image is resized to min(size\[“height”], size\[“width”]) with the longest edge resized to keep the input aspect ratio.
* **resample** (`int`, *optional*, defaults to `self.resample`) — Resampling filter to use if resizing the image. This can be one of the enum `PILImageResampling`. Only has an effect if `do_resize` is set to `True`.
* **do\_thumbnail** (`bool`, *optional*, defaults to `self.do_thumbnail`) — Whether to resize the image using thumbnail method.
* **do\_align\_long\_axis** (`bool`, *optional*, defaults to `self.do_align_long_axis`) — Whether to align the long axis of the image with the long axis of `size` by rotating by 90 degrees.
* **do\_pad** (`bool`, *optional*, defaults to `self.do_pad`) — Whether to pad the images to the largest image size in the batch.
* **do\_rescale** (`bool`, *optional*, defaults to `self.do_rescale`) — Whether to rescale the image by the specified scale `rescale_factor`.
* **rescale\_factor** (`int` or `float`, *optional*, defaults to `self.rescale_factor`) — Scale factor to use if rescaling the image.
* **do\_normalize** (`bool`, *optional*, defaults to `self.do_normalize`) — Whether to normalize the image.
* **image\_mean** (`float` or `List[float]`, *optional*, defaults to `self.image_mean`) — Image mean to use for normalization.
* **image\_std** (`float` or `List[float]`, *optional*, defaults to `self.image_std`) — Image standard deviation to use for normalization.
* **return\_tensors** (`str` or `TensorType`, *optional*) — The type of tensors to return. Can be one of:
  * Unset: Return a list of `np.ndarray`.
  * `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
  * `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
  * `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
  * `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
* **data\_format** (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`) — The channel dimension format for the output image. Can be one of:
  * `ChannelDimension.FIRST`: image in (num\_channels, height, width) format.
  * `ChannelDimension.LAST`: image in (height, width, num\_channels) format.
  * Unset: defaults to the channel dimension format of the input image.
* **input\_data\_format** (`ChannelDimension` or `str`, *optional*) — The channel dimension format for the input image. If unset, the channel dimension format is inferred from the input image. Can be one of:
  * `"channels_first"` or `ChannelDimension.FIRST`: image in (num\_channels, height, width) format.
  * `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num\_channels) format.
  * `"none"` or `ChannelDimension.NONE`: image in (height, width) format.

Preprocess an image or batch of images.

### NougatTokenizerFast

#### class transformers.NougatTokenizerFast

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/tokenization_nougat_fast.py#L377)

( vocab\_file = Nonetokenizer\_file = Noneclean\_up\_tokenization\_spaces = Falseunk\_token = '\<unk>'bos\_token = '\<s>'eos\_token = '\</s>'pad\_token = '\<pad>'\*\*kwargs )

Parameters

* **vocab\_file** (`str`) — [SentencePiece](https://github.com/google/sentencepiece) file (generally has a .model extension) that contains the vocabulary necessary to instantiate a tokenizer.
* **tokenizer\_file** (`str`) — [tokenizers](https://github.com/huggingface/tokenizers) file (generally has a .json extension) that contains everything needed to load the tokenizer.
* **clean\_up\_tokenization\_spaces** (`str`, *optional*, defaults to `False`) — Wether to cleanup spaces after decoding, cleanup consists in removing potential artifacts like extra spaces.
* **bos\_token** (`str`, *optional*, defaults to `"<s>"`) — The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.
* **eos\_token** (`str`, *optional*, defaults to `"</s>"`) — The end of sequence token.
* **unk\_token** (`str`, *optional*, defaults to `"<unk>"`) — The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead.
* **pad\_token** (`str`, *optional*, defaults to `"<pad>"`) — The token used for padding, for example when batching sequences of different lengths.
* **model\_max\_length** (`int`, *optional*) — The maximum length (in number of tokens) for the inputs to the transformer model. When the tokenizer is loaded with [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.from_pretrained), this will be set to the value stored for the associated model in `max_model_input_sizes` (see above). If no value is provided, will default to VERY\_LARGE\_INTEGER (`int(1e30)`).
* **padding\_side** (`str`, *optional*) — The side on which the model should have padding applied. Should be selected between \[‘right’, ‘left’]. Default value is picked from the class attribute of the same name.
* **truncation\_side** (`str`, *optional*) — The side on which the model should have truncation applied. Should be selected between \[‘right’, ‘left’]. Default value is picked from the class attribute of the same name.
* **chat\_template** (`str`, *optional*) — A Jinja template string that will be used to format lists of chat messages. See [https://boincai.com/docs/transformers/chat\_templating](https://huggingface.co/docs/transformers/chat_templating) for a full description.
* **model\_input\_names** (`List[string]`, *optional*) — The list of inputs accepted by the forward pass of the model (like `"token_type_ids"` or `"attention_mask"`). Default value is picked from the class attribute of the same name.
* **bos\_token** (`str` or `tokenizers.AddedToken`, *optional*) — A special token representing the beginning of a sentence. Will be associated to `self.bos_token` and `self.bos_token_id`.
* **eos\_token** (`str` or `tokenizers.AddedToken`, *optional*) — A special token representing the end of a sentence. Will be associated to `self.eos_token` and `self.eos_token_id`.
* **unk\_token** (`str` or `tokenizers.AddedToken`, *optional*) — A special token representing an out-of-vocabulary token. Will be associated to `self.unk_token` and `self.unk_token_id`.
* **sep\_token** (`str` or `tokenizers.AddedToken`, *optional*) — A special token separating two different sentences in the same input (used by BERT for instance). Will be associated to `self.sep_token` and `self.sep_token_id`.
* **pad\_token** (`str` or `tokenizers.AddedToken`, *optional*) — A special token used to make arrays of tokens the same size for batching purpose. Will then be ignored by attention mechanisms or loss computation. Will be associated to `self.pad_token` and `self.pad_token_id`.
* **cls\_token** (`str` or `tokenizers.AddedToken`, *optional*) — A special token representing the class of the input (used by BERT for instance). Will be associated to `self.cls_token` and `self.cls_token_id`.
* **mask\_token** (`str` or `tokenizers.AddedToken`, *optional*) — A special token representing a masked token (used by masked-language modeling pretraining objectives, like BERT). Will be associated to `self.mask_token` and `self.mask_token_id`.
* **additional\_special\_tokens** (tuple or list of `str` or `tokenizers.AddedToken`, *optional*) — A tuple or a list of additional special tokens. Add them here to ensure they are skipped when decoding with `skip_special_tokens` is set to True. If they are not part of the vocabulary, they will be added at the end of the vocabulary.
* **clean\_up\_tokenization\_spaces** (`bool`, *optional*, defaults to `True`) — Whether or not the model should cleanup the spaces that were added when splitting the input text during the tokenization process.
* **split\_special\_tokens** (`bool`, *optional*, defaults to `False`) — Whether or not the special tokens should be split during the tokenization process. The default behavior is to not split special tokens. This means that if `<s>` is the `bos_token`, then `tokenizer.tokenize("<s>") = ['<s>`]. Otherwise, if `split_special_tokens=True`, then `tokenizer.tokenize("<s>")` will be give `['<', 's', '>']`. This argument is only supported for `slow` tokenizers for the moment.
* **tokenizer\_object** (`tokenizers.Tokenizer`) — A `tokenizers.Tokenizer` object from 🌍tokenizers to instantiate from. See [Using tokenizers from ](https://huggingface.co/docs/transformers/fast_tokenizers)🌍[ tokenizers](https://huggingface.co/docs/transformers/fast_tokenizers) for more information.
* **tokenizer\_file** (`str`) — A path to a local JSON file representing a previously serialized `tokenizers.Tokenizer` object from 🌍 tokenizers.

Fast tokenizer for Nougat (backed by BOINC AI tokenizers library).

This tokenizer inherits from [PreTrainedTokenizerFast](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast) which contains most of the main methods. Users should refer to this superclass for more information regarding those methods. This class mainly adds Nougat-specific methods for postprocessing the generated text.

Class attributes (overridden by derived classes)

* **vocab\_files\_names** (`Dict[str, str]`) — A dictionary with, as keys, the `__init__` keyword name of each vocabulary file required by the model, and as associated values, the filename for saving the associated file (string).
* **pretrained\_vocab\_files\_map** (`Dict[str, Dict[str, str]]`) — A dictionary of dictionaries, with the high-level keys being the `__init__` keyword name of each vocabulary file required by the model, the low-level being the `short-cut-names` of the pretrained models with, as associated values, the `url` to the associated pretrained vocabulary file.
* **max\_model\_input\_sizes** (`Dict[str, Optional[int]]`) — A dictionary with, as keys, the `short-cut-names` of the pretrained models, and as associated values, the maximum length of the sequence inputs of this model, or `None` if the model has no maximum input size.
* **pretrained\_init\_configuration** (`Dict[str, Dict[str, Any]]`) — A dictionary with, as keys, the `short-cut-names` of the pretrained models, and as associated values, a dictionary of specific arguments to pass to the `__init__` method of the tokenizer class for this pretrained model when loading the tokenizer with the [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.from_pretrained) method.
* **model\_input\_names** (`List[str]`) — A list of inputs expected in the forward pass of the model.
* **padding\_side** (`str`) — The default value for the side on which the model should have padding applied. Should be `'right'` or `'left'`.
* **truncation\_side** (`str`) — The default value for the side on which the model should have truncation applied. Should be `'right'` or `'left'`.

**correct\_tables**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/tokenization_nougat_fast.py#L470)

( generation: str ) → str

Parameters

* **generation** (str) — The generated text to be postprocessed.

Returns

str

The postprocessed text.

Takes a generated string and fixes tables/tabulars to make them match the markdown format needed.

Example:

Copied

```
correct_tables("\begin{table} \begin{tabular}{l l} & \ \end{tabular} \end{table}")
"\begin{table}
abular}{l l} & \ \end{tabular}
le}"
```

**post\_process\_generation**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/tokenization_nougat_fast.py#L600)

( generation: typing.Union\[str, typing.List\[str]]fix\_markdown: bool = Truenum\_workers: int = None ) → Union\[str, List\[str]]

Parameters

* **generation** (Union\[str, List\[str]]) — The generated text or a list of generated texts.
* **fix\_markdown** (`bool`, *optional*, defaults to `True`) — Whether to perform Markdown formatting fixes.
* **num\_workers** (`int`, *optional*) — Optional number of workers to pass to leverage multiprocessing (postprocessing several texts in parallel).

Returns

Union\[str, List\[str]]

The postprocessed text or list of postprocessed texts.

Postprocess a generated text or a list of generated texts.

This function can be used to perform postprocessing on generated text, such as fixing Markdown formatting.

Postprocessing is quite slow so it is recommended to use multiprocessing to speed up the process.

**post\_process\_single**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/tokenization_nougat_fast.py#L505)

( generation: strfix\_markdown: bool = True ) → str

Parameters

* **generation** (str) — The generated text to be postprocessed.
* **fix\_markdown** (bool, optional) — Whether to perform Markdown formatting fixes. Default is True.

Returns

str

The postprocessed text.

Postprocess a single generated text. Regular expressions used here are taken directly from the Nougat article authors. These expressions are commented for clarity and tested end-to-end in most cases.

**remove\_hallucinated\_references**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/tokenization_nougat_fast.py#L440)

( text: str ) → `str`

Parameters

* **text** (`str`) — The input text containing references.

Returns

`str`

The text with hallucinated references removed.

Remove hallucinated or missing references from the text.

This function identifies and removes references that are marked as missing or hallucinated from the input text.

### NougatProcessor

#### class transformers.NougatProcessor

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/processing_nougat.py#L27)

( image\_processortokenizer )

Parameters

* **image\_processor** ([NougatImageProcessor](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatImageProcessor)) — An instance of [NougatImageProcessor](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatImageProcessor). The image processor is a required input.
* **tokenizer** ([NougatTokenizerFast](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatTokenizerFast)) — An instance of [NougatTokenizerFast](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatTokenizerFast). The tokenizer is a required input.

Constructs a Nougat processor which wraps a Nougat image processor and a Nougat tokenizer into a single processor.

[NougatProcessor](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatProcessor) offers all the functionalities of [NougatImageProcessor](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatImageProcessor) and [NougatTokenizerFast](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatTokenizerFast). See the [**call**()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatProcessor.__call__) and [decode()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatProcessor.decode) for more information.

**\_\_call\_\_**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/processing_nougat.py#L48)

( images = Nonetext = Nonedo\_crop\_margin: bool = Nonedo\_resize: bool = Nonesize: typing.Dict\[str, int] = Noneresample: PILImageResampling = Nonedo\_thumbnail: bool = Nonedo\_align\_long\_axis: bool = Nonedo\_pad: bool = Nonedo\_rescale: bool = Nonerescale\_factor: typing.Union\[int, float] = Nonedo\_normalize: bool = Noneimage\_mean: typing.Union\[float, typing.List\[float], NoneType] = Noneimage\_std: typing.Union\[float, typing.List\[float], NoneType] = Nonedata\_format: typing.Optional\[ForwardRef('ChannelDimension')] = 'ChannelDimension.FIRST'input\_data\_format: typing.Union\[str, ForwardRef('ChannelDimension'), NoneType] = Nonetext\_pair: typing.Union\[str, typing.List\[str], typing.List\[typing.List\[str]], NoneType] = Nonetext\_target: typing.Union\[str, typing.List\[str], typing.List\[typing.List\[str]]] = Nonetext\_pair\_target: typing.Union\[str, typing.List\[str], typing.List\[typing.List\[str]], NoneType] = Noneadd\_special\_tokens: bool = Truepadding: typing.Union\[bool, str, transformers.utils.generic.PaddingStrategy] = Falsetruncation: typing.Union\[bool, str, transformers.tokenization\_utils\_base.TruncationStrategy] = Nonemax\_length: typing.Optional\[int] = Nonestride: int = 0is\_split\_into\_words: bool = Falsepad\_to\_multiple\_of: typing.Optional\[int] = Nonereturn\_tensors: typing.Union\[str, transformers.utils.generic.TensorType, NoneType] = Nonereturn\_token\_type\_ids: typing.Optional\[bool] = Nonereturn\_attention\_mask: typing.Optional\[bool] = Nonereturn\_overflowing\_tokens: bool = Falsereturn\_special\_tokens\_mask: bool = Falsereturn\_offsets\_mapping: bool = Falsereturn\_length: bool = Falseverbose: bool = True )

**from\_pretrained**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/processing_utils.py#L167)

( pretrained\_model\_name\_or\_path: typing.Union\[str, os.PathLike]cache\_dir: typing.Union\[str, os.PathLike, NoneType] = Noneforce\_download: bool = Falselocal\_files\_only: bool = Falsetoken: typing.Union\[bool, str, NoneType] = Nonerevision: str = 'main'\*\*kwargs )

Parameters

* **pretrained\_model\_name\_or\_path** (`str` or `os.PathLike`) — This can be either:
  * a string, the *model id* of a pretrained feature\_extractor hosted inside a model repo on boincai.com. Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a user or organization name, like `dbmdz/bert-base-german-cased`.
  * a path to a *directory* containing a feature extractor file saved using the [save\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.save_pretrained) method, e.g., `./my_model_directory/`.
  * a path or url to a saved feature extractor JSON *file*, e.g., `./my_model_directory/preprocessor_config.json`. \*\*kwargs — Additional keyword arguments passed along to both [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.from_pretrained) and `~tokenization_utils_base.PreTrainedTokenizer.from_pretrained`.

Instantiate a processor associated with a pretrained model.

This class method is simply calling the feature extractor [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.from_pretrained), image processor [ImageProcessingMixin](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/image_processor#transformers.ImageProcessingMixin) and the tokenizer `~tokenization_utils_base.PreTrainedTokenizer.from_pretrained` methods. Please refer to the docstrings of the methods above for more information.

**save\_pretrained**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/processing_utils.py#L93)

( save\_directorypush\_to\_hub: bool = False\*\*kwargs )

Parameters

* **save\_directory** (`str` or `os.PathLike`) — Directory where the feature extractor JSON file and the tokenizer files will be saved (directory will be created if it does not exist).
* **push\_to\_hub** (`bool`, *optional*, defaults to `False`) — Whether or not to push your model to the BOINC AI model hub after saving it. You can specify the repository you want to push to with `repo_id` (will default to the name of `save_directory` in your namespace).
* **kwargs** (`Dict[str, Any]`, *optional*) — Additional key word arguments passed along to the [push\_to\_hub()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/processors#transformers.ProcessorMixin.push_to_hub) method.

Saves the attributes of this processor (feature extractor, tokenizer…) in the specified directory so that it can be reloaded using the [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nougat#transformers.NougatProcessor.from_pretrained) method.

This class method is simply calling [save\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.save_pretrained) and [save\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.save_pretrained). Please refer to the docstrings of the methods above for more information.

**batch\_decode**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/processing_nougat.py#L140)

( \*args\*\*kwargs )

This method forwards all its arguments to NougatTokenizer’s [batch\_decode()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/speecht5#transformers.SpeechT5Tokenizer.batch_decode). Please refer to the docstring of this method for more information.

**decode**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/processing_nougat.py#L147)

( \*args\*\*kwargs )

This method forwards all its arguments to NougatTokenizer’s [decode()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/speecht5#transformers.SpeechT5Tokenizer.decode). Please refer to the docstring of this method for more information.

**post\_process\_generation**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/nougat/processing_nougat.py#L154)

( \*args\*\*kwargs )

This method forwards all its arguments to NougatTokenizer’s `~PreTrainedTokenizer.post_process_generation`. Please refer to the docstring of this method for more information.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boinc-ai.gitbook.io/transformers/api/models/multimodal-models/nougat.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
