
    Z jX                     P   S r SSKrSSKJrJrJr  SSKJrJrJ	r	J
r
JrJrJr  SSKJr  SSKJrJr  SSKJr  S	S
KJrJrJrJrJrJrJrJr   " S S\5      r " S S\5      r " S S\5      r  " S S\5      r! " S S\5      r" " S S\5      r# " S S\5      r$ " S S\5      r%/ SQr&g)zPyTorch CamemBERT model.    N)BCEWithLogitsLossCrossEntropyLossMSELoss   ),BaseModelOutputWithPoolingAndCrossAttentions!CausalLMOutputWithCrossAttentionsMaskedLMOutputMultipleChoiceModelOutputQuestionAnsweringModelOutputSequenceClassifierOutputTokenClassifierOutput)Unpack)TransformersKwargsauto_docstring)can_return_tuple   )RobertaForCausalLMRobertaForMaskedLMRobertaForMultipleChoiceRobertaForQuestionAnswering RobertaForSequenceClassificationRobertaForTokenClassificationRobertaModelRobertaPreTrainedModelc                       \ rS rSrSrSrg)CamembertPreTrainedModel,   roberta N)__name__
__module____qualname____firstlineno__base_model_prefix__static_attributes__r       ڀ/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/camembert/modular_camembert.pyr   r   ,   s    !r&   r   c                       \ rS rSrSrg)CamembertModel0   r   N)r    r!   r"   r#   r%   r   r&   r'   r)   r)   0   s    r&   r)   c                     ^  \ rS rSrSSS.rU 4S jr\\        SS\R                  S-  S\R                  S-  S	\R                  S-  S
\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\\   S\\R                     \-  4S jj5       5       rSrU =r$ )CamembertForMaskedLM4   )roberta.embeddings.word_embeddings.weightlm_head.biaszlm_head.decoder.weightzlm_head.decoder.biasc                 F   > [         TU ]  U5        U ?[        USS9U l        g NF)add_pooling_layersuper__init__	camembertr)   r   selfconfig	__class__s     r'   r6   CamembertForMaskedLM.__init__:   #     N%fFr&   N	input_idsattention_masktoken_type_idsposition_idsinputs_embedsencoder_hidden_statesencoder_attention_masklabelskwargsreturnc	                 p   U R                   " U4UUUUUUSS.U	D6n
U
S   nU R                  U5      nSnUba  UR                  UR                  5      n[	        5       nU" UR                  SU R                  R                  5      UR                  S5      5      n[        UUU
R                  U
R                  S9$ )a  
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.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
    config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
    loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`
T)r?   r@   rA   rB   rC   rD   return_dictr   Nlosslogitshidden_states
attentions)r   lm_headtodevicer   viewr:   
vocab_sizer	   rN   rO   )r9   r>   r?   r@   rA   rB   rC   rD   rE   rF   outputssequence_outputprediction_scoresmasked_lm_lossloss_fcts                  r'   forwardCamembertForMaskedLM.forward@   s    : ,,

))%'"7#9

 

 "!* LL9YY0778F')H%&7&<&<RAWAW&XZ`ZeZefhZijN$!//))	
 	
