---
local: dpr
sections:
- local: overview
  title: Overview
- local: transformers.DPRConfig
  title: DPRConfig
- local: transformers.DPRContextEncoderTokenizer
  title: DPRContextEncoderTokenizer
- local: transformers.DPRContextEncoderTokenizerFast
  title: DPRContextEncoderTokenizerFast
- local: transformers.DPRQuestionEncoderTokenizer
  title: DPRQuestionEncoderTokenizer
- local: transformers.DPRQuestionEncoderTokenizerFast
  title: DPRQuestionEncoderTokenizerFast
- local: transformers.DPRReaderTokenizer
  title: DPRReaderTokenizer
- local: transformers.DPRReaderTokenizerFast
  title: DPRReaderTokenizerFast
- local: transformers.models.dpr.modeling_dpr.DPRContextEncoderOutput
  title: DPR specific outputs
- local: transformers.DPRContextEncoder
  title: DPRContextEncoder
- local: transformers.DPRQuestionEncoder
  title: DPRQuestionEncoder
- local: transformers.DPRReader
  title: DPRReader
- local: transformers.TFDPRContextEncoder
  title: TFDPRContextEncoder
- local: transformers.TFDPRQuestionEncoder
  title: TFDPRQuestionEncoder
- local: transformers.TFDPRReader
  title: TFDPRReader
title: DPR
---
<script>
import Tip from "./Tip.svelte";
import Youtube from "./Youtube.svelte";
import Docstring from "./Docstring.svelte";
import CodeBlock from "./CodeBlock.svelte";
import CodeBlockFw from "./CodeBlockFw.svelte";
import DocNotebookDropdown from "./DocNotebookDropdown.svelte";
import IconCopyLink from "./IconCopyLink.svelte";
export let fw: "pt" | "tf"
</script>
<!--Copyright 2020 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

<h1 id="dpr">DPR</h1>

<h2 id="overview">Overview</h2>

