


'''simple docstring'''



import pandas as pd
from matplotlib import pyplot as plt
from sklearn.linear_model import LinearRegression

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split

# Fitting Polynomial Regression to the dataset
from sklearn.preprocessing import PolynomialFeatures

# Importing the dataset
__UpperCAmelCase    :Union[str, Any]				       =     pd.read_csv(
    "https://s3.us-west-2.amazonaws.com/public.gamelab.fun/dataset/"
    "position_salaries.csv"
)
__UpperCAmelCase    :Tuple				       =     dataset.iloc[:, 1:2].values
__UpperCAmelCase    :Optional[int]				       =     dataset.iloc[:, 2].values


__UpperCAmelCase    :Union[str, Any]				       =     train_test_split(X, y, test_size=0.2, random_state=0)


__UpperCAmelCase    :List[str]				       =     PolynomialFeatures(degree=4)
__UpperCAmelCase    :Dict				       =     poly_reg.fit_transform(X)
__UpperCAmelCase    :List[Any]				       =     LinearRegression()
pol_reg.fit(X_poly, y)




def 			_a			(		):





     '''simple docstring'''






     plt.scatter(_lowercase    ,      _lowercase    ,      color='''red'''						)
     plt.plot(_lowercase    ,      pol_reg.predict(poly_reg.fit_transform(_lowercase						)						)    ,      color='''blue'''						)
     plt.title('''Truth or Bluff (Linear Regression)'''						)
     plt.xlabel('''Position level'''						)
     plt.ylabel('''Salary'''						)
     plt.show()


if __name__ == "__main__":
      viz_polymonial()

      # Predicting a new result with Polymonial Regression
      pol_reg.predict(poly_reg.fit_transform([[5.5]]))
      # output should be 132148.43750003



'''simple docstring'''



import unittest

from transformers import AutoTokenizer, NystromformerConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          NystromformerForMaskedLM,
          NystromformerForMultipleChoice,
          NystromformerForQuestionAnswering,
          NystromformerForSequenceClassification,
          NystromformerForTokenClassification,
          NystromformerModel,
      )
      from transformers.models.nystromformer.modeling_nystromformer import NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST



