

'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import LEDConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
      import tensorflow as tf

      from transformers import TFLEDForConditionalGeneration, TFLEDModel


@require_tf
class        A__   :
    lowercase						       =		LEDConfig
    lowercase						       =		{}
    lowercase						       =		"gelu"



    def __init__(       self		,					UpperCamelCase__		,					UpperCamelCase__=13		,					UpperCamelCase__=7		,					UpperCamelCase__=True		,					UpperCamelCase__=False		,					UpperCamelCase__=99		,					UpperCamelCase__=32		,					UpperCamelCase__=2		,					UpperCamelCase__=4		,					UpperCamelCase__=37		,					UpperCamelCase__=0.1		,					UpperCamelCase__=0.1		,					UpperCamelCase__=20		,					UpperCamelCase__=2		,					UpperCamelCase__=1		,					UpperCamelCase__=0		,					UpperCamelCase__=4		,					)    ->   List[Any]:





           '''simple docstring'''
           A_						       =   parent
           A_						       =   batch_size
           A_						       =   seq_length
           A_						       =   is_training
           A_						       =   use_labels
           A_						       =   vocab_size
           A_						       =   hidden_size
           A_						       =   num_hidden_layers
           A_						       =   num_attention_heads
           A_						       =   intermediate_size

           A_						       =   hidden_dropout_prob
           A_						       =   attention_probs_dropout_prob
           A_						       =   max_position_embeddings
           A_						       =   eos_token_id
           A_						       =   pad_token_id
           A_						       =   bos_token_id
           A_						       =   attention_window

           # `ModelTesterMixin.test_attention_outputs` is expecting attention tensors to be of size
           # [num_attention_heads, encoder_seq_length, encoder_key_length], but TFLongformerSelfAttention
           # returns attention of shape [num_attention_heads, encoder_seq_length, self.attention_window + 1]
           # because its local attention only attends to `self.attention_window` and one before and one after
           A_						       =   self.attention_window + 2

           # because of padding `encoder_seq_length`, is different from `seq_length`. Relevant for
           # the `test_attention_outputs` and `test_hidden_states_output` tests
           A_						       =   (
               self.seq_length + (self.attention_window - self.seq_length % self.attention_window) % self.attention_window
           )



    def        snake_case_      (       self							)    ->   List[str]:





           '''simple docstring'''
           A_						       =   ids_tensor([self.batch_size, self.seq_length - 1]		,					self.vocab_size							)
           A_						       =   tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size							)		,					1							)
           A_						       =   tf.concat([input_ids, eos_tensor]		,					axis=1							)

           A_						       =   ids_tensor([self.batch_size, self.seq_length]		,					self.vocab_size							)

           A_						       =   self.config_cls(
               vocab_size=self.vocab_size		,					d_model=self.hidden_size		,					encoder_layers=self.num_hidden_layers		,					decoder_layers=self.num_hidden_layers		,					encoder_attention_heads=self.num_attention_heads		,					decoder_attention_heads=self.num_attention_heads		,					encoder_ffn_dim=self.intermediate_size		,					decoder_ffn_dim=self.intermediate_size		,					dropout=self.hidden_dropout_prob		,					attention_dropout=self.attention_probs_dropout_prob		,					max_position_embeddings=self.max_position_embeddings		,					eos_token_ids=[2]		,					bos_token_id=self.bos_token_id		,					pad_token_id=self.pad_token_id		,					decoder_start_token_id=self.pad_token_id		,					attention_window=self.attention_window		,					**self.config_updates		,					)
           A_						       =   prepare_led_inputs_dict(UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__							)
           A_						       =   tf.concat(
               [tf.zeros_like(UpperCamelCase__							)[:, :-1], tf.ones_like(UpperCamelCase__							)[:, -1:]]		,					axis=-1		,					)
           A_						       =   global_attention_mask
           return config, inputs_dict







    def        snake_case_      (       self		,					UpperCamelCase__		,					UpperCamelCase__							)    ->   List[Any]:





           '''simple docstring'''
           A_						       =   TFLEDModel(config=UpperCamelCase__							).get_decoder()
           A_						       =   inputs_dict["""input_ids"""]

           A_						       =   input_ids[:1, :]
           A_						       =   inputs_dict["""attention_mask"""][:1, :]
           A_						       =   1

           # first forward pass
           A_						       =   model(UpperCamelCase__		,					attention_mask=UpperCamelCase__		,					use_cache=UpperCamelCase__							)

           A_       ,      A_						       =   outputs.to_tuple()

           # create hypothetical next token and extent to next_input_ids
           A_						       =   ids_tensor((self.batch_size, 3)		,					config.vocab_size							)
           A_						       =   tf.cast(ids_tensor((self.batch_size, 3)		,					2							)		,					tf.inta							)

           # append to next input_ids and
           A_						       =   tf.concat([input_ids, next_tokens]		,					axis=-1							)
           A_						       =   tf.concat([attention_mask, next_attn_mask]		,					axis=-1							)

           A_						       =   model(UpperCamelCase__		,					attention_mask=UpperCamelCase__							)[0]
           A_						       =   model(UpperCamelCase__		,					attention_mask=UpperCamelCase__		,					past_key_values=UpperCamelCase__							)[0]

           self.parent.assertEqual(next_tokens.shape[1]		,					output_from_past.shape[1]							)

           # select random slice
           A_						       =   int(ids_tensor((1,)		,					output_from_past.shape[-1]							)							)
           A_						       =   output_from_no_past[:, -3:, random_slice_idx]
           A_						       =   output_from_past[:, :, random_slice_idx]

           # test that outputs are equal for slice
           tf.debugging.assert_near(UpperCamelCase__		,					UpperCamelCase__		,					rtol=1e-3							)

