ó
    >:jí  ã                  ó¢   • S SK Jr  S SKJr  S SKrS SKJr  S SKJr  S SK	J
r  S SKJrJrJr  S SKJr  \R$                  " \5      r " S	 S
\5      rg)é    )Úannotations)ÚAnyN)Ú	Tokenizer)ÚPreTrainedTokenizerBase)Úlogging)ÚModalityÚ	PairInputÚSingleInput)ÚModulec                  óŠ   • \ rS rSr% SrSrS\S'   S\S'    \SS j5       r\	SS	 j5       r
 S     SS jjrSS jrSS jrSrg
)ÚInputModuleé   aq  
Subclass of :class:`sentence_transformers.base.modules.Module`, base class for all input modules in the Sentence
Transformers library, i.e. modules that are used to process inputs and optionally also perform processing
in the forward pass.

This class provides a common interface for all input modules, including methods for loading and saving the module's
configuration and weights, as well as input processing. It also provides a method for performing the forward pass
of the module.

Two abstract methods are inherited from :class:`~sentence_transformers.base.modules.Module` and must be implemented
by subclasses:

- :meth:`sentence_transformers.base.modules.Module.forward`: The forward pass of the module.
- :meth:`sentence_transformers.base.modules.Module.save`: Save the module to disk.

Additionally, subclasses should override:

- :meth:`sentence_transformers.base.modules.InputModule.preprocess`: Preprocess the inputs and return a dictionary of preprocessed features.

Optionally, you may also have to override:

- :attr:`sentence_transformers.base.modules.InputModule.modalities`: The list of supported input modalities. Defaults to ``["text"]``. Override this to advertise support for non-text modalities (e.g. ``["text", "image"]``).
- :meth:`sentence_transformers.base.modules.Module.load`: Load the module from disk.

To assist with loading and saving the module, several utility methods are provided:

- :meth:`sentence_transformers.base.modules.Module.load_config`: Load the module's configuration from a JSON file.
- :meth:`sentence_transformers.base.modules.Module.load_file_path`: Load a file from the module's directory, regardless of whether the module is saved locally or on Hugging Face.
- :meth:`sentence_transformers.base.modules.Module.load_dir_path`: Load a directory from the module's directory, regardless of whether the module is saved locally or on Hugging Face.
- :meth:`sentence_transformers.base.modules.Module.load_torch_weights`: Load the PyTorch weights of the module, regardless of whether the module is saved locally or on Hugging Face.
- :meth:`sentence_transformers.base.modules.Module.save_config`: Save the module's configuration to a JSON file.
- :meth:`sentence_transformers.base.modules.Module.save_torch_weights`: Save the PyTorch weights of the module.
- :meth:`sentence_transformers.base.modules.InputModule.save_tokenizer`: Save the tokenizer used by the module.
- :meth:`sentence_transformers.base.modules.Module.get_config_dict`: Get the module's configuration as a dictionary.

And several class variables are defined to assist with loading and saving the module:

