original_docstring:  Load weights of neural model from the binary data.
  
          :param weights_as_bytes: 2-element tuple of binary data (`bytes` or `byterray` objects) containing weights of
          neural encoder and neural decoder respectively.
          
docstring: Load weights of neural model from the binary data.
docstring_tokens: Load weights of neural model from the binary data .
code: def load_weights(self, weights_as_bytes):
          """ Load weights of neural model from the binary data.
  
          :param weights_as_bytes: 2-element tuple of binary data (`bytes` or `byterray` objects) containing weights of
          neural encoder and neural decoder respectively.
          """
          if not isinstance(weights_as_bytes, tuple):
              raise ValueError(f'`weights_as_bytes` must be a 2-element tuple, not `{type(weights_as_bytes)}`!')
          if len(weights_as_bytes) != 2:
              raise ValueError(f'`weights_as_bytes` must be a 2-element tuple, but it is a {len(weights_as_bytes)}-element tuple!')
          if (not isinstance(weights_as_bytes[0], bytearray)) and (not isinstance(weights_as_bytes[0], bytes)):
              raise ValueError(f'First element of `weights_as_bytes` must be an array of bytes, not `{type(weights_as_bytes[0])}`!')
          if (not isinstance(weights_as_bytes[1], bytearray)) and (not isinstance(weights_as_bytes[1], bytes)):
              raise ValueError(f'Second element of `weights_as_bytes` must be an array of bytes, not `{type(weights_as_bytes[1])}`!')
          tmp_weights_name = self.get_temp_name()
          try:
              K.clear_session()
              encoder_inputs = Input(shape=(None, len(self.input_token_index_)),
                                     name='EncoderInputs')
              encoder_mask = Masking(name='EncoderMask', mask_value=0.0)(encoder_inputs)
              encoder = LSTM(
                  self.latent_dim,
                  return_sequences=False, return_state=True,
                  kernel_initializer=GlorotUniform(seed=self.generate_random_seed()),
                  recurrent_initializer=Orthogonal(seed=self.generate_random_seed()),
                  name='EncoderLSTM'
              )
              encoder_outputs, state_h, state_c = encoder(encoder_mask)
              encoder_states = [state_h, state_c]
              decoder_inputs = Input(shape=(None, len(self.target_token_index_)),
                                     name='DecoderInputs')
              decoder_mask = Masking(name='DecoderMask', mask_value=0.0)(decoder_inputs)
              decoder_lstm = LSTM(
                  self.latent_dim, return_sequences=True, return_state=True,
                  kernel_initializer=GlorotUniform(seed=self.generate_random_seed()),
                  recurrent_initializer=Orthogonal(seed=self.generate_random_seed()),
                  name='DecoderLSTM'
              )
              decoder_outputs, _, _ = decoder_lstm(decoder_mask, initial_state=encoder_states)
              decoder_dense = Dense(
                  len(self.target_token_index_), activation='softmax',
                  kernel_initializer=GlorotUniform(seed=self.generate_random_seed()),
                  name='DecoderOutput'
              )
              self.encoder_model_ = Model(encoder_inputs, encoder_states)
              decoder_state_input_h = Input(shape=(self.latent_dim,))
              decoder_state_input_c = Input(shape=(self.latent_dim,))
              decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]
              decoder_outputs, state_h, state_c = decoder_lstm(
                  decoder_mask, initial_state=decoder_states_inputs)
              decoder_states = [state_h, state_c]
              decoder_outputs = decoder_dense(decoder_outputs)
              self.decoder_model_ = Model(
                  [decoder_inputs] + decoder_states_inputs,
                  [decoder_outputs] + decoder_states)
              with open(tmp_weights_name, 'wb') as fp:
                  fp.write(weights_as_bytes[0])
              self.encoder_model_.load_weights(tmp_weights_name)
              os.remove(tmp_weights_name)
              with open(tmp_weights_name, 'wb') as fp:
                  fp.write(weights_as_bytes[1])
              self.decoder_model_.load_weights(tmp_weights_name)
              os.remove(tmp_weights_name)
          finally:
              if os.path.isfile(tmp_weights_name):
                  os.remove(tmp_weights_name)