class 			a       :


     """simple docstring"""






     def __init__(       self  :	Union[str, Any]							,				snake_case  :	str							,				snake_case  :	Union[str, Any]=13							,				snake_case  :	int=7							,				snake_case  :	Union[str, Any]=True							,				snake_case  :	Tuple=True							,				snake_case  :	Tuple=True							,				snake_case  :	Union[str, Any]=True							,				snake_case  :	Tuple=99							,				snake_case  :	str=32							,				snake_case  :	Tuple=5							,				snake_case  :	int=4							,				snake_case  :	Union[str, Any]=37							,				snake_case  :	Union[str, Any]="gelu"							,				snake_case  :	List[Any]=0.1							,				snake_case  :	List[Any]=0.1							,				snake_case  :	Any=512							,				snake_case  :	Dict=16							,				snake_case  :	Dict=2							,				snake_case  :	int=0.02							,				snake_case  :	Dict=3							,				snake_case  :	Tuple=4							,				snake_case  :	Any=None							,				)		->							Tuple:
          __UpperCAmelCase			:				Optional[Any]													=    parent
          __UpperCAmelCase			:				int													=    batch_size
          __UpperCAmelCase			:				List[Any]													=    seq_length
          __UpperCAmelCase			:				Dict													=    is_training
          __UpperCAmelCase			:				Union[str, Any]													=    use_input_mask
          __UpperCAmelCase			:				Union[str, Any]													=    use_token_type_ids
          __UpperCAmelCase			:				Optional[Any]													=    use_labels
          __UpperCAmelCase			:				str													=    vocab_size
          __UpperCAmelCase			:				List[str]													=    hidden_size
          __UpperCAmelCase			:				Any													=    num_hidden_layers
          __UpperCAmelCase			:				Optional[int]													=    num_attention_heads
          __UpperCAmelCase			:				str													=    intermediate_size
          __UpperCAmelCase			:				Tuple													=    hidden_act
          __UpperCAmelCase			:				Tuple													=    hidden_dropout_prob
          __UpperCAmelCase			:				Optional[Any]													=    attention_probs_dropout_prob
          __UpperCAmelCase			:				List[str]													=    max_position_embeddings
          __UpperCAmelCase			:				Optional[Any]													=    type_vocab_size
          __UpperCAmelCase			:				Dict													=    type_sequence_label_size
          __UpperCAmelCase			:				Tuple													=    initializer_range
          __UpperCAmelCase			:				Union[str, Any]													=    num_labels
          __UpperCAmelCase			:				List[str]													=    num_choices
          __UpperCAmelCase			:				List[str]													=    scope

     def 				lowerCamelCase__				(       self  :	Optional[int]    )		->							Any:
          __UpperCAmelCase			:				int													=    ids_tensor([self.batch_size, self.seq_length]							,				self.vocab_size    )

          __UpperCAmelCase			:				Optional[int]													=    None
          if self.use_input_mask:
               __UpperCAmelCase			:				Tuple													=    random_attention_mask([self.batch_size, self.seq_length]    )

          __UpperCAmelCase			:				Optional[int]													=    None
          if self.use_token_type_ids:
               __UpperCAmelCase			:				int													=    ids_tensor([self.batch_size, self.seq_length]							,				self.type_vocab_size    )

          __UpperCAmelCase			:				Union[str, Any]													=    None
          __UpperCAmelCase			:				int													=    None
          __UpperCAmelCase			:				Union[str, Any]													=    None
          if self.use_labels:
               __UpperCAmelCase			:				List[Any]													=    ids_tensor([self.batch_size]							,				self.type_sequence_label_size    )
               __UpperCAmelCase			:				int													=    ids_tensor([self.batch_size, self.seq_length]							,				self.num_labels    )
               __UpperCAmelCase			:				int													=    ids_tensor([self.batch_size]							,				self.num_choices    )

          __UpperCAmelCase			:				int													=    self.get_config()

          return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

     def 				lowerCamelCase__				(       self  :	Union[str, Any]    )		->							int:
          return NystromformerConfig(
              vocab_size=self.vocab_size							,				hidden_size=self.hidden_size							,				num_hidden_layers=self.num_hidden_layers							,				num_attention_heads=self.num_attention_heads							,				intermediate_size=self.intermediate_size							,				hidden_act=self.hidden_act							,				hidden_dropout_prob=self.hidden_dropout_prob							,				attention_probs_dropout_prob=self.attention_probs_dropout_prob							,				max_position_embeddings=self.max_position_embeddings							,				type_vocab_size=self.type_vocab_size							,				is_decoder=snake_case							,				initializer_range=self.initializer_range							,				)

     def 				lowerCamelCase__				(       self  :	int							,				snake_case  :	Optional[int]							,				snake_case  :	str							,				snake_case  :	Optional[Any]							,				snake_case  :	List[str]							,				snake_case  :	str							,				snake_case  :	Union[str, Any]							,				snake_case  :	Tuple    )		->							Dict:
          __UpperCAmelCase			:				Any													=    NystromformerModel(config=snake_case    )
          model.to(snake_case    )
          model.eval()
          __UpperCAmelCase			:				str													=    model(snake_case							,				attention_mask=snake_case							,				token_type_ids=snake_case    )
          __UpperCAmelCase			:				List[str]													=    model(snake_case							,				token_type_ids=snake_case    )
          __UpperCAmelCase			:				Dict													=    model(snake_case    )
          self.parent.assertEqual(result.last_hidden_state.shape							,				(self.batch_size, self.seq_length, self.hidden_size)    )

     def 				lowerCamelCase__				(       self  :	Dict							,				snake_case  :	int							,				snake_case  :	Optional[int]							,				snake_case  :	int							,				snake_case  :	int							,				snake_case  :	List[str]							,				snake_case  :	Any							,				snake_case  :	Tuple    )		->							List[Any]:
          __UpperCAmelCase			:				List[Any]													=    NystromformerForMaskedLM(config=snake_case    )
          model.to(snake_case    )
          model.eval()
          __UpperCAmelCase			:				List[str]													=    model(snake_case							,				attention_mask=snake_case							,				token_type_ids=snake_case							,				labels=snake_case    )
          self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.seq_length, self.vocab_size)    )

     def 				lowerCamelCase__				(       self  :	str							,				snake_case  :	Optional[Any]							,				snake_case  :	Union[str, Any]							,				snake_case  :	List[str]							,				snake_case  :	Optional[Any]							,				snake_case  :	Union[str, Any]							,				snake_case  :	List[Any]							,				snake_case  :	Tuple    )		->							Union[str, Any]:
          __UpperCAmelCase			:				List[str]													=    NystromformerForQuestionAnswering(config=snake_case    )
          model.to(snake_case    )
          model.eval()
          __UpperCAmelCase			:				List[str]													=    model(
              snake_case							,				attention_mask=snake_case							,				token_type_ids=snake_case							,				start_positions=snake_case							,				end_positions=snake_case							,				)
          self.parent.assertEqual(result.start_logits.shape							,				(self.batch_size, self.seq_length)    )
          self.parent.assertEqual(result.end_logits.shape							,				(self.batch_size, self.seq_length)    )

     def 				lowerCamelCase__				(       self  :	Dict							,				snake_case  :	Any							,				snake_case  :	int							,				snake_case  :	Dict							,				snake_case  :	Any							,				snake_case  :	Optional[int]							,				snake_case  :	Tuple							,				snake_case  :	Any    )		->							List[str]:
          __UpperCAmelCase			:				int													=    self.num_labels
          __UpperCAmelCase			:				str													=    NystromformerForSequenceClassification(snake_case    )
          model.to(snake_case    )
          model.eval()
          __UpperCAmelCase			:				List[str]													=    model(snake_case							,				attention_mask=snake_case							,				token_type_ids=snake_case							,				labels=snake_case    )
          self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.num_labels)    )

     def 				lowerCamelCase__				(       self  :	Tuple							,				snake_case  :	List[Any]							,				snake_case  :	Optional[int]							,				snake_case  :	int							,				snake_case  :	List[str]							,				snake_case  :	Union[str, Any]							,				snake_case  :	List[str]							,				snake_case  :	List[str]    )		->							Optional[Any]:
          __UpperCAmelCase			:				str													=    self.num_labels
          __UpperCAmelCase			:				int													=    NystromformerForTokenClassification(config=snake_case    )
          model.to(snake_case    )
          model.eval()
          __UpperCAmelCase			:				str													=    model(snake_case							,				attention_mask=snake_case							,				token_type_ids=snake_case							,				labels=snake_case    )
          self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.seq_length, self.num_labels)    )

     def 				lowerCamelCase__				(       self  :	int							,				snake_case  :	Tuple							,				snake_case  :	Optional[int]							,				snake_case  :	Union[str, Any]							,				snake_case  :	Dict							,				snake_case  :	List[Any]							,				snake_case  :	Optional[int]							,				snake_case  :	Union[str, Any]    )		->							Any:
          __UpperCAmelCase			:				List[str]													=    self.num_choices
          __UpperCAmelCase			:				List[str]													=    NystromformerForMultipleChoice(config=snake_case    )
          model.to(snake_case    )
          model.eval()
          __UpperCAmelCase			:				Optional[int]													=    input_ids.unsqueeze(1    ).expand(-1							,				self.num_choices							,				-1    ).contiguous()
          __UpperCAmelCase			:				Dict													=    token_type_ids.unsqueeze(1    ).expand(-1							,				self.num_choices							,				-1    ).contiguous()
          __UpperCAmelCase			:				Optional[Any]													=    input_mask.unsqueeze(1    ).expand(-1							,				self.num_choices							,				-1    ).contiguous()
          __UpperCAmelCase			:				Union[str, Any]													=    model(
              snake_case							,				attention_mask=snake_case							,				token_type_ids=snake_case							,				labels=snake_case							,				)
          self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.num_choices)    )






     def 				lowerCamelCase__				(       self  :	List[Any]    )		->							Optional[int]:
          __UpperCAmelCase			:				Union[str, Any]													=    self.prepare_config_and_inputs()
          (
              (
              __UpperCAmelCase
          )							,     (
              __UpperCAmelCase
          )							,     (
              __UpperCAmelCase
          )							,     (
              __UpperCAmelCase
          )							,     (
              __UpperCAmelCase
          )							,     (
              __UpperCAmelCase
          )							,     (
              __UpperCAmelCase
          )							,     
          )			:				int													=    config_and_inputs
          __UpperCAmelCase			:				Tuple													=    {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
          return config, inputs_dict



@require_torch
class 			a       (	_a			,						_a			,						unittest.TestCase ):


     """simple docstring"""






     SCREAMING_SNAKE_CASE :				List[str]							     =     (
         (
             NystromformerModel,
             NystromformerForMaskedLM,
             NystromformerForMultipleChoice,
             NystromformerForQuestionAnswering,
             NystromformerForSequenceClassification,
             NystromformerForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     SCREAMING_SNAKE_CASE :				Union[str, Any]							     =     (
         {
             "feature-extraction": NystromformerModel,
             "fill-mask": NystromformerForMaskedLM,
             "question-answering": NystromformerForQuestionAnswering,
             "text-classification": NystromformerForSequenceClassification,
             "token-classification": NystromformerForTokenClassification,
             "zero-shot": NystromformerForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     SCREAMING_SNAKE_CASE :				Tuple							     =     False
     SCREAMING_SNAKE_CASE :				Union[str, Any]							     =     False

     def 				lowerCamelCase__				(       self  :	Dict    )		->							List[str]:
          __UpperCAmelCase			:				str													=    NystromformerModelTester(self    )
          __UpperCAmelCase			:				List[str]													=    ConfigTester(self							,				config_class=snake_case							,				hidden_size=37    )

     def 				lowerCamelCase__				(       self  :	int    )		->							Any:
          self.config_tester.run_common_tests()

     def 				lowerCamelCase__				(       self  :	Union[str, Any]    )		->							Optional[int]:
          __UpperCAmelCase			:				List[str]													=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case    )

     def 				lowerCamelCase__				(       self  :	Dict    )		->							Tuple:
          __UpperCAmelCase			:				Dict													=    self.model_tester.prepare_config_and_inputs()
          for type in ["absolute", "relative_key", "relative_key_query"]:
               __UpperCAmelCase			:				List[str]													=    type
               self.model_tester.create_and_check_model(*snake_case    )

     def 				lowerCamelCase__				(       self  :	Any    )		->							List[Any]:
          __UpperCAmelCase			:				List[Any]													=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*snake_case    )

     def 				lowerCamelCase__				(       self  :	Optional[Any]    )		->							Optional[Any]:
          __UpperCAmelCase			:				Optional[Any]													=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*snake_case    )

     def 				lowerCamelCase__				(       self  :	str    )		->							Optional[Any]:
          __UpperCAmelCase			:				int													=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*snake_case    )

     def 				lowerCamelCase__				(       self  :	str    )		->							Union[str, Any]:
          __UpperCAmelCase			:				Any													=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*snake_case    )

     def 				lowerCamelCase__				(       self  :	str    )		->							int:
          __UpperCAmelCase			:				Dict													=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*snake_case    )






     @slow
     def 				lowerCamelCase__				(       self  :	Any    )		->							Union[str, Any]:
          for model_name in NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __UpperCAmelCase			:				List[Any]													=    NystromformerModel.from_pretrained(snake_case    )
               self.assertIsNotNone(snake_case    )