def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__=None,							UpperCAmelCase__=None,							UpperCAmelCase__=None,							UpperCAmelCase__=None,							)      ->      Union[str, Any]:
       if attention_mask is None:
              A_						       =   tf.cast(tf.math.not_equal(UpperCAmelCase__,							config.pad_token_id					),							tf.inta					)
       if decoder_attention_mask is None:
              A_						       =   tf.concat(
                  [
                      tf.ones(decoder_input_ids[:, :1].shape,							dtype=tf.inta					),
                      tf.cast(tf.math.not_equal(decoder_input_ids[:, 1:],							config.pad_token_id					),							tf.inta					),
                  ],							axis=-1,							)
       if head_mask is None:
              A_						       =   tf.ones((config.encoder_layers, config.encoder_attention_heads)					)
       if decoder_head_mask is None:
              A_						       =   tf.ones((config.decoder_layers, config.decoder_attention_heads)					)
       return {
           "input_ids": input_ids,
           "attention_mask": attention_mask,
           "decoder_input_ids": decoder_input_ids,
           "decoder_attention_mask": decoder_attention_mask,
           "head_mask": head_mask,
           "decoder_head_mask": decoder_head_mask,
       }


@require_tf
class        A__   (   _snake_case    ,    _snake_case    ,    unittest.TestCase      ):
    lowercase						       =		(TFLEDForConditionalGeneration, TFLEDModel) if is_tf_available() else ()
    lowercase						       =		(TFLEDForConditionalGeneration,) if is_tf_available() else ()
    lowercase						       =		(
        {
            "conversational": TFLEDForConditionalGeneration,
            "feature-extraction": TFLEDModel,
            "summarization": TFLEDForConditionalGeneration,
            "text2text-generation": TFLEDForConditionalGeneration,
            "translation": TFLEDForConditionalGeneration,
        }
        if is_tf_available()
        else {}
    )
    lowercase						       =		True
    lowercase						       =		False
    lowercase						       =		False
    lowercase						       =		False



    def        snake_case_      (       self							)    ->   Union[str, Any]:





           '''simple docstring'''
           A_						       =   TFLEDModelTester(self							)
           A_						       =   ConfigTester(self		,					config_class=UpperCamelCase__							)



    def        snake_case_      (       self							)    ->   int:





           '''simple docstring'''
           self.config_tester.run_common_tests()



    def        snake_case_      (       self							)    ->   int:





           '''simple docstring'''
           A_						       =   self.model_tester.prepare_config_and_inputs_for_common()
           self.model_tester.check_decoder_model_past_large_inputs(*UpperCamelCase__							)



    def        snake_case_      (       self							)    ->   Any:





           '''simple docstring'''
           A_       ,      A_						       =   self.model_tester.prepare_config_and_inputs_for_common()
           A_						       =   tf.zeros_like(inputs_dict["""attention_mask"""]							)
           A_						       =   2
           A_						       =   tf.where(
               tf.range(self.model_tester.seq_length							)[None, :] < num_global_attn_indices		,					1		,					inputs_dict["""global_attention_mask"""]		,					)

           A_						       =   True
           A_						       =   self.model_tester.seq_length
           A_						       =   self.model_tester.encoder_seq_length

           def check_decoder_attentions_output(UpperCamelCase__							):
                  A_						       =   outputs.decoder_attentions
                  self.assertEqual(len(UpperCamelCase__							)		,					self.model_tester.num_hidden_layers							)
                  self.assertListEqual(
                      list(decoder_attentions[0].shape[-3:]							)		,					[self.model_tester.num_attention_heads, seq_length, seq_length]		,					)

           def check_encoder_attentions_output(UpperCamelCase__							):
                  A_						       =   [t.numpy() for t in outputs.encoder_attentions]
                  A_						       =   [t.numpy() for t in outputs.encoder_global_attentions]
                  self.assertEqual(len(UpperCamelCase__							)		,					self.model_tester.num_hidden_layers							)
                  self.assertEqual(len(UpperCamelCase__							)		,					self.model_tester.num_hidden_layers							)
                  self.assertListEqual(
                      list(attentions[0].shape[-3:]							)		,					[self.model_tester.num_attention_heads, seq_length, seq_length]		,					)
                  self.assertListEqual(
                      list(global_attentions[0].shape[-3:]							)		,					[self.model_tester.num_attention_heads, encoder_seq_length, num_global_attn_indices]		,					)

           for model_class in self.all_model_classes:
                  A_						       =   True
                  A_						       =   False
                  A_						       =   False
                  A_						       =   model_class(UpperCamelCase__							)
                  A_						       =   model(self._prepare_for_class(UpperCamelCase__		,					UpperCamelCase__							)							)
                  A_						       =   len(UpperCamelCase__							)
                  self.assertEqual(config.output_hidden_states		,					UpperCamelCase__							)
                  check_encoder_attentions_output(UpperCamelCase__							)

                  if self.is_encoder_decoder:
                         A_						       =   model_class(UpperCamelCase__							)
                         A_						       =   model(self._prepare_for_class(UpperCamelCase__		,					UpperCamelCase__							)							)
                         self.assertEqual(config.output_hidden_states		,					UpperCamelCase__							)
                         check_decoder_attentions_output(UpperCamelCase__							)

                  # Check that output attentions can also be changed via the config
                  del inputs_dict["output_attentions"]
                  A_						       =   True
                  A_						       =   model_class(UpperCamelCase__							)
                  A_						       =   model(self._prepare_for_class(UpperCamelCase__		,					UpperCamelCase__							)							)
                  self.assertEqual(config.output_hidden_states		,					UpperCamelCase__							)
                  check_encoder_attentions_output(UpperCamelCase__							)

                  # Check attention is always last and order is fine
                  A_						       =   True
                  A_						       =   True
                  A_						       =   model_class(UpperCamelCase__							)
                  A_						       =   model(self._prepare_for_class(UpperCamelCase__		,					UpperCamelCase__							)							)

                  self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)		,					len(UpperCamelCase__							)							)
                  self.assertEqual(model.config.output_hidden_states		,					UpperCamelCase__							)
                  check_encoder_attentions_output(UpperCamelCase__							)



    @unittest.skip("""LED keeps using potentially symbolic tensors in conditionals and breaks tracing."""							)
    def        snake_case_      (       self							)    ->   Dict:





           '''simple docstring'''
           pass







    def        snake_case_      (       self							)    ->   Optional[Any]:





           '''simple docstring'''
           # TODO: Head-masking not yet implement
           pass