Dense Passage Retrieval (DPR) is a set of tools and models for state-of-the-art open-domain Q&A research. It was
introduced in [Dense Passage Retrieval for Open-Domain Question Answering](https://arxiv.org/abs/2004.04906) by
Vladimir Karpukhin, Barlas Oğuz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, Wen-tau Yih.

The abstract from the paper is the following:

*Open-domain question answering relies on efficient passage retrieval to select candidate contexts, where traditional
sparse vector space models, such as TF-IDF or BM25, are the de facto method. In this work, we show that retrieval can
be practically implemented using dense representations alone, where embeddings are learned from a small number of
questions and passages by a simple dual-encoder framework. When evaluated on a wide range of open-domain QA datasets,
our dense retriever outperforms a strong Lucene-BM25 system largely by 9%-19% absolute in terms of top-20 passage
retrieval accuracy, and helps our end-to-end QA system establish new state-of-the-art on multiple open-domain QA
benchmarks.*

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


<h2 id="transformers.DPRConfig">DPRConfig</h2>

<div class="docstring">

<docstring><name>class transformers.DPRConfig</name><anchor>transformers.DPRConfig</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/configuration_dpr.py#L33</source><parameters>[{"name": "vocab_size", "val": " = 30522"}, {"name": "hidden_size", "val": " = 768"}, {"name": "num_hidden_layers", "val": " = 12"}, {"name": "num_attention_heads", "val": " = 12"}, {"name": "intermediate_size", "val": " = 3072"}, {"name": "hidden_act", "val": " = 'gelu'"}, {"name": "hidden_dropout_prob", "val": " = 0.1"}, {"name": "attention_probs_dropout_prob", "val": " = 0.1"}, {"name": "max_position_embeddings", "val": " = 512"}, {"name": "type_vocab_size", "val": " = 2"}, {"name": "initializer_range", "val": " = 0.02"}, {"name": "layer_norm_eps", "val": " = 1e-12"}, {"name": "pad_token_id", "val": " = 0"}, {"name": "position_embedding_type", "val": " = 'absolute'"}, {"name": "projection_dim", "val": ": int = 0"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **vocab_size** (`int`, *optional*, defaults to 30522) --
  Vocabulary size of the DPR model. Defines the different tokens that can be represented by the *inputs_ids*
  passed to the forward method of [BertModel](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertModel).
- **hidden_size** (`int`, *optional*, defaults to 768) --
  Dimensionality of the encoder layers and the pooler layer.
- **num_hidden_layers** (`int`, *optional*, defaults to 12) --
  Number of hidden layers in the Transformer encoder.
- **num_attention_heads** (`int`, *optional*, defaults to 12) --
  Number of attention heads for each attention layer in the Transformer encoder.
- **intermediate_size** (`int`, *optional*, defaults to 3072) --
  Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
- **hidden_act** (`str` or `function`, *optional*, defaults to `"gelu"`) --
  The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  `"relu"`, `"silu"` and `"gelu_new"` are supported.
- **hidden_dropout_prob** (`float`, *optional*, defaults to 0.1) --
  The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
- **attention_probs_dropout_prob** (`float`, *optional*, defaults to 0.1) --
  The dropout ratio for the attention probabilities.
- **max_position_embeddings** (`int`, *optional*, defaults to 512) --
  The maximum sequence length that this model might ever be used with. Typically set this to something large
  just in case (e.g., 512 or 1024 or 2048).
- **type_vocab_size** (`int`, *optional*, defaults to 2) --
  The vocabulary size of the *token_type_ids* passed into [BertModel](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertModel).
- **initializer_range** (`float`, *optional*, defaults to 0.02) --
  The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
- **layer_norm_eps** (`float`, *optional*, defaults to 1e-12) --
  The epsilon used by the layer normalization layers.
- **position_embedding_type** (`str`, *optional*, defaults to `"absolute"`) --
  Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`. For
  positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to
  [Self-Attention with Relative Position Representations (Shaw et al.)](https://arxiv.org/abs/1803.02155).
  For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models
  with Better Relative Position Embeddings (Huang et al.)](https://arxiv.org/abs/2009.13658).
- **projection_dim** (`int`, *optional*, defaults to 0) --
  Dimension of the projection for the context and question encoders. If it is set to zero (default), then no
  projection is done.</paramsdesc><paramgroups>0</paramgroups></docstring>

[DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig) is the configuration class to store the configuration of a *DPRModel*.

This is the configuration class to store the configuration of a [DPRContextEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRContextEncoder), [DPRQuestionEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRQuestionEncoder), or a
[DPRReader](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReader). It is used to instantiate the components of the DPR model.

This class is a subclass of [BertConfig](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertConfig). Please check the superclass for the documentation of all kwargs.




</div>

<h2 id="transformers.DPRContextEncoderTokenizer">DPRContextEncoderTokenizer</h2>

<div class="docstring">

<docstring><name>class transformers.DPRContextEncoderTokenizer</name><anchor>transformers.DPRContextEncoderTokenizer</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/tokenization_dpr.py#L90</source><parameters>[{"name": "vocab_file", "val": ""}, {"name": "do_lower_case", "val": " = True"}, {"name": "do_basic_tokenize", "val": " = True"}, {"name": "never_split", "val": " = None"}, {"name": "unk_token", "val": " = '[UNK]'"}, {"name": "sep_token", "val": " = '[SEP]'"}, {"name": "pad_token", "val": " = '[PAD]'"}, {"name": "cls_token", "val": " = '[CLS]'"}, {"name": "mask_token", "val": " = '[MASK]'"}, {"name": "tokenize_chinese_chars", "val": " = True"}, {"name": "strip_accents", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters></docstring>

Construct a DPRContextEncoder tokenizer.

[DPRContextEncoderTokenizer](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRContextEncoderTokenizer) is identical to [BertTokenizer](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizer) and runs end-to-end tokenization: punctuation
splitting and wordpiece.

Refer to superclass [BertTokenizer](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizer) for usage examples and documentation concerning parameters.


</div>

<h2 id="transformers.DPRContextEncoderTokenizerFast">DPRContextEncoderTokenizerFast</h2>

<div class="docstring">

<docstring><name>class transformers.DPRContextEncoderTokenizerFast</name><anchor>transformers.DPRContextEncoderTokenizerFast</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/tokenization_dpr_fast.py#L91</source><parameters>[{"name": "vocab_file", "val": " = None"}, {"name": "tokenizer_file", "val": " = None"}, {"name": "do_lower_case", "val": " = True"}, {"name": "unk_token", "val": " = '[UNK]'"}, {"name": "sep_token", "val": " = '[SEP]'"}, {"name": "pad_token", "val": " = '[PAD]'"}, {"name": "cls_token", "val": " = '[CLS]'"}, {"name": "mask_token", "val": " = '[MASK]'"}, {"name": "tokenize_chinese_chars", "val": " = True"}, {"name": "strip_accents", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters></docstring>

Construct a "fast" DPRContextEncoder tokenizer (backed by HuggingFace's *tokenizers* library).

[DPRContextEncoderTokenizerFast](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRContextEncoderTokenizerFast) is identical to [BertTokenizerFast](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizerFast) and runs end-to-end tokenization:
punctuation splitting and wordpiece.

Refer to superclass [BertTokenizerFast](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizerFast) for usage examples and documentation concerning parameters.


</div>

<h2 id="transformers.DPRQuestionEncoderTokenizer">DPRQuestionEncoderTokenizer</h2>

<div class="docstring">

<docstring><name>class transformers.DPRQuestionEncoderTokenizer</name><anchor>transformers.DPRQuestionEncoderTokenizer</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/tokenization_dpr.py#L106</source><parameters>[{"name": "vocab_file", "val": ""}, {"name": "do_lower_case", "val": " = True"}, {"name": "do_basic_tokenize", "val": " = True"}, {"name": "never_split", "val": " = None"}, {"name": "unk_token", "val": " = '[UNK]'"}, {"name": "sep_token", "val": " = '[SEP]'"}, {"name": "pad_token", "val": " = '[PAD]'"}, {"name": "cls_token", "val": " = '[CLS]'"}, {"name": "mask_token", "val": " = '[MASK]'"}, {"name": "tokenize_chinese_chars", "val": " = True"}, {"name": "strip_accents", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters></docstring>

Constructs a DPRQuestionEncoder tokenizer.

[DPRQuestionEncoderTokenizer](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRQuestionEncoderTokenizer) is identical to [BertTokenizer](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizer) and runs end-to-end tokenization: punctuation
splitting and wordpiece.

Refer to superclass [BertTokenizer](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizer) for usage examples and documentation concerning parameters.


</div>

<h2 id="transformers.DPRQuestionEncoderTokenizerFast">DPRQuestionEncoderTokenizerFast</h2>

<div class="docstring">

<docstring><name>class transformers.DPRQuestionEncoderTokenizerFast</name><anchor>transformers.DPRQuestionEncoderTokenizerFast</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/tokenization_dpr_fast.py#L108</source><parameters>[{"name": "vocab_file", "val": " = None"}, {"name": "tokenizer_file", "val": " = None"}, {"name": "do_lower_case", "val": " = True"}, {"name": "unk_token", "val": " = '[UNK]'"}, {"name": "sep_token", "val": " = '[SEP]'"}, {"name": "pad_token", "val": " = '[PAD]'"}, {"name": "cls_token", "val": " = '[CLS]'"}, {"name": "mask_token", "val": " = '[MASK]'"}, {"name": "tokenize_chinese_chars", "val": " = True"}, {"name": "strip_accents", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters></docstring>

Constructs a "fast" DPRQuestionEncoder tokenizer (backed by HuggingFace's *tokenizers* library).

[DPRQuestionEncoderTokenizerFast](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRQuestionEncoderTokenizerFast) is identical to [BertTokenizerFast](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizerFast) and runs end-to-end tokenization:
punctuation splitting and wordpiece.

Refer to superclass [BertTokenizerFast](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizerFast) for usage examples and documentation concerning parameters.


</div>

<h2 id="transformers.DPRReaderTokenizer">DPRReaderTokenizer</h2>

<div class="docstring">

<docstring><name>class transformers.DPRReaderTokenizer</name><anchor>transformers.DPRReaderTokenizer</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/tokenization_dpr.py#L370</source><parameters>[{"name": "vocab_file", "val": ""}, {"name": "do_lower_case", "val": " = True"}, {"name": "do_basic_tokenize", "val": " = True"}, {"name": "never_split", "val": " = None"}, {"name": "unk_token", "val": " = '[UNK]'"}, {"name": "sep_token", "val": " = '[SEP]'"}, {"name": "pad_token", "val": " = '[PAD]'"}, {"name": "cls_token", "val": " = '[CLS]'"}, {"name": "mask_token", "val": " = '[MASK]'"}, {"name": "tokenize_chinese_chars", "val": " = True"}, {"name": "strip_accents", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **questions** (`str` or `List[str]`) --
  The questions to be encoded. You can specify one question for many passages. In this case, the question
  will be duplicated like `[questions] * n_passages`. Otherwise you have to specify as many questions as in
  `titles` or `texts`.
- **titles** (`str` or `List[str]`) --
  The passages titles to be encoded. This can be a string or a list of strings if there are several passages.
- **texts** (`str` or `List[str]`) --
  The passages texts to be encoded. This can be a string or a list of strings if there are several passages.
- **padding** (`bool`, `str` or [PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy), *optional*, defaults to `False`) --
  Activates and controls padding. Accepts the following values:

  - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single sequence
    if provided).
  - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided.
  - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
    lengths).
- **truncation** (`bool`, `str` or [TruncationStrategy](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy), *optional*, defaults to `False`) --
  Activates and controls truncation. Accepts the following values:

  - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or to
    the maximum acceptable input length for the model if that argument is not provided. This will truncate
    token by token, removing a token from the longest sequence in the pair if a pair of sequences (or a batch
    of pairs) is provided.
  - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided. This will only truncate the first
    sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided. This will only truncate the
    second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
    greater than the model maximum admissible input size).
- **max_length** (`int`, *optional*) --
  Controls the maximum length to use by one of the truncation/padding parameters.

  If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
  is required by one of the truncation/padding parameters. If the model has no specific maximum input
  length (like XLNet) truncation/padding to a maximum length will be deactivated.
- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  If set, will return tensors instead of list of python integers. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return Numpy `np.ndarray` objects.
- **return_attention_mask** (`bool`, *optional*) --
  Whether or not to return the attention mask. If not set, will return the attention mask according to the
  specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are attention masks?](../glossary#attention-mask)</paramsdesc><paramgroups>0</paramgroups><rettype>`Dict[str, List[List[int]]]`</rettype><retdesc>A dictionary with the following keys:

- `input_ids`: List of token ids to be fed to a model.
- `attention_mask`: List of indices specifying which tokens should be attended to by the model.</retdesc></docstring>

Construct a DPRReader tokenizer.

[DPRReaderTokenizer](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReaderTokenizer) is almost identical to [BertTokenizer](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizer) and runs end-to-end tokenization: punctuation
splitting and wordpiece. The difference is that is has three inputs strings: question, titles and texts that are
combined to be fed to the [DPRReader](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReader) model.

Refer to superclass [BertTokenizer](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizer) for usage examples and documentation concerning parameters.

Return a dictionary with the token ids of the input strings and other information to give to `.decode_best_spans`.
It converts the strings of a question and different passages (title and text) in a sequence of IDs (integers),
using the tokenizer and vocabulary. The resulting `input_ids` is a matrix of size `(n_passages, sequence_length)`
with the format:

```
[CLS] &amp;lt;question token ids> [SEP] &amp;lt;titles ids> [SEP] &amp;lt;texts ids>
```








</div>

<h2 id="transformers.DPRReaderTokenizerFast">DPRReaderTokenizerFast</h2>

<div class="docstring">

<docstring><name>class transformers.DPRReaderTokenizerFast</name><anchor>transformers.DPRReaderTokenizerFast</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/tokenization_dpr_fast.py#L371</source><parameters>[{"name": "vocab_file", "val": " = None"}, {"name": "tokenizer_file", "val": " = None"}, {"name": "do_lower_case", "val": " = True"}, {"name": "unk_token", "val": " = '[UNK]'"}, {"name": "sep_token", "val": " = '[SEP]'"}, {"name": "pad_token", "val": " = '[PAD]'"}, {"name": "cls_token", "val": " = '[CLS]'"}, {"name": "mask_token", "val": " = '[MASK]'"}, {"name": "tokenize_chinese_chars", "val": " = True"}, {"name": "strip_accents", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **questions** (`str` or `List[str]`) --
  The questions to be encoded. You can specify one question for many passages. In this case, the question
  will be duplicated like `[questions] * n_passages`. Otherwise you have to specify as many questions as in
  `titles` or `texts`.
- **titles** (`str` or `List[str]`) --
  The passages titles to be encoded. This can be a string or a list of strings if there are several passages.
- **texts** (`str` or `List[str]`) --
  The passages texts to be encoded. This can be a string or a list of strings if there are several passages.
- **padding** (`bool`, `str` or [PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy), *optional*, defaults to `False`) --
  Activates and controls padding. Accepts the following values:

  - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single sequence
    if provided).
  - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided.
  - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
    lengths).
- **truncation** (`bool`, `str` or [TruncationStrategy](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy), *optional*, defaults to `False`) --
  Activates and controls truncation. Accepts the following values:

  - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or to
    the maximum acceptable input length for the model if that argument is not provided. This will truncate
    token by token, removing a token from the longest sequence in the pair if a pair of sequences (or a batch
    of pairs) is provided.
  - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided. This will only truncate the first
    sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided. This will only truncate the
    second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
    greater than the model maximum admissible input size).
- **max_length** (`int`, *optional*) --
  Controls the maximum length to use by one of the truncation/padding parameters.

  If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
  is required by one of the truncation/padding parameters. If the model has no specific maximum input
  length (like XLNet) truncation/padding to a maximum length will be deactivated.
- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  If set, will return tensors instead of list of python integers. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return Numpy `np.ndarray` objects.
- **return_attention_mask** (`bool`, *optional*) --
  Whether or not to return the attention mask. If not set, will return the attention mask according to the
  specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are attention masks?](../glossary#attention-mask)</paramsdesc><paramgroups>0</paramgroups><rettype>`Dict[str, List[List[int]]]`</rettype><retdesc>A dictionary with the following keys:

- `input_ids`: List of token ids to be fed to a model.
- `attention_mask`: List of indices specifying which tokens should be attended to by the model.</retdesc></docstring>

Constructs a "fast" DPRReader tokenizer (backed by HuggingFace's *tokenizers* library).

[DPRReaderTokenizerFast](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReaderTokenizerFast) is almost identical to [BertTokenizerFast](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizerFast) and runs end-to-end tokenization:
punctuation splitting and wordpiece. The difference is that is has three inputs strings: question, titles and texts
that are combined to be fed to the [DPRReader](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReader) model.

Refer to superclass [BertTokenizerFast](/docs/transformers/pr_15592/en/model_doc/bert#transformers.BertTokenizerFast) for usage examples and documentation concerning parameters.


Return a dictionary with the token ids of the input strings and other information to give to `.decode_best_spans`.
It converts the strings of a question and different passages (title and text) in a sequence of IDs (integers),
using the tokenizer and vocabulary. The resulting `input_ids` is a matrix of size `(n_passages, sequence_length)`
with the format:

[CLS] &amp;lt;question token ids> [SEP] &amp;lt;titles ids> [SEP] &amp;lt;texts ids>








</div>

<h2 id="transformers.models.dpr.modeling_dpr.DPRContextEncoderOutput">DPR specific outputs</h2>

<div class="docstring">

<docstring><name>class transformers.models.dpr.modeling\_dpr.DPRContextEncoderOutput</name><anchor>transformers.models.dpr.modeling_dpr.DPRContextEncoderOutput</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L62</source><parameters>[{"name": "pooler_output", "val": ": FloatTensor"}, {"name": "hidden_states", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}]</parameters><paramsdesc>- **pooler_output** (`torch.FloatTensor` of shape `(batch_size, embeddings_size)`) --
  The DPR encoder outputs the *pooler_output* that corresponds to the context representation. Last layer
  hidden-state of the first token of the sequence (classification token) further processed by a Linear layer.
  This output is to be used to embed contexts for nearest neighbors queries with questions embeddings.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) --
  Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</paramsdesc><paramgroups>0</paramgroups></docstring>

Class for outputs of [DPRQuestionEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRQuestionEncoder).




</div>

<div class="docstring">

<docstring><name>class transformers.models.dpr.modeling\_dpr.DPRQuestionEncoderOutput</name><anchor>transformers.models.dpr.modeling_dpr.DPRQuestionEncoderOutput</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L90</source><parameters>[{"name": "pooler_output", "val": ": FloatTensor"}, {"name": "hidden_states", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}]</parameters><paramsdesc>- **pooler_output** (`torch.FloatTensor` of shape `(batch_size, embeddings_size)`) --
  The DPR encoder outputs the *pooler_output* that corresponds to the question representation. Last layer
  hidden-state of the first token of the sequence (classification token) further processed by a Linear layer.
  This output is to be used to embed questions for nearest neighbors queries with context embeddings.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) --
  Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</paramsdesc><paramgroups>0</paramgroups></docstring>

Class for outputs of [DPRQuestionEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRQuestionEncoder).




</div>

<div class="docstring">

<docstring><name>class transformers.DPRReaderOutput</name><anchor>transformers.DPRReaderOutput</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L118</source><parameters>[{"name": "start_logits", "val": ": FloatTensor"}, {"name": "end_logits", "val": ": FloatTensor = None"}, {"name": "relevance_logits", "val": ": FloatTensor = None"}, {"name": "hidden_states", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}]</parameters><paramsdesc>- **start_logits** (`torch.FloatTensor` of shape `(n_passages, sequence_length)`) --
  Logits of the start index of the span for each passage.
- **end_logits** (`torch.FloatTensor` of shape `(n_passages, sequence_length)`) --
  Logits of the end index of the span for each passage.
- **relevance_logits** (`torch.FloatTensor` of shape `(n_passages, )`) --
  Outputs of the QA classifier of the DPRReader that corresponds to the scores of each passage to answer the
  question, compared to all the other passages.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) --
  Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</paramsdesc><paramgroups>0</paramgroups></docstring>

Class for outputs of [DPRQuestionEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRQuestionEncoder).




</div>

<h2 id="transformers.DPRContextEncoder">DPRContextEncoder</h2>

<div class="docstring">

<docstring><name>class transformers.DPRContextEncoder</name><anchor>transformers.DPRContextEncoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L445</source><parameters>[{"name": "config", "val": ": DPRConfig"}]</parameters><paramsdesc>- **config** ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
The bare DPRContextEncoder transformer outputting pooler outputs as context representations.

This model inherits from [PreTrainedModel](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel). Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)

This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.DPRContextEncoder.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L453</source><parameters>[{"name": "input_ids", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "attention_mask", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "token_type_ids", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "inputs_embeds", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "return_dict", "val": " = None"}]</parameters><paramsdesc>- **input_ids** (`torch.LongTensor` of shape `(batch_size, sequence_length)`) --
  Indices of input sequence tokens in the vocabulary. To match pretraining, DPR input sequence should be
  formatted with [CLS] and [SEP] tokens as follows:

  (a) For sequence pairs (for a pair title+text for example):

```
tokens:         [CLS] is this jack ##son ##ville ? [SEP] no it is not . [SEP]
token_type_ids:   0   0  0    0    0     0       0   0   1  1  1  1   1   1
```

  (b) For single sequences (for a question for example):

```
tokens:         [CLS] the dog is hairy . [SEP]
token_type_ids:   0   0   0   0  0     0   0
```

  DPR is a model with absolute position embeddings so it's usually advised to pad the inputs on the right
  rather than the left.

  Indices can be obtained using `DPRTokenizer`. See [PreTrainedTokenizer.encode()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode) and
  [PreTrainedTokenizer.__call__()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__) for details.

  [What are input IDs?](../glossary#input-ids)
- **attention_mask** (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **token_type_ids** (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
  1]`:

  - 0 corresponds to a *sentence A* token,
  - 1 corresponds to a *sentence B* token.

  [What are token type IDs?](../glossary#token-type-ids)
- **inputs_embeds** (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) --
  Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
  is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
  model's internal embedding lookup matrix.
- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.dpr.modeling_dpr.DPRContextEncoderOutput](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.models.dpr.modeling_dpr.DPRContextEncoderOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.dpr.modeling_dpr.DPRContextEncoderOutput](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.models.dpr.modeling_dpr.DPRContextEncoderOutput) 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 ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) and inputs.