code_tokens: def load_weights ( self , weights_as_bytes ) : if not isinstance ( weights_as_bytes , tuple ) : raise ValueError ( f'`weights_as_bytes` must be a 2-element tuple, not `{type(weights_as_bytes)}`!' ) if len ( weights_as_bytes ) != 2 : raise ValueError ( f'`weights_as_bytes` must be a 2-element tuple, but it is a {len(weights_as_bytes)}-element tuple!' ) if ( not isinstance ( weights_as_bytes [ 0 ] , bytearray ) ) and ( not isinstance ( weights_as_bytes [ 0 ] , bytes ) ) : raise ValueError ( f'First element of `weights_as_bytes` must be an array of bytes, not `{type(weights_as_bytes[0])}`!' ) if ( not isinstance ( weights_as_bytes [ 1 ] , bytearray ) ) and ( not isinstance ( weights_as_bytes [ 1 ] , bytes ) ) : raise ValueError ( f'Second element of `weights_as_bytes` must be an array of bytes, not `{type(weights_as_bytes[1])}`!' ) tmp_weights_name = self . get_temp_name ( ) try : K . clear_session ( ) encoder_inputs = Input ( shape = ( None , len ( self . input_token_index_ ) ) , name = 'EncoderInputs' ) encoder_mask = Masking ( name = 'EncoderMask' , mask_value = 0.0 ) ( encoder_inputs ) encoder = LSTM ( self . latent_dim , return_sequences = False , return_state = True , kernel_initializer = GlorotUniform ( seed = self . generate_random_seed ( ) ) , recurrent_initializer = Orthogonal ( seed = self . generate_random_seed ( ) ) , name = 'EncoderLSTM' ) encoder_outputs , state_h , state_c = encoder ( encoder_mask ) encoder_states = [ state_h , state_c ] decoder_inputs = Input ( shape = ( None , len ( self . target_token_index_ ) ) , name = 'DecoderInputs' ) decoder_mask = Masking ( name = 'DecoderMask' , mask_value = 0.0 ) ( decoder_inputs ) decoder_lstm = LSTM ( self . latent_dim , return_sequences = True , return_state = True , kernel_initializer = GlorotUniform ( seed = self . generate_random_seed ( ) ) , recurrent_initializer = Orthogonal ( seed = self . generate_random_seed ( ) ) , name = 'DecoderLSTM' ) decoder_outputs , _ , _ = decoder_lstm ( decoder_mask , initial_state = encoder_states ) decoder_dense = Dense ( len ( self . target_token_index_ ) , activation = 'softmax' , kernel_initializer = GlorotUniform ( seed = self . generate_random_seed ( ) ) , name = 'DecoderOutput' ) self . encoder_model_ = Model ( encoder_inputs , encoder_states ) decoder_state_input_h = Input ( shape = ( self . latent_dim , ) ) decoder_state_input_c = Input ( shape = ( self . latent_dim , ) ) decoder_states_inputs = [ decoder_state_input_h , decoder_state_input_c ] decoder_outputs , state_h , state_c = decoder_lstm ( decoder_mask , initial_state = decoder_states_inputs ) decoder_states = [ state_h , state_c ] decoder_outputs = decoder_dense ( decoder_outputs ) self . decoder_model_ = Model ( [ decoder_inputs ] + decoder_states_inputs , [ decoder_outputs ] + decoder_states ) with open ( tmp_weights_name , 'wb' ) as fp : fp . write ( weights_as_bytes [ 0 ] ) self . encoder_model_ . load_weights ( tmp_weights_name ) os . remove ( tmp_weights_name ) with open ( tmp_weights_name , 'wb' ) as fp : fp . write ( weights_as_bytes [ 1 ] ) self . decoder_model_ . load_weights ( tmp_weights_name ) os . remove ( tmp_weights_name ) finally : if os . path . isfile ( tmp_weights_name ) : os . remove ( tmp_weights_name )
short_docstring: Load weights of neural model from the binary data.
short_docstring_tokens: Load weights of neural model from the binary data .
comment: """ Load weights of neural model from the binary data.
  
          :param weights_as_bytes: 2-element tuple of binary data (`bytes` or `byterray` objects) containing weights of
          neural encoder and neural decoder respectively.
          """