autorag.nodes.passagereranker.tart package¶
Submodules¶
autorag.nodes.passagereranker.tart.modeling_enc_t5 module¶
- class autorag.nodes.passagereranker.tart.modeling_enc_t5.EncT5ForSequenceClassification(config: T5Config, dropout=0.1)[source]¶
Bases:
T5PreTrainedModel
- forward(input_ids=None, attention_mask=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
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 registered hooks while the latter silently ignores them.
autorag.nodes.passagereranker.tart.tart module¶
- autorag.nodes.passagereranker.tart.tart.tart(queries: List[str], contents_list: List[List[str]], scores_list: List[List[float]], ids_list: List[List[str]], top_k: int, instruction: str = 'Find passage to answer given question', batch: int = 64) Tuple[List[List[str]], List[List[str]], List[List[float]]] [source]¶
Rerank a list of contents based on their relevance to a query using Tart. TART is a reranker based on TART (https://github.com/facebookresearch/tart). You can rerank the passages with the instruction using TARTReranker. The default model is facebook/tart-full-flan-t5-xl.
- Parameters:
queries – The list of queries to use for reranking
contents_list – The list of lists of contents to rerank
scores_list – The list of lists of scores retrieved from the initial ranking
ids_list – The list of lists of ids retrieved from the initial ranking
top_k – The number of passages to be retrieved
instruction –
The instruction for reranking. Note: default instruction is “Find passage to answer given question”
The default instruction from the TART paper is being used. If you want to use a different instruction, you can change the instruction through this parameter
batch – The number of queries to be processed in a batch
- Returns:
tuple of lists containing the reranked contents, ids, and scores
autorag.nodes.passagereranker.tart.tokenization_enc_t5 module¶
- class autorag.nodes.passagereranker.tart.tokenization_enc_t5.EncT5Tokenizer(vocab_file, bos_token='<s>', eos_token='</s>', unk_token='<unk>', pad_token='<pad>', extra_ids=100, additional_special_tokens=None, sp_model_kwargs: Dict[str, Any] | None = None, **kwargs)[source]¶
Bases:
T5Tokenizer
- build_inputs_with_special_tokens(token_ids_0: List[int], token_ids_1: List[int] | None = None) List[int] [source]¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A sequence has the following format: - single sequence: <s> X </s> - pair of sequences: <s> A </s> B </s> Args:
- token_ids_0 (List[int]):
List of IDs to which the special tokens will be added.
- token_ids_1 (List[int], optional):
Optional second list of IDs for sequence pairs.
- Returns:
List[int]: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
- create_token_type_ids_from_sequences(token_ids_0: List[int], token_ids_1: List[int] | None = None) List[int] [source]¶
Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 does not make use of token type ids, therefore a list of zeros is returned. Args:
- token_ids_0 (List[int]):
List of IDs.
- token_ids_1 (List[int], optional):
Optional second list of IDs for sequence pairs.
- Returns:
List[int]: List of zeros.
- get_special_tokens_mask(token_ids_0: List[int], token_ids_1: List[int] | None = None, already_has_special_tokens: bool = False) List[int] [source]¶
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer prepare_for_model method. Args:
- token_ids_0 (List[int]):
List of IDs.
- token_ids_1 (List[int], optional):
Optional second list of IDs for sequence pairs.
- already_has_special_tokens (bool, optional, defaults to False):
Whether or not the token list is already formatted with special tokens for the model.
- Returns:
List[int]: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.