- **pooler_output** (`torch.FloatTensor` of shape `(batch_size, embeddings_size)`) -- The DPR encoder outputs the *pooler_output* that corresponds to the context representation. Last layer
  hidden-state of the first token of the sequence (classification token) further processed by a Linear layer.
  This output is to be used to embed contexts for nearest neighbors queries with questions embeddings.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</retdesc></docstring>
The [DPRContextEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRContextEncoder) 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>







Examples:

```python
>>> from transformers import DPRContextEncoder, DPRContextEncoderTokenizer

>>> tokenizer = DPRContextEncoderTokenizer.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base")
>>> model = DPRContextEncoder.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base")
>>> input_ids = tokenizer("Hello, is my dog cute ?", return_tensors="pt")["input_ids"]
>>> embeddings = model(input_ids).pooler_output
```

</div></div>

<h2 id="transformers.DPRQuestionEncoder">DPRQuestionEncoder</h2>

<div class="docstring">

<docstring><name>class transformers.DPRQuestionEncoder</name><anchor>transformers.DPRQuestionEncoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L526</source><parameters>[{"name": "config", "val": ": DPRConfig"}]</parameters><paramsdesc>- **config** ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
The bare DPRQuestionEncoder transformer outputting pooler outputs as question representations.

This model inherits from [PreTrainedModel](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel). Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)

