
    #i                        d dl mZ d dlZd dlmZ 	 d dlmZ d dl	m
Z
mZ d dlmZ d dlmZmZ  ej"                  e      Z G d d	e      Zy# e$ r	 d dlmZ Y Aw xY w)
    )annotationsN)Callable)Self)Tensornn)Module)fullnameimport_from_stringc                       e Zd ZU dZg dZded<   d ej                         ddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZdd	Z	dd
Z
 fdZddddZe	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z xZS )Densea  Applies a linear transformation with an optional activation function.

    Passes the embedding through a feed-forward layer (``nn.Linear`` + activation), useful for
    dimensionality reduction or projecting embeddings into a different space.

    Args:
        in_features: Size of the input dimension.
        out_features: Size of the output dimension.
        bias: Whether to include a bias vector in the linear layer.
        activation_function: Activation function applied after the linear layer.
            If ``None``, uses ``nn.Identity()``. Defaults to ``nn.Tanh()``.
        init_weight: Initial value for the weight matrix of the linear layer.
        init_bias: Initial value for the bias vector of the linear layer.
        module_input_name: The key in the features dictionary to read the input from.
            Defaults to ``"sentence_embedding"``.
        module_output_name: The key in the features dictionary to store the output in.
            If ``None``, uses the same key as ``module_input_name``.
    )in_featuresout_featuresbiasactivation_functionmodule_input_namemodule_output_namez	list[str]config_keysTNsentence_embeddingc	                   t         	|           || _        || _        || _        |t        j                         n|| _        t        j                  |||      | _	        || _
        ||n|| _        |$t        j                  |      | j                  _        |(|r%t        j                  |      | j                  _        y y y )N)r   )super__init__r   r   r   r   Identityr   Linearlinearr   r   	Parameterweight)
selfr   r   r   r   init_weight	init_biasr   r   	__class__s
            y/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/sentence_transformers/base/modules/dense.pyr   zDense.__init__0   s     	&(	4G4O2;;=Uh ii\E!28J8V"4\m"!#k!:DKK T!||I6DKK &*     c           	         |j                  | j                  | j                  | j                  || j                                 i       |S N)updater   r   r   r   )r   featuress     r!   forwardzDense.forwardJ   sC    $$d&>&>t{{8TXTjTjKk?l&mn	
 r"   c                    | j                   S r$   )r   )r   s    r!   get_embedding_dimensionzDense.get_embedding_dimensionP   s       r"   c                T    t         |          }t        | j                        |d<   |S )Nr   )r   get_config_dictr	   r   )r   configr    s     r!   r+   zDense.get_config_dictS   s+    (*(01I1I(J$%r"   safe_serializationc               L    | j                  |       | j                  ||       y )Nr-   )save_configsave_torch_weights)r   output_pathr.   argskwargss        r!   savez
Dense.saveX   s$    %@RSr"   c                   |||||d}	 | j                   dd|i|	}
d|
v rL|s|
d   j                  d      r t        |
d                |
d<   nt        j	                  d|
d    d       |
d=  | di |
} | j
                  d||d|	}|S )	N)	subfoldertokencache_folderrevisionlocal_files_onlymodel_name_or_pathr   ztorch.zActivation function path 'z' is not trusted, falling back to the default activation function (Tanh). Please load the model with `trust_remote_code=True` to allow loading custom activation functions via the configuration.)r<   model )load_config
startswithr
   loggerwarningload_torch_weights)clsr<   r7   r8   r9   r:   r;   trust_remote_coder4   
hub_kwargsr,   r=   s               r!   loadz
Dense.load\   s     #(  0

 !U4FU*U F* F+@$A$L$LX$V0a0B6J_C`0a0c,-08M1N0O P7 7 01f&&&h:LTYh]ghr"   )r   intr   rH   r   boolr   z!Callable[[Tensor], Tensor] | Noner   Tensor | Noner   rJ   r   strr   
str | None)r&   zdict[str, Tensor])returnrH   )r2   rK   r.   rI   rM   None) NNNFF)r<   rK   r7   rK   r8   zbool | str | Noner9   rL   r:   rL   r;   rI   rE   rI   rM   r   )__name__
__module____qualname____doc__r   __annotations__r   Tanhr   r'   r)   r+   r5   classmethodrG   __classcell__)r    s   @r!   r   r      s   &K  AH%)#'!5)-77 7 	7
 ?7 #7 !7 7 '74!
 HL T  #'#'#!&"'     !	 
 !         
   r"   r   )
__future__r   loggingcollections.abcr   typingr   ImportErrortyping_extensionstorchr   r   )sentence_transformers.base.modules.moduler   sentence_transformers.utilr	   r
   	getLoggerrP   rA   r   r>   r"   r!   <module>rb      sU    "  $'  < C			8	$jF j  '&'s   A AA