@require_torch
class 			a       (	unittest.TestCase ):


     """simple docstring"""






     @slow
     def 				lowerCamelCase__				(       self  :	List[str]    )		->							List[str]:
          __UpperCAmelCase			:				Union[str, Any]													=    NystromformerModel.from_pretrained('''uw-madison/nystromformer-512'''    )
          __UpperCAmelCase			:				Any													=    torch.tensor([[0, 1, 2, 3, 4, 5]]    )

          with torch.no_grad():
               __UpperCAmelCase			:				Union[str, Any]													=    model(snake_case    )[0]

          __UpperCAmelCase			:				Tuple													=    torch.Size((1, 6, 768)    )
          self.assertEqual(output.shape							,				snake_case    )

          __UpperCAmelCase			:				Tuple													=    torch.tensor(
              [[[-0.4_532, -0.0_936, 0.5_137], [-0.2_676, 0.0_628, 0.6_186], [-0.3_629, -0.1_726, 0.4_716]]]    )

          self.assertTrue(torch.allclose(output[:, :3, :3]							,				snake_case							,				atol=1E-4    )    )






     @slow
     def 				lowerCamelCase__				(       self  :	Optional[int]    )		->							str:
          __UpperCAmelCase			:				str													=    '''the [MASK] of Belgium is Brussels'''

          __UpperCAmelCase			:				Dict													=    AutoTokenizer.from_pretrained('''uw-madison/nystromformer-512'''    )
          __UpperCAmelCase			:				Tuple													=    NystromformerForMaskedLM.from_pretrained('''uw-madison/nystromformer-512'''    )

          __UpperCAmelCase			:				Optional[Any]													=    tokenizer(snake_case							,				return_tensors='''pt'''    )

          with torch.no_grad():
               __UpperCAmelCase			:				Union[str, Any]													=    model(encoding.input_ids    ).logits

          __UpperCAmelCase			:				str													=    token_logits[:, 2, :].argmax(-1    )[0]

          self.assertEqual(tokenizer.decode(snake_case    )							,				'''capital'''    )