This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.DPRQuestionEncoder.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L534</source><parameters>[{"name": "input_ids", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "attention_mask", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "token_type_ids", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "inputs_embeds", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "return_dict", "val": " = None"}]</parameters><paramsdesc>- **input_ids** (`torch.LongTensor` of shape `(batch_size, sequence_length)`) --
  Indices of input sequence tokens in the vocabulary. To match pretraining, DPR input sequence should be
  formatted with [CLS] and [SEP] tokens as follows:

  (a) For sequence pairs (for a pair title+text for example):

```
tokens:         [CLS] is this jack ##son ##ville ? [SEP] no it is not . [SEP]
token_type_ids:   0   0  0    0    0     0       0   0   1  1  1  1   1   1
```

  (b) For single sequences (for a question for example):

```
tokens:         [CLS] the dog is hairy . [SEP]
token_type_ids:   0   0   0   0  0     0   0
```

  DPR is a model with absolute position embeddings so it's usually advised to pad the inputs on the right
  rather than the left.

  Indices can be obtained using `DPRTokenizer`. See [PreTrainedTokenizer.encode()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode) and
  [PreTrainedTokenizer.__call__()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__) for details.

  [What are input IDs?](../glossary#input-ids)
- **attention_mask** (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **token_type_ids** (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
  1]`:

  - 0 corresponds to a *sentence A* token,
  - 1 corresponds to a *sentence B* token.

  [What are token type IDs?](../glossary#token-type-ids)
- **inputs_embeds** (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) --
  Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
  is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
  model's internal embedding lookup matrix.
- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.dpr.modeling_dpr.DPRQuestionEncoderOutput](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.models.dpr.modeling_dpr.DPRQuestionEncoderOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.dpr.modeling_dpr.DPRQuestionEncoderOutput](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.models.dpr.modeling_dpr.DPRQuestionEncoderOutput) 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 ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) and inputs.

- **pooler_output** (`torch.FloatTensor` of shape `(batch_size, embeddings_size)`) -- The DPR encoder outputs the *pooler_output* that corresponds to the question representation. Last layer
  hidden-state of the first token of the sequence (classification token) further processed by a Linear layer.
  This output is to be used to embed questions for nearest neighbors queries with context embeddings.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</retdesc></docstring>
The [DPRQuestionEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRQuestionEncoder) 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>







Examples:

```python
>>> from transformers import DPRQuestionEncoder, DPRQuestionEncoderTokenizer

>>> tokenizer = DPRQuestionEncoderTokenizer.from_pretrained("facebook/dpr-question_encoder-single-nq-base")
>>> model = DPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base")
>>> input_ids = tokenizer("Hello, is my dog cute ?", return_tensors="pt")["input_ids"]
>>> embeddings = model(input_ids).pooler_output
```


</div></div>

<h2 id="transformers.DPRReader">DPRReader</h2>

<div class="docstring">

<docstring><name>class transformers.DPRReader</name><anchor>transformers.DPRReader</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L607</source><parameters>[{"name": "config", "val": ": DPRConfig"}]</parameters><paramsdesc>- **config** ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
The bare DPRReader transformer outputting span predictions.

This model inherits from [PreTrainedModel](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel). Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)

This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.DPRReader.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_dpr.py#L615</source><parameters>[{"name": "input_ids", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "attention_mask", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "inputs_embeds", "val": ": typing.Optional[torch.Tensor] = None"}, {"name": "output_attentions", "val": ": bool = None"}, {"name": "output_hidden_states", "val": ": bool = None"}, {"name": "return_dict", "val": " = None"}]</parameters><paramsdesc>input_ids -- (`Tuple[torch.LongTensor]` of shapes `(n_passages, sequence_length)`):
Indices of input sequence tokens in the vocabulary. It has to be a sequence triplet with 1) the question
and 2) the passages titles and 3) the passages texts To match pretraining, DPR `input_ids` sequence should
be formatted with [CLS] and [SEP] with the format:

`[CLS] &amp;lt;question token ids> [SEP] &amp;lt;titles ids> [SEP] &amp;lt;texts ids>`

DPR is a model with absolute position embeddings so it's usually advised to pad the inputs on the right
rather than the left.

Indices can be obtained using [DPRReaderTokenizer](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReaderTokenizer). See this class documentation for more details.

[What are input IDs?](../glossary#input-ids)
- **attention_mask** (`torch.FloatTensor` of shape `(n_passages, sequence_length)`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **inputs_embeds** (`torch.FloatTensor` of shape `(n_passages, sequence_length, hidden_size)`, *optional*) --
  Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
  is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
  model's internal embedding lookup matrix.
- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.dpr.modeling_dpr.DPRReaderOutput](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReaderOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.dpr.modeling_dpr.DPRReaderOutput](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReaderOutput) 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 ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) and inputs.

- **start_logits** (`torch.FloatTensor` of shape `(n_passages, sequence_length)`) -- Logits of the start index of the span for each passage.
- **end_logits** (`torch.FloatTensor` of shape `(n_passages, sequence_length)`) -- Logits of the end index of the span for each passage.
- **relevance_logits** (`torch.FloatTensor` of shape `(n_passages, )`) -- Outputs of the QA classifier of the DPRReader that corresponds to the scores of each passage to answer the
  question, compared to all the other passages.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</retdesc></docstring>
The [DPRReader](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReader) 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>







Examples:

```python
>>> from transformers import DPRReader, DPRReaderTokenizer

>>> tokenizer = DPRReaderTokenizer.from_pretrained("facebook/dpr-reader-single-nq-base")
>>> model = DPRReader.from_pretrained("facebook/dpr-reader-single-nq-base")
>>> encoded_inputs = tokenizer(
...     questions=["What is love ?"],
...     titles=["Haddaway"],
...     texts=["'What Is Love' is a song recorded by the artist Haddaway"],
...     return_tensors="pt",
... )
>>> outputs = model(**encoded_inputs)
>>> start_logits = outputs.start_logits
>>> end_logits = outputs.end_logits
>>> relevance_logits = outputs.relevance_logits
```


</div></div>

<h2 id="transformers.TFDPRContextEncoder">TFDPRContextEncoder</h2>

<div class="docstring">

<docstring><name>class transformers.TFDPRContextEncoder</name><anchor>transformers.TFDPRContextEncoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_tf_dpr.py#L585</source><parameters>[{"name": "*args", "val": ""}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.TFPreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
The bare DPRContextEncoder transformer outputting pooler outputs as context representations.

This model inherits from [TFPreTrainedModel](/docs/transformers/pr_15592/en/main_classes/model#transformers.TFPreTrainedModel). Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)

This model is also a Tensorflow [tf.keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model)
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.

<Tip>

TF 2.0 models accepts two formats as inputs:

- having all inputs as keyword arguments (like PyTorch models), or
- having all inputs as a list, tuple or dict in the first positional arguments.

This second option is useful when using `tf.keras.Model.fit` method which currently requires having all the
tensors in the first argument of the model call function: `model(inputs)`.

If you choose this second option, there are three possibilities you can use to gather all the input Tensors in the
first positional argument :

- a single Tensor with `input_ids` only and nothing else: `model(inputs_ids)`
- a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
`model([input_ids, attention_mask])` or `model([input_ids, attention_mask, token_type_ids])`
- a dictionary with one or several input Tensors associated to the input names given in the docstring:
`model(&amp;lcub;"input_ids": input_ids, "token_type_ids": token_type_ids})`

</Tip>





<div class="docstring">
<docstring><name>call</name><anchor>transformers.TFDPRContextEncoder.call</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_tf_dpr.py#L597</source><parameters>[{"name": "input_ids", "val": " = None"}, {"name": "attention_mask", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "token_type_ids", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "inputs_embeds", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "return_dict", "val": " = None"}, {"name": "training", "val": ": bool = False"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **input_ids** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length)`) --
  Indices of input sequence tokens in the vocabulary. To match pretraining, DPR input sequence should be
  formatted with [CLS] and [SEP] tokens as follows:

  (a) For sequence pairs (for a pair title+text for example):