def    UpperCAmelCase__     (   UpperCAmelCase__					)      ->      int:
       return tf.constant(UpperCAmelCase__,							dtype=tf.intaa					)


__lowerCamelCase									=     1e-4







@slow
@require_tf
class        A__   (   unittest.TestCase      ):



    def        snake_case_      (       self							)    ->   Tuple:





           '''simple docstring'''
           A_						       =   TFLEDForConditionalGeneration.from_pretrained("""allenai/led-base-16384"""							).led

           # change to intended input here
           A_						       =   _long_tensor([512 * [0, 31414, 232, 328, 740, 1140, 12695, 69]]							)
           A_						       =   _long_tensor([128 * [0, 31414, 232, 328, 740, 1140, 12695, 69]]							)
           A_						       =   prepare_led_inputs_dict(model.config		,					UpperCamelCase__		,					UpperCamelCase__							)
           A_						       =   model(**UpperCamelCase__							)[0]
           A_						       =   (1, 1024, 768)
           self.assertEqual(output.shape		,					UpperCamelCase__							)
           # change to expected output here
           A_						       =   tf.convert_to_tensor(
               [[2.3050, 2.8279, 0.6531], [-1.8457, -0.1455, -3.5661], [-1.0186, 0.4586, -2.2043]]		,					)
           tf.debugging.assert_near(output[:, :3, :3]		,					UpperCamelCase__		,					atol=1e-3							)







    def        snake_case_      (       self							)    ->   Optional[Any]:





           '''simple docstring'''
           A_						       =   TFLEDForConditionalGeneration.from_pretrained("""allenai/led-base-16384"""							)

           # change to intended input here
           A_						       =   _long_tensor([512 * [0, 31414, 232, 328, 740, 1140, 12695, 69]]							)
           A_						       =   _long_tensor([128 * [0, 31414, 232, 328, 740, 1140, 12695, 69]]							)
           A_						       =   prepare_led_inputs_dict(model.config		,					UpperCamelCase__		,					UpperCamelCase__							)
           A_						       =   model(**UpperCamelCase__							)[0]
           A_						       =   (1, 1024, model.config.vocab_size)
           self.assertEqual(output.shape		,					UpperCamelCase__							)
           # change to expected output here
           A_						       =   tf.convert_to_tensor(
               [[33.6507, 6.4572, 16.8089], [5.8739, -2.4238, 11.2902], [-3.2139, -4.3149, 4.2783]]		,					)
           tf.debugging.assert_near(output[:, :3, :3]		,					UpperCamelCase__		,					atol=1e-3		,					rtol=1e-3							)



