Loading caption-lib/lstm/Readers/helper.py +4 −0 Original line number Diff line number Diff line Loading @@ -16,3 +16,7 @@ def get_input_data(filename): def get_vocabulary(filename): with open(outputPath + filename + '_vocab' + config.reader.export_data_type, 'r') as outfile: return jsonlib.load(outfile) def get_sequences(filename): with open(outputPath + filename + '_seqence' + config.reader.export_data_type, 'r') as outfile: return jsonlib.load(outfile) No newline at end of file caption-lib/lstm/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -3,3 +3,4 @@ # lstm folder level init from lstm import lstm_main from lstm import lstm_train from lstm import helpers No newline at end of file caption-lib/lstm/configuration.py +2 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,8 @@ class default_trainer(object): max_batches = 300 batches_in_epoch = 10 batch_size = 10 PAD = 0 EOS = 1 ''' Loading caption-lib/lstm/helpers.py 0 → 100644 +36 −0 Original line number Diff line number Diff line import numpy as np def batch(inputs, max_sequence_length=None): """ Args: inputs: list of sentences (integer lists) max_sequence_length: integer specifying how large should `max_time` dimension be. If None, maximum sequence length would be used Outputs: inputs_time_major: input sentences transformed into time-major matrix (shape [max_time, batch_size]) padded with 0s sequence_lengths: batch-sized list of integers specifying amount of active time steps in each input sequence """ sequence_lengths = [len(seq) for seq in inputs] batch_size = len(inputs) if max_sequence_length is None: max_sequence_length = max(sequence_lengths) inputs_batch_major = np.zeros(shape=[batch_size, max_sequence_length], dtype=np.int32) # == PAD for i, seq in enumerate(inputs): for j, element in enumerate(seq): inputs_batch_major[i, j] = element # [batch_size, max_time] -> [max_time, batch_size] inputs_time_major = inputs_batch_major.swapaxes(0, 1) return inputs_time_major, sequence_lengths No newline at end of file caption-lib/lstm/lstm_main.py +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ def main(self, parameter_list): reader.basic_text_reader() if(config.trainer.train_on): trainer.train() trainer() # class arguments Loading Loading
caption-lib/lstm/Readers/helper.py +4 −0 Original line number Diff line number Diff line Loading @@ -16,3 +16,7 @@ def get_input_data(filename): def get_vocabulary(filename): with open(outputPath + filename + '_vocab' + config.reader.export_data_type, 'r') as outfile: return jsonlib.load(outfile) def get_sequences(filename): with open(outputPath + filename + '_seqence' + config.reader.export_data_type, 'r') as outfile: return jsonlib.load(outfile) No newline at end of file
caption-lib/lstm/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -3,3 +3,4 @@ # lstm folder level init from lstm import lstm_main from lstm import lstm_train from lstm import helpers No newline at end of file
caption-lib/lstm/configuration.py +2 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,8 @@ class default_trainer(object): max_batches = 300 batches_in_epoch = 10 batch_size = 10 PAD = 0 EOS = 1 ''' Loading
caption-lib/lstm/helpers.py 0 → 100644 +36 −0 Original line number Diff line number Diff line import numpy as np def batch(inputs, max_sequence_length=None): """ Args: inputs: list of sentences (integer lists) max_sequence_length: integer specifying how large should `max_time` dimension be. If None, maximum sequence length would be used Outputs: inputs_time_major: input sentences transformed into time-major matrix (shape [max_time, batch_size]) padded with 0s sequence_lengths: batch-sized list of integers specifying amount of active time steps in each input sequence """ sequence_lengths = [len(seq) for seq in inputs] batch_size = len(inputs) if max_sequence_length is None: max_sequence_length = max(sequence_lengths) inputs_batch_major = np.zeros(shape=[batch_size, max_sequence_length], dtype=np.int32) # == PAD for i, seq in enumerate(inputs): for j, element in enumerate(seq): inputs_batch_major[i, j] = element # [batch_size, max_time] -> [max_time, batch_size] inputs_time_major = inputs_batch_major.swapaxes(0, 1) return inputs_time_major, sequence_lengths No newline at end of file
caption-lib/lstm/lstm_main.py +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ def main(self, parameter_list): reader.basic_text_reader() if(config.trainer.train_on): trainer.train() trainer() # class arguments Loading