```
tokens:         [CLS] is this jack ##son ##ville ? [SEP] no it is not . [SEP]
token_type_ids:   0   0  0    0    0     0       0   0   1  1  1  1   1   1
```

  (b) For single sequences (for a question for example):

```
tokens:         [CLS] the dog is hairy . [SEP]
token_type_ids:   0   0   0   0  0     0   0
```

  DPR is a model with absolute position embeddings so it's usually advised to pad the inputs on the right
  rather than the left.

  Indices can be obtained using `DPRTokenizer`. See [PreTrainedTokenizer.encode()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode) and
  [PreTrainedTokenizer.__call__()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__) for details.

  [What are input IDs?](../glossary#input-ids)
- **attention_mask** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **token_type_ids** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
  1]`:

  - 0 corresponds to a *sentence A* token,
  - 1 corresponds to a *sentence B* token.

  [What are token type IDs?](../glossary#token-type-ids)
- **inputs_embeds** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) --
  Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
  is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
  model's internal embedding lookup matrix.
- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail. This argument can be used only in eager mode, in graph mode the value in the
  config will be used instead.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail. This argument can be used only in eager mode, in graph mode the value in the config will be
  used instead.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple. This argument can be used
  in eager mode, in graph mode the value will always be set to True.
- **training** (`bool`, *optional*, defaults to `False`) --
  Whether or not to use the model in training mode (some modules like dropout modules have different
  behaviors between training and evaluation).</paramsdesc><paramgroups>0</paramgroups><rettype>`transformers.models.dpr.modeling_tf_dpr.TFDPRContextEncoderOutput`or `tuple(tf.Tensor)`</rettype><retdesc>A `transformers.models.dpr.modeling_tf_dpr.TFDPRContextEncoderOutput`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 ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) and inputs.

- **pooler_output** (`tf.Tensor` of shape `(batch_size, embeddings_size)`) -- The DPR encoder outputs the *pooler_output* that corresponds to the context representation. Last layer
  hidden-state of the first token of the sequence (classification token) further processed by a Linear layer.
  This output is to be used to embed contexts for nearest neighbors queries with questions embeddings.
- **hidden_states** (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
  `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</retdesc></docstring>
