original_docstring:  Predict resulting sequences of tokens by source sequences with a trained seq2seq model.
  
          Each sequence is unicode text composed from the tokens. Tokens are separated by spaces.
  
          :param X: source sequences.
  
          :return: resulting sequences, predicted for source sequences.
  
          
docstring: Predict resulting sequences of tokens by source sequences with a trained seq2seq model.
  Each sequence is unicode text composed from the tokens. Tokens are separated by spaces.
docstring_tokens: Predict resulting sequences of tokens by source sequences with a trained seq2seq model . Each sequence is unicode text composed from the tokens . Tokens are separated by spaces .
code: def predict(self, X):
          """ Predict resulting sequences of tokens by source sequences with a trained seq2seq model.
  
          Each sequence is unicode text composed from the tokens. Tokens are separated by spaces.
  
          :param X: source sequences.
  
          :return: resulting sequences, predicted for source sequences.
  
          """
          self.check_X(X, 'X')
          check_is_fitted(self, ['input_token_index_', 'target_token_index_', 'reverse_target_char_index_',
                                 'max_encoder_seq_length_', 'max_decoder_seq_length_',
                                 'encoder_model_', 'decoder_model_'])
          texts = list()
          n_samples = X.shape[0] if isinstance(X, np.ndarray) else len(X)
          n_batches = int(np.ceil(n_samples / float(self.batch_size)))
          bounds_of_batches = [
              (
                  idx * self.batch_size,
                  min(n_samples, (idx + 1) * self.batch_size)
              ) for idx in range(n_batches)
          ]
          for batch_start, batch_end in (tqdm(bounds_of_batches) if self.verbose else bounds_of_batches):
              input_seq = Seq2SeqLSTM.generate_data_for_prediction(
                  input_texts=X, batch_start=batch_start, batch_end=batch_end,
                  max_encoder_seq_length=self.max_encoder_seq_length_,
                  input_token_index=self.input_token_index_,
                  lowercase=self.lowercase
              )
              batch_size = batch_end - batch_start
              states_value = self.encoder_model_.predict(input_seq)
              target_seq = np.zeros(
                  (batch_size, 1, len(self.target_token_index_)),
                  dtype=np.float32)
              stop_conditions = []
              decoded_sentences = []
              for text_idx in range(batch_size):
                  target_seq[text_idx, 0, self.target_token_index_['\t']] = 1.0
                  stop_conditions.append(False)
                  decoded_sentences.append([])
              while not all(stop_conditions):
                  output_tokens, h, c = self.decoder_model_.predict(
                      [target_seq] + states_value)
                  indices_of_sampled_tokens = np.argmax(output_tokens[:, -1, :],
                                                        axis=1)
                  for text_idx in range(batch_size):
                      if stop_conditions[text_idx]:
                          continue
                      sampled_char = self.reverse_target_char_index_[
                          indices_of_sampled_tokens[text_idx]]
                      decoded_sentences[text_idx].append(sampled_char)
                      if (sampled_char == '\n') or (len(decoded_sentences[text_idx]) > self.max_decoder_seq_length_):
                          stop_conditions[text_idx] = True
                      for token_idx in range(len(self.target_token_index_)):
                          target_seq[text_idx][0][token_idx] = 0.0
                      target_seq[
                          text_idx, 0, indices_of_sampled_tokens[text_idx]] = 1.0
                  states_value = [h, c]
              for text_idx in range(batch_size):
                  texts.append(' '.join(decoded_sentences[text_idx]))
              del input_seq
          del bounds_of_batches
          if isinstance(X, tuple):
              return tuple(texts)
          if isinstance(X, np.ndarray):
              return np.array(texts, dtype=object)
          return texts
code_tokens: def predict ( self , X ) : self . check_X ( X , 'X' ) check_is_fitted ( self , [ 'input_token_index_' , 'target_token_index_' , 'reverse_target_char_index_' , 'max_encoder_seq_length_' , 'max_decoder_seq_length_' , 'encoder_model_' , 'decoder_model_' ] ) texts = list ( ) n_samples = X . shape [ 0 ] if isinstance ( X , np . ndarray ) else len ( X ) n_batches = int ( np . ceil ( n_samples / float ( self . batch_size ) ) ) bounds_of_batches = [ ( idx * self . batch_size , min ( n_samples , ( idx + 1 ) * self . batch_size ) ) for idx in range ( n_batches ) ] for batch_start , batch_end in ( tqdm ( bounds_of_batches ) if self . verbose else bounds_of_batches ) : input_seq = Seq2SeqLSTM . generate_data_for_prediction ( input_texts = X , batch_start = batch_start , batch_end = batch_end , max_encoder_seq_length = self . max_encoder_seq_length_ , input_token_index = self . input_token_index_ , lowercase = self . lowercase ) batch_size = batch_end - batch_start states_value = self . encoder_model_ . predict ( input_seq ) target_seq = np . zeros ( ( batch_size , 1 , len ( self . target_token_index_ ) ) , dtype = np . float32 ) stop_conditions = [ ] decoded_sentences = [ ] for text_idx in range ( batch_size ) : target_seq [ text_idx , 0 , self . target_token_index_ [ '\t' ] ] = 1.0 stop_conditions . append ( False ) decoded_sentences . append ( [ ] ) while not all ( stop_conditions ) : output_tokens , h , c = self . decoder_model_ . predict ( [ target_seq ] + states_value ) indices_of_sampled_tokens = np . argmax ( output_tokens [ : , - 1 , : ] , axis = 1 ) for text_idx in range ( batch_size ) : if stop_conditions [ text_idx ] : continue sampled_char = self . reverse_target_char_index_ [ indices_of_sampled_tokens [ text_idx ] ] decoded_sentences [ text_idx ] . append ( sampled_char ) if ( sampled_char == '\n' ) or ( len ( decoded_sentences [ text_idx ] ) > self . max_decoder_seq_length_ ) : stop_conditions [ text_idx ] = True for token_idx in range ( len ( self . target_token_index_ ) ) : target_seq [ text_idx ] [ 0 ] [ token_idx ] = 0.0 target_seq [ text_idx , 0 , indices_of_sampled_tokens [ text_idx ] ] = 1.0 states_value = [ h , c ] for text_idx in range ( batch_size ) : texts . append ( ' ' . join ( decoded_sentences [ text_idx ] ) ) del input_seq del bounds_of_batches if isinstance ( X , tuple ) : return tuple ( texts ) if isinstance ( X , np . ndarray ) : return np . array ( texts , dtype = object ) return texts
short_docstring: Predict resulting sequences of tokens by source sequences with a trained seq2seq model.
short_docstring_tokens: Predict resulting sequences of tokens by source sequences with a trained seq2seq model .
comment: """ Predict resulting sequences of tokens by source sequences with a trained seq2seq model.
  
          Each sequence is unicode text composed from the tokens. Tokens are separated by spaces.
  
          :param X: source sequences.
  
          :return: resulting sequences, predicted for source sequences.
  
          """