def test_forward(self): with initialize_config_dir(config_dir=get_config_directory()): data_folder, dataset_name = get_test_data_info() config = compose("main", overrides=[ f"data_folder={data_folder}", f"dataset.name={dataset_name}" ]) dataset_folder = join(config.data_folder, config.dataset.name) vocabulary = Vocabulary.load_vocabulary( join(dataset_folder, config.vocabulary_name)) data_file_path = join( dataset_folder, f"{config.dataset.name}.{config.train_holdout}.c2s") dataset = PathContextDataset(data_file_path, config, vocabulary, False) batch = PathContextBatch( [dataset[i] for i in range(config.hyper_parameters.batch_size)]) model = PathEncoder( config.encoder, config.decoder.decoder_size, len(vocabulary.token_to_id), vocabulary.token_to_id[PAD], len(vocabulary.node_to_id), vocabulary.node_to_id[PAD], ) output = model(batch.contexts) true_shape = (sum(batch.contexts_per_label), config.decoder.decoder_size) self.assertTupleEqual(true_shape, output.shape)
def test_forward(self): config = EncoderConfig(self._hidden_size, self._hidden_size, True, 0.5, 1, 0.5) buffered_path_contexts = BufferedPathContext.load(self._test_data_path) batch = PathContextBatch([buffered_path_contexts[i] for i in range(self._batch_size)]) token_vocab_size = max(batch.context[FROM_TOKEN].max().item(), batch.context[TO_TOKEN].max().item()) type_vocab_size = batch.context[PATH_TYPES].max().item() model = PathEncoder(config, self._hidden_size, token_vocab_size + 1, 0, type_vocab_size + 1, 0) out = model(batch.context) number_of_paths = sum(batch.contexts_per_label) self.assertTupleEqual((number_of_paths, self._hidden_size), out.shape)
def __init__(self, config: DictConfig, vocabulary: Vocabulary): super().__init__() self._config = config self.save_hyperparameters() self.encoder = PathEncoder( self._config.encoder, self._config.classifier.classifier_input_size, len(vocabulary.token_to_id), vocabulary.token_to_id[PAD], len(vocabulary.node_to_id), vocabulary.node_to_id[PAD], ) self.num_classes = len(vocabulary.label_to_id) self.classifier = PathClassifier(self._config.classifier, self.num_classes)
def __init__(self, config: Code2ClassConfig, vocab: Vocabulary, num_workers: int): super().__init__(config.hyperparams, vocab, num_workers) self.save_hyperparameters() self.encoder = PathEncoder( config.encoder_config, config.classifier_config.classifier_input_size, len(self.vocab.token_to_id), self.vocab.token_to_id[PAD], len(self.vocab.type_to_id), self.vocab.type_to_id[PAD], ) self.num_classes = len(self.vocab.label_to_id) self.classifier = PathClassifier(config.classifier_config, self.num_classes)
def __init__(self, config: Code2SeqConfig, vocab: Vocabulary, num_workers: int): super().__init__(config.hyperparams, vocab, num_workers) self.save_hyperparameters() encoder_config = config.encoder_config decoder_config = config.decoder_config self.encoder = PathEncoder( encoder_config, decoder_config.decoder_size, len(vocab.token_to_id), vocab.token_to_id[PAD], len(vocab.type_to_id), vocab.type_to_id[PAD], ) self.decoder = PathDecoder( decoder_config, len(vocab.label_to_id), vocab.label_to_id[SOS], vocab.label_to_id[PAD] )