The [TFDPRContextEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.TFDPRContextEncoder) 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>







Examples:

```python
>>> from transformers import TFDPRContextEncoder, DPRContextEncoderTokenizer

>>> tokenizer = DPRContextEncoderTokenizer.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base")
>>> model = TFDPRContextEncoder.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base", from_pt=True)
>>> input_ids = tokenizer("Hello, is my dog cute ?", return_tensors="tf")["input_ids"]
>>> embeddings = model(input_ids).pooler_output
```


</div></div>

<h2 id="transformers.TFDPRQuestionEncoder">TFDPRQuestionEncoder</h2>

<div class="docstring">

<docstring><name>class transformers.TFDPRQuestionEncoder</name><anchor>transformers.TFDPRQuestionEncoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_tf_dpr.py#L686</source><parameters>[{"name": "*args", "val": ""}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.TFPreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
The bare DPRQuestionEncoder transformer outputting pooler outputs as question representations.

This model inherits from [TFPreTrainedModel](/docs/transformers/pr_15592/en/main_classes/model#transformers.TFPreTrainedModel). Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)

This model is also a Tensorflow [tf.keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model)
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.

<Tip>

TF 2.0 models accepts two formats as inputs:

- having all inputs as keyword arguments (like PyTorch models), or
- having all inputs as a list, tuple or dict in the first positional arguments.

This second option is useful when using `tf.keras.Model.fit` method which currently requires having all the
tensors in the first argument of the model call function: `model(inputs)`.

If you choose this second option, there are three possibilities you can use to gather all the input Tensors in the
first positional argument :

- a single Tensor with `input_ids` only and nothing else: `model(inputs_ids)`
- a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
`model([input_ids, attention_mask])` or `model([input_ids, attention_mask, token_type_ids])`
- a dictionary with one or several input Tensors associated to the input names given in the docstring:
`model(&amp;lcub;"input_ids": input_ids, "token_type_ids": token_type_ids})`

</Tip>





<div class="docstring">
<docstring><name>call</name><anchor>transformers.TFDPRQuestionEncoder.call</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_tf_dpr.py#L698</source><parameters>[{"name": "input_ids", "val": " = None"}, {"name": "attention_mask", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "token_type_ids", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "inputs_embeds", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "return_dict", "val": " = None"}, {"name": "training", "val": ": bool = False"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **input_ids** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length)`) --
  Indices of input sequence tokens in the vocabulary. To match pretraining, DPR input sequence should be
  formatted with [CLS] and [SEP] tokens as follows:

  (a) For sequence pairs (for a pair title+text for example):

```
tokens:         [CLS] is this jack ##son ##ville ? [SEP] no it is not . [SEP]
token_type_ids:   0   0  0    0    0     0       0   0   1  1  1  1   1   1
```

  (b) For single sequences (for a question for example):

```
tokens:         [CLS] the dog is hairy . [SEP]
token_type_ids:   0   0   0   0  0     0   0
```

  DPR is a model with absolute position embeddings so it's usually advised to pad the inputs on the right
  rather than the left.

  Indices can be obtained using `DPRTokenizer`. See [PreTrainedTokenizer.encode()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode) and
  [PreTrainedTokenizer.__call__()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__) for details.

  [What are input IDs?](../glossary#input-ids)
- **attention_mask** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **token_type_ids** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
  1]`:

  - 0 corresponds to a *sentence A* token,
  - 1 corresponds to a *sentence B* token.

  [What are token type IDs?](../glossary#token-type-ids)
- **inputs_embeds** (`Numpy array` or `tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) --
  Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
  is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
  model's internal embedding lookup matrix.
- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail. This argument can be used only in eager mode, in graph mode the value in the
  config will be used instead.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail. This argument can be used only in eager mode, in graph mode the value in the config will be
  used instead.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple. This argument can be used
  in eager mode, in graph mode the value will always be set to True.
- **training** (`bool`, *optional*, defaults to `False`) --
  Whether or not to use the model in training mode (some modules like dropout modules have different
  behaviors between training and evaluation).</paramsdesc><paramgroups>0</paramgroups><rettype>`transformers.models.dpr.modeling_tf_dpr.TFDPRQuestionEncoderOutput`or `tuple(tf.Tensor)`</rettype><retdesc>A `transformers.models.dpr.modeling_tf_dpr.TFDPRQuestionEncoderOutput`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 ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) and inputs.

- **pooler_output** (`tf.Tensor` of shape `(batch_size, embeddings_size)`) -- The DPR encoder outputs the *pooler_output* that corresponds to the question representation. Last layer
  hidden-state of the first token of the sequence (classification token) further processed by a Linear layer.
  This output is to be used to embed questions for nearest neighbors queries with context embeddings.
- **hidden_states** (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
  `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</retdesc></docstring>
The [TFDPRQuestionEncoder](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.TFDPRQuestionEncoder) 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>







Examples:

```python
>>> from transformers import TFDPRQuestionEncoder, DPRQuestionEncoderTokenizer

>>> tokenizer = DPRQuestionEncoderTokenizer.from_pretrained("facebook/dpr-question_encoder-single-nq-base")
>>> model = TFDPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base", from_pt=True)
>>> input_ids = tokenizer("Hello, is my dog cute ?", return_tensors="tf")["input_ids"]
>>> embeddings = model(input_ids).pooler_output
```


</div></div>

<h2 id="transformers.TFDPRReader">TFDPRReader</h2>

<div class="docstring">

<docstring><name>class transformers.TFDPRReader</name><anchor>transformers.TFDPRReader</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_tf_dpr.py#L786</source><parameters>[{"name": "*args", "val": ""}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.TFPreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
The bare DPRReader transformer outputting span predictions.

This model inherits from [TFPreTrainedModel](/docs/transformers/pr_15592/en/main_classes/model#transformers.TFPreTrainedModel). Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)

This model is also a Tensorflow [tf.keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model)
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.

<Tip>

TF 2.0 models accepts two formats as inputs:

- having all inputs as keyword arguments (like PyTorch models), or
- having all inputs as a list, tuple or dict in the first positional arguments.

This second option is useful when using `tf.keras.Model.fit` method which currently requires having all the
tensors in the first argument of the model call function: `model(inputs)`.

If you choose this second option, there are three possibilities you can use to gather all the input Tensors in the
first positional argument :

- a single Tensor with `input_ids` only and nothing else: `model(inputs_ids)`
- a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
`model([input_ids, attention_mask])` or `model([input_ids, attention_mask, token_type_ids])`
- a dictionary with one or several input Tensors associated to the input names given in the docstring:
`model(&amp;lcub;"input_ids": input_ids, "token_type_ids": token_type_ids})`

</Tip>





<div class="docstring">
<docstring><name>call</name><anchor>transformers.TFDPRReader.call</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/dpr/modeling_tf_dpr.py#L798</source><parameters>[{"name": "input_ids", "val": " = None"}, {"name": "attention_mask", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "inputs_embeds", "val": ": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"}, {"name": "output_attentions", "val": ": bool = None"}, {"name": "output_hidden_states", "val": ": bool = None"}, {"name": "return_dict", "val": " = None"}, {"name": "training", "val": ": bool = False"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>input_ids -- (`Numpy array` or `tf.Tensor` of shapes `(n_passages, sequence_length)`):
Indices of input sequence tokens in the vocabulary. It has to be a sequence triplet with 1) the question
and 2) the passages titles and 3) the passages texts To match pretraining, DPR `input_ids` sequence should
be formatted with [CLS] and [SEP] with the format:

`[CLS] &amp;lt;question token ids> [SEP] &amp;lt;titles ids> [SEP] &amp;lt;texts ids>`

DPR is a model with absolute position embeddings so it's usually advised to pad the inputs on the right
rather than the left.

Indices can be obtained using [DPRReaderTokenizer](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRReaderTokenizer). See this class documentation for more details.
- **attention_mask** (`Numpy array` or `tf.Tensor` of shape `(n_passages, sequence_length)`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **inputs_embeds** (`Numpy array` or `tf.Tensor` of shape `(n_passages, sequence_length, hidden_size)`, *optional*) --
  Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
  is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
  model's internal embedding lookup matrix.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail. This argument can be used only in eager mode, in graph mode the value in the config will be
  used instead.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple. This argument can be used
  in eager mode, in graph mode the value will always be set to True.
- **training** (`bool`, *optional*, defaults to `False`) --
  Whether or not to use the model in training mode (some modules like dropout modules have different
  behaviors between training and evaluation).</paramsdesc><paramgroups>0</paramgroups><rettype>`transformers.models.dpr.modeling_tf_dpr.TFDPRReaderOutput`or `tuple(tf.Tensor)`</rettype><retdesc>A `transformers.models.dpr.modeling_tf_dpr.TFDPRReaderOutput`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 ([DPRConfig](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.DPRConfig)) and inputs.

- **start_logits** (`tf.Tensor` of shape `(n_passages, sequence_length)`) -- Logits of the start index of the span for each passage.
- **end_logits** (`tf.Tensor` of shape `(n_passages, sequence_length)`) -- Logits of the end index of the span for each passage.
- **relevance_logits** (`tf.Tensor` of shape `(n_passages, )`) -- Outputs of the QA classifier of the DPRReader that corresponds to the scores of each passage to answer the
  question, compared to all the other passages.
- **hidden_states** (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
  `(batch_size, sequence_length, hidden_size)`.

  Hidden-states of the model at the output of each layer plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`.

  Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
  heads.</retdesc></docstring>
The [TFDPRReader](/docs/transformers/pr_15592/en/model_doc/dpr#transformers.TFDPRReader) 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>







Examples:

```python
>>> from transformers import TFDPRReader, DPRReaderTokenizer

>>> tokenizer = DPRReaderTokenizer.from_pretrained("facebook/dpr-reader-single-nq-base")
>>> model = TFDPRReader.from_pretrained("facebook/dpr-reader-single-nq-base", from_pt=True)
>>> encoded_inputs = tokenizer(
...     questions=["What is love ?"],
...     titles=["Haddaway"],
...     texts=["'What Is Love' is a song recorded by the artist Haddaway"],
...     return_tensors="tf",
... )
>>> outputs = model(encoded_inputs)
>>> start_logits = outputs.start_logits
>>> end_logits = outputs.end_logits
>>> relevance_logits = outputs.relevance_logits
```


</div></div>