- :attr:`sentence_transformers.base.modules.Module.config_file_name`: The name of the configuration file used to save the module's configuration.
- :attr:`sentence_transformers.base.modules.Module.config_keys`: A list of keys used to save the module's configuration.
- :attr:`sentence_transformers.base.modules.InputModule.save_in_root`: Whether to save the module's configuration in the root directory of the model or in a subdirectory named after the module.
- :attr:`sentence_transformers.base.modules.InputModule.tokenizer`: The tokenizer used by the module.
TÚboolÚsave_in_rootz#PreTrainedTokenizerBase | TokenizerÚ	tokenizerc                ó   • S/$ )zAThe list of supported input modalities. Defaults to ``["text"]``.Útext© )Úselfs    Úl/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sentence_transformers/base/modules/input_module.pyÚ
modalitiesÚInputModule.modalitiesE   s   € ð ˆxˆó    c                ó6   • U  Vs/ s H  o!U-   PM	     sn$ s  snf )z+Prepend a prompt string to each text input.r   )ÚinputsÚpromptr   s      r   Ú_prepend_promptÚInputModule._prepend_promptJ   s   € ñ +1Ó1ª& $˜”©&Ñ1Ð1ùÒ1s   …Nc                ó<  • [        U 5      R                  [        R                  LaV  [        R	                  [        U 5      R
                   S35        U(       a  U R                  X5      nU R                  " U40 UD6$ [        [        U 5      R
                   S35      e)a  
Preprocesses the input texts and returns a dictionary of preprocessed features.

Args:
    inputs (list[SingleInput | PairInput]): List of inputs to preprocess.
    prompt (str | None): Optional prompt to prepend to text inputs.
    **kwargs: Additional keyword arguments for preprocessing, e.g. ``task``.

Returns:
    dict[str, torch.Tensor | Any]: Dictionary containing preprocessed features, e.g.
        ``{"input_ids": ..., "attention_mask": ...}``, depending on what keys the module's forward method expects.
zn overrides `tokenize` instead of `preprocess`. `tokenize` is deprecated, please override `preprocess` instead.z( must implement the `preprocess` method.)ÚtypeÚtokenizer   ÚloggerÚwarning_onceÚ__name__r   ÚNotImplementedError)r   r   r   Úkwargss       r   Ú
preprocessÚInputModule.preprocessO   s�   € ô* �‹:×Ñ¤k×&:Ñ&:Ò:Ü×ÑÜ˜“:×&Ñ&Ð'ð (Rð Rôö Ø×-Ñ-¨fÓ=�Ø—=’= Ñ2¨6Ñ2Ð2Ü!¤T¨$£Z×%8Ñ%8Ð$9Ð9aÐ"bÓcÐcr   c                óR   • [         R                  S5        U R                  " U40 UD6$ )a±  
.. deprecated::
    `tokenize` is deprecated. Use `preprocess` instead.

Tokenizes the input texts and returns a dictionary of tokenized features.

Args:
    texts (list[str]): List of input texts to tokenize.
    **kwargs: Additional keyword arguments for tokenization, e.g. ``task``.

Returns:
    dict[str, torch.Tensor | Any]: Dictionary containing tokenized features, e.g.
        ``{"input_ids": ..., "attention_mask": ...}``
zEThe `tokenize` method is deprecated, please use `preprocess` instead.)r"   r#   r'   )r   Útextsr&   s      r   r!   ÚInputModule.tokenizen   s+   € ô 	×ÑØSô	
ð �Š˜uÑ/¨Ñ/Ð/r   c                ó  • [        U S5      (       d  g[        U R                  [        5      (       a  U R                  R                  " U40 UD6  g[        U R                  [
        5      (       a  U R                  R                  " U40 UD6  g)zÅ
Saves the tokenizer to the specified output path.

Args:
    output_path (str): Path to save the tokenizer.
    **kwargs: Additional keyword arguments for saving the tokenizer.

Returns:
    None
r   N)ÚhasattrÚ
isinstancer   r   Úsave_pretrainedr   Úsave)r   Úoutput_pathr&   s      r   Úsave_tokenizerÚInputModule.save_tokenizer‚   so   € ô �t˜[×)Ñ)Øä�d—n‘nÔ&=×>Ñ>Ø�N‰N×*Ò*¨;ÑA¸&ÒAð 	ô ˜Ÿ™¬	×2Ñ2Ø�N‰N×Ò Ñ6¨vÒ6Ør   r   )Úreturnzlist[Modality])r   ú	list[str]r   Ústrr4   r5   )N)r   zlist[SingleInput | PairInput]r   z
str | Noner4   údict[str, torch.Tensor | Any])r*   r5   r4   r7   )r1   r6   r4   ÚNone)r$   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__annotations__Úpropertyr   Ústaticmethodr   r'   r!   r2   Ú__static_attributes__r   r   r   r   r      s{   ‡ ñ)ðV €L�$ÓØ2Ó2ðð óó ðð ó2ó ð2ð "ðdà-ðdð ðdð
 
'õdô>0÷(r   r   )Ú
__future__r   Útypingr   ÚtorchÚ
tokenizersr   Ú$transformers.tokenization_utils_baser   Útransformers.utilsr   Útransformers_loggingÚ)sentence_transformers.base.modality_typesr   r	   r
   Ú)sentence_transformers.base.modules.moduler   Ú
get_loggerr$   r"   r   r   r   r   Ú<module>rK      s@   ðÝ "å ã Ý  Ý HÝ >ç VÑ VÝ <ð 
×	(Ò	(¨Ó	2€ôC�&õ Cr   