r&   r   )NNNNNNNN)r    r!   r"   r#   _tied_weights_keysr6   r   r   torch
LongTensorFloatTensorr   r   tupleTensorr	   rZ   r%   __classcell__r;   s   @r'   r,   r,   4   s   "M .
G  .237260426:>;?*.5
##d*5
 ))D05
 ((4/	5

 &&-5
 ((4/5
  %00475
 !& 1 1D 85
   4'5
 +,5
 
u||	~	-5
  5
r&   r,   c                   8  ^  \ rS rSrU 4S jr\\      SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\
\   S\\R                     \-  4S jj5       5       rSrU =r$ )"CamembertForSequenceClassificationz   c                 F   > [         TU ]  U5        U ?[        USS9U l        g r2   r4   r8   s     r'   r6   +CamembertForSequenceClassification.__init__{   r=   r&   Nr>   r?   r@   rA   rB   rE   rF   rG   c           	         U R                   " U4UUUUSS.UD6nUS   n	U R                  U	5      n
SnUGb  UR                  U
R                  5      nU R                  R
                  c  U R                  S:X  a  SU R                  l        OoU R                  S:  aN  UR                  [        R                  :X  d  UR                  [        R                  :X  a  SU R                  l        OSU R                  l        U R                  R
                  S:X  aI  [        5       nU R                  S:X  a&  U" U
R                  5       UR                  5       5      nOU" X5      nOU R                  R
                  S:X  a=  [        5       nU" U
R                  S	U R                  5      UR                  S	5      5      nO,U R                  R
                  S:X  a  [        5       nU" X5      n[!        UU
UR"                  UR$                  S
9$ )a  
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.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
    config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
    `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
Tr?   r@   rA   rB   rI   r   N   
regressionsingle_label_classificationmulti_label_classificationrJ   rK   )r   
classifierrQ   rR   r:   problem_type
num_labelsdtyper^   longintr   squeezer   rS   r   r   rN   rO   r9   r>   r?   r@   rA   rB   rE   rF   rU   rV   rM   rL   rY   s                r'   rZ   *CamembertForSequenceClassification.forward   s   6 ,,
))%'
 
 "!*1YYv}}-F{{''/??a'/;DKK,__q(fllejj.HFLL\a\e\eLe/LDKK,/KDKK,{{''<7"9??a'#FNN$4fnn6FGD#F3D))-JJ+-B @&++b/R))-II,./'!//))	
 	
r&   r\   NNNNNN)r    r!   r"   r#   r6   r   r   r^   r_   r`   r   r   ra   rb   r   rZ   r%   rc   rd   s   @r'   rf   rf   z   s    G  .237260426*.C
##d*C
 ))D0C
 ((4/	C

 &&-C
 ((4/C
   4'C
 +,C
 
u||	7	7C
  C
r&   rf   c                   8  ^  \ rS rSrU 4S jr\\      SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\
\   S\\R                     \-  4S jj5       5       rSrU =r$ )CamembertForMultipleChoice   c                 F   > [         TU ]  U5        U ?[        USS9U l        g r2   r4   r8   s     r'   r6   #CamembertForMultipleChoice.__init__   r=   r&   Nr>   r@   r?   rE   rA   rB   rF   rG   c           	      *   Ub  UR                   S   OUR                   S   nUb!  UR                  SUR                  S5      5      OSn	Ub!  UR                  SUR                  S5      5      OSn
Ub!  UR                  SUR                  S5      5      OSnUb!  UR                  SUR                  S5      5      OSnUb1  UR                  SUR                  S5      UR                  S5      5      OSnU R                  " U	4U
UUUSS.UD6nUS   nU R	                  U5      nU R                  U5      nUR                  SU5      nSnUb.  UR                  UR                  5      n[        5       nU" UU5      n[        UUUR                  UR                  S9$ )aO  
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
    Indices of input sequence tokens in the vocabulary.

    Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
    [`PreTrainedTokenizer.__call__`] for details.

    [What are input IDs?](../glossary#input-ids)
token_type_ids (`torch.LongTensor` of shape `(batch_size, num_choices, 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.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the multiple choice classification loss. Indices should be in `[0, ...,
    num_choices-1]` where `num_choices` is the size of the second dimension of the input tensors. (See
    `input_ids` above)
position_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`, *optional*):
    Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
    config.max_position_embeddings - 1]`.

    [What are position IDs?](../glossary#position-ids)
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, num_choices, 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.
Nrl   rJ   T)rA   r@   r?   rB   rI   rK   )shaperS   sizer   dropoutrp   rQ   rR   r   r
   rN   rO   )r9   r>   r@   r?   rE   rA   rB   rF   num_choicesflat_input_idsflat_position_idsflat_token_type_idsflat_attention_maskflat_inputs_embedsrU   pooled_outputrM   reshaped_logitsrL   rY   s                       r'   rZ   "CamembertForMultipleChoice.forward   s   V -6,Aiooa(}GZGZ[\G]CLCXINN2,>?^bLXLdL--b,2C2CB2GHjnR`Rln11"n6I6I"6MNrvR`Rln11"n6I6I"6MNrv ( r=#5#5b#9=;M;Mb;QR 	 ,,
*..,
 
  
]3/ ++b+6YY556F')HOV4D("!//))	
 	
r&   r\   ry   )r    r!   r"   r#   r6   r   r   r^   r_   r`   r   r   ra   rb   r
   rZ   r%   rc   rd   s   @r'   r{   r{      s    G  .22637*.0426P
##d*P
 ((4/P
 ))D0	P

   4'P
 &&-P
 ((4/P
 +,P
 
u||	8	8P
  P
r&   r{   c                   8  ^  \ rS rSrU 4S jr\\      SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\
\   S\\R                     \-  4S jj5       5       rSrU =r$ )CamembertForTokenClassificationi%  c                 F   > [         TU ]  U5        U ?[        USS9U l        g r2   r4   r8   s     r'   r6   (CamembertForTokenClassification.__init__&  r=   r&   Nr>   r?   r@   rA   rB   rE   rF   rG   c           	      z   U R                   " U4UUUUSS.UD6nUS   n	U R                  U	5      n	U R                  U	5      n
SnUbW  UR                  U
R                  5      n[        5       nU" U
R                  SU R                  5      UR                  S5      5      n[        UU
UR                  UR                  S9$ )a  
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.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
Trk   r   NrJ   rK   )r   r   rp   rQ   rR   r   rS   rr   r   rN   rO   rw   s                r'   rZ   'CamembertForTokenClassification.forward,  s    2 ,,
))%'
 
 "!*,,71YYv}}-F')HFKKDOO<fkk"oND$!//))	
 	
r&   r\   ry   )r    r!   r"   r#   r6   r   r   r^   r_   r`   r   r   ra   rb   r   rZ   r%   rc   rd   s   @r'   r   r   %  s    G  .237260426*.2
##d*2
 ))D02
 ((4/	2

 &&-2
 ((4/2
   4'2
 +,2
 
u||	4	42
  2
r&   r   c                   X  ^  \ rS rSrU 4S jr\\       SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\R                  S-  S\
\   S\\R                     \-  4S jj5       5       rSrU =r$ )CamembertForQuestionAnsweringic  c                 F   > [         TU ]  U5        U ?[        USS9U l        g r2   r4   r8   s     r'   r6   &CamembertForQuestionAnswering.__init__d  r=   r&   Nr>   r?   r@   rA   rB   start_positionsend_positionsrF   rG   c           	         U R                   " U4UUUUSS.UD6n	U	S   n
U R                  U
5      nUR                  SSS9u  pUR                  S5      R	                  5       nUR                  S5      R	                  5       nSnUb  Ub  [        UR                  5       5      S:  a  UR                  S5      n[        UR                  5       5      S:  a  UR                  S5      nUR                  S5      nUR                  SU5      nUR                  SU5      n[        US9nU" X5      nU" X5      nUU-   S	-  n[        UUUU	R                  U	R                  S
9$ )a  
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.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
Trk   r   rl   rJ   )dimN)ignore_indexr   )rL   start_logits
end_logitsrN   rO   )r   
qa_outputssplitrv   
contiguouslenr   clampr   r   rN   rO   )r9   r>   r?   r@   rA   rB   r   r   rF   rU   rV   rM   r   r   
total_lossignored_indexrY   
start_lossend_losss                      r'   rZ   %CamembertForQuestionAnswering.forwardj  sx   0 ,,
))%'
 
 "!*1#)<<r<#: #++B/::<''+668

&=+D?'')*Q."1"9"9""==%%'(1, - 5 5b 9(--a0M-33A}EO)//=AM']CH!,@J
:H$x/14J+%!!//))
 	
r&   r\   )NNNNNNN)r    r!   r"   r#   r6   r   r   r^   r_   r`   r   r   ra   rb   r   rZ   r%   rc   rd   s   @r'   r   r   c  s    G  .2372604263715>
##d*>
 ))D0>
 ((4/	>

 &&->
 ((4/>
 ))D0>
 ''$.>
 +,>
 
u||	;	;>
  >
r&   r   c                     ^  \ rS rSrSSS.rU 4S jr\\           SS\R                  S-  S\R                  S-  S	\R                  S-  S
\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\\\R                        S-  S\S-  S\\R                  -  S\\   S\\R                     \-  4S jj5       5       rSrU =r$ )CamembertForCausalLMi  r.   r/   r0   c                 F   > [         TU ]  U5        U ?[        USS9U l        g r2   r4   r8   s     r'   r6   CamembertForCausalLM.__init__  r=   r&   Nr>   r?   r@   rA   rB   rC   rD   rE   past_key_values	use_cachelogits_to_keeprF   rG   c                    Ub  Sn
U R                   " U4UUUUUUU	U
SS.	UD6nUR                  n[        U[        5      (       a  [	        U* S5      OUnU R                  USS2USS24   5      nSnUb)  U R                  " SUXR                  R                  S.UD6n[        UUUR                  UR                  UR                  UR                  S9$ )a  
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.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the left-to-right language modeling loss (next word prediction). Indices should be in
    `[-100, 0, ..., config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are
    ignored (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`

Example:

```python
>>> from transformers import AutoTokenizer, CamembertForCausalLM, AutoConfig
>>> import torch

>>> tokenizer = AutoTokenizer.from_pretrained("almanach/camembert-base")
>>> config = AutoConfig.from_pretrained("almanach/camembert-base")
>>> config.is_decoder = True
>>> model = CamembertForCausalLM.from_pretrained("almanach/camembert-base", config=config)

>>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
>>> outputs = model(**inputs)

>>> prediction_logits = outputs.logits
```NFT)	r?   r@   rA   rB   rC   rD   r   r   rI   )rM   rE   rT   )rL   rM   r   rN   rO   cross_attentionsr   )r   last_hidden_state
isinstanceru   slicerP   loss_functionr:   rT   r   r   rN   rO   r   )r9   r>   r?   r@   rA   rB   rC   rD   rE   r   r   r   rF   rU   rN   slice_indicesrM   rL   s                     r'   rZ   CamembertForCausalLM.forward  s    ` I@DA
))%'"7#9+A
 A
  118B>SV8W8W~ot4]kmA}a,?@A%%pVF{{OeOepiopD0#33!//))$55
 	
r&   r\   )NNNNNNNNNNr   )r    r!   r"   r#   r]   r6   r   r   r^   r_   r`   ra   boolru   rb   r   r   r   rZ   r%   rc   rd   s   @r'   r   r     st   "M .
G  .237260426:>;?*.BF!%-.O
##d*O
 ))D0O
 ((4/	O

 &&-O
 ((4/O
  %0047O
 !& 1 1D 8O
   4'O
 uU%6%6784?O
 $;O
 ell*O
 +,O
 
u||	@	@O
  O
r&   r   )r   r,   r{   r   rf   r   r)   r   )'__doc__r^   torch.nnr   r   r   modeling_outputsr   r   r	   r
   r   r   r   processing_utilsr   utilsr   r   utils.genericr   roberta.modeling_robertar   r   r   r   r   r   r   r   r   r)   r,   rf   r{   r   r   r   __all__r   r&   r'   <module>r      s      A A   ' 7 -	 	 	"5 "	\ 	C
- C
LL
)I L
^Y
!9 Y
x;
&C ;
|G
$? G
T]
- ]
@	r&   