






import torch

from transformers import CamembertForMaskedLM, CamembertTokenizer







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase=5      )			->     List[Any]:
     # Adapted from https://github.com/pytorch/fairseq/blob/master/fairseq/models/roberta/hub_interface.py
     assert masked_input.count("<mask>"      ) == 1
     UpperCamelCase__      :       Union[str, Any]	    =  torch.tensor(tokenizer.encode(snake_case_ ,   add_special_tokens=snake_case_      )      ).unsqueeze(0      )  # Batch size 1
     UpperCamelCase__      :       Tuple	    =  model(snake_case_      )[0]  # The last hidden-state is the first element of the output tuple
     UpperCamelCase__      :       Dict	    =  (input_ids.squeeze() == tokenizer.mask_token_id).nonzero().item()
     UpperCamelCase__      :       Tuple	    =  logits[0, masked_index, :]
     UpperCamelCase__      :       str	    =  logits.softmax(dim=0      )
     UpperCamelCase__    ,					UpperCamelCase__      :       List[Any]	    =  prob.topk(k=snake_case_ ,   dim=0      )
     UpperCamelCase__      :       List[Any]	    =  " ".join(
         [tokenizer.convert_ids_to_tokens(indices[i].item()      ) for i in range(len(snake_case_      )      )]      )
     UpperCamelCase__      :       int	    =  tokenizer.mask_token
     UpperCamelCase__      :       Any	    =  []
     for index, predicted_token_bpe in enumerate(topk_predicted_token_bpe.split(" "      )      ):
          UpperCamelCase__      :       Tuple	    =  predicted_token_bpe.replace("\u2581" ,   " "      )
          if " {0}".format(snake_case_      ) in masked_input:
               topk_filled_outputs.append(
                   (
                       masked_input.replace(" {0}".format(snake_case_      ) ,   snake_case_      ),
                       values[index].item(),
                       predicted_token,
                   )      )
          else:
               topk_filled_outputs.append(
                   (
                       masked_input.replace(snake_case_ ,   snake_case_      ),
                       values[index].item(),
                       predicted_token,
                   )      )
     return topk_filled_outputs


lowerCamelCase     :							Any    =CamembertTokenizer.from_pretrained('''camembert-base''')
lowerCamelCase     :							Optional[Any]    =CamembertForMaskedLM.from_pretrained('''camembert-base''')
model.eval()

lowerCamelCase     :							int    ='Le camembert est <mask> :)'




print(fill_mask(masked_input, model, tokenizer, topk=3))







from __future__ import annotations







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase      )			->     list[int]:
     UpperCamelCase__      :       Optional[Any]	    =  0
     UpperCamelCase__      :       Any	    =  len(__lowerCAmelCase      ) - 1

     while i < j:
          if nums[i] + nums[j] == target:
               return [i, j]
          elif nums[i] + nums[j] < target:
               UpperCamelCase__      :       Optional[int]	    =  i + 1
          else:
               UpperCamelCase__      :       Dict	    =  j - 1

     return []


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 print(F"""{two_pointer([2, 7, 11, 15], 9) = }""")