'''simple docstring'''







import csv

import tweepy

# Twitter API credentials
__lowerCamelCase									=     ''''''
__lowerCamelCase									=     ''''''
__lowerCamelCase									=     ''''''
__lowerCamelCase									=     ''''''
def    UpperCAmelCase__     (   UpperCAmelCase__					)      ->      None:
       # authorize twitter, initialize tweepy
       A_						       =   tweepy.OAuthHandler(UpperCAmelCase__,							UpperCAmelCase__					)
       auth.set_access_token(UpperCAmelCase__,							UpperCAmelCase__					)
       A_						       =   tweepy.API(UpperCAmelCase__					)

       # initialize a list to hold all the tweepy Tweets
       A_						       =   []

       # make initial request for most recent tweets (200 is the maximum allowed count)
       A_						       =   api.user_timeline(screen_name=UpperCAmelCase__,							count=2_00					)

       # save most recent tweets
       alltweets.extend(UpperCAmelCase__					)

       # save the id of the oldest tweet less one
       A_						       =   alltweets[-1].id - 1

       # keep grabbing tweets until there are no tweets left to grab
       while len(UpperCAmelCase__					) > 0:
              print(F'''getting tweets before {oldest}'''					)

              # all subsequent requests use the max_id param to prevent duplicates
              A_						       =   api.user_timeline(
                  screen_name=UpperCAmelCase__,							count=2_00,							max_id=UpperCAmelCase__					)

              # save most recent tweets
              alltweets.extend(UpperCAmelCase__					)

              # update the id of the oldest tweet less one
              A_						       =   alltweets[-1].id - 1

              print(F'''...{len(UpperCAmelCase__					)} tweets downloaded so far'''					)

       # transform the tweepy tweets into a 2D array that will populate the csv
       A_						       =   [[tweet.id_str, tweet.created_at, tweet.text] for tweet in alltweets]

       # write the csv
       with open(F'''new_{screen_name}_tweets.csv''',							"""w"""					) as f:
              A_						       =   csv.writer(UpperCAmelCase__					)
              writer.writerow(["""id""", """created_at""", """text"""]					)
              writer.writerows(UpperCAmelCase__					)


if __name__ == "__main__":
      # pass in the username of the account you want to download
      get_all_tweets('''FirePing32''')
