def setUp(self): self.id = False self.uv = False self.ub = False self.threshold = 0.8 self.assoc_threshold = 0.3 seed = 10 dim = 512 prop = 0.1 input_dir, output_dir = tools.read_config() relation_symbols = symbol_definitions.uni_relation_symbols() vector_factory = VectorFactory(seed) isA_symbols = symbol_definitions.isA_symbols() sentence_symbols = symbol_definitions.sentence_role_symbols() self.corpus_dict, self.id_vectors, self.semantic_pointers = \ tools.setup_corpus( input_dir, relation_symbols, dim, vector_factory, seed, self.id, self.uv, prop) self.createAssociator(self.id_vectors, self.semantic_pointers) self.tester = WordnetAssociativeMemoryTester( self.corpus_dict, self.id_vectors, self.semantic_pointers, relation_symbols, self.associator, seed, output_dir, isA_symbols, sentence_symbols, VectorFactory(), self.uv, True)
def run(num_runs, jump_trials, hier_trials, sent_trials, deep_trials, expr, unitary_roles, short_sentence, do_neg, corpus_seed, extractor_seed, test_seed, seed, dimension, num_synsets, proportion, unitary_relations, id_vecs, sp_noise, normalize, abstract, synapse, timesteps, threshold, probe_all, identical, fast, plot, gpus, name): input_dir, output_dir = read_config() if not name: name = "hrr_scaling_results" directory = make_filename(name, output_dir) if not os.path.isdir(directory): os.makedirs(directory) make_sym_link( os.path.split(directory)[1], os.path.join(output_dir, 'latest')) neural = not abstract if gpus is not None: gpus.sort() def make_corpus_factory(dimension, input_dir, unitary_relations, id_vecs, proportion, num_synsets, sp_noise, normalize): def make_corpus(): corpus = VectorizedCorpus( dimension=dimension, input_dir=input_dir, unitary_relations=unitary_relations, id_vecs=id_vecs, sp_noise=sp_noise, normalize=normalize, num_synsets=num_synsets, proportion=proportion) return corpus return make_corpus def make_extractor_factory(neural, fast, gpus, plot, threshold, timesteps, synapse): # pick an extraction algorithm def make_extractor(id_vectors, semantic_pointers, probe_keys, output_dir): if neural: if fast and gpus: extractor = FastNeuralExtractor( id_vectors, semantic_pointers, threshold=threshold, probe_keys=probe_keys, timesteps=timesteps, synapse=synapse, plot=plot, gpus=gpus, identical=identical, output_dir=output_dir) else: extractor = NeuralExtractor( id_vectors, semantic_pointers, threshold=threshold, probe_keys=probe_keys, timesteps=timesteps, synapse=synapse, plot=plot, gpus=gpus, identical=identical, output_dir=output_dir) else: extractor = Extractor( id_vectors, semantic_pointers, threshold, output_dir=output_dir) return extractor return make_extractor corpus_factory = make_corpus_factory( dimension, input_dir, unitary_relations, id_vecs, proportion, num_synsets, sp_noise, normalize) extractor_factory = make_extractor_factory( neural, fast, gpus, plot, threshold, timesteps, synapse) if seed != -1: random.seed(seed) corpus_seed = random.randrange(1000) extractor_seed = random.randrange(1000) test_seed = random.randrange(1000) else: if corpus_seed == -1: corpus_seed = random.randrange(1000) if extractor_seed == -1: extractor_seed = random.randrange(1000) if test_seed == -1: test_seed = random.randrange(1000) np.random.seed(test_seed) random.seed(test_seed) test_runner = ExtractionTester( corpus_factory, extractor_factory, corpus_seed, extractor_seed, test_seed, probe_all, directory) if jump_trials > 0: test = JumpTest(jump_trials) test_runner.add_test(test) if hier_trials > 0: test = HierarchicalTest(hier_trials, do_neg=do_neg) test_runner.add_test(test) if sent_trials > 0: test = SentenceTest( sent_trials, deep=False, unitary=unitary_roles, short=short_sentence) test_runner.add_test(test) if deep_trials > 0: test = SentenceTest( deep_trials, deep=True, unitary=unitary_roles, short=short_sentence) test_runner.add_test(test) if expr: expr_trials = expr[0] expr = expr[1] test = ExpressionTest(expr_trials, expression=expr) test_runner.add_test(test) test_runner.run_bootstrap(num_runs)
def run(num_runs, jump_trials, hier_trials, sent_trials, deep_trials, expr, unitary_roles, short_sentence, do_neg, corpus_seed, extractor_seed, test_seed, seed, dimension, num_synsets, proportion, unitary_relations, id_vecs, sp_noise, normalize, abstract, synapse, timesteps, threshold, probe_all, identical, fast, plot, gpus, name): input_dir, output_dir = read_config() if not name: name = "hrr_scaling_results" directory = make_filename(name, output_dir) if not os.path.isdir(directory): os.makedirs(directory) make_sym_link( os.path.split(directory)[1], os.path.join(output_dir, 'latest')) neural = not abstract if gpus is not None: gpus.sort() def make_corpus_factory(dimension, input_dir, unitary_relations, id_vecs, proportion, num_synsets, sp_noise, normalize): def make_corpus(): corpus = VectorizedCorpus(dimension=dimension, input_dir=input_dir, unitary_relations=unitary_relations, id_vecs=id_vecs, sp_noise=sp_noise, normalize=normalize, num_synsets=num_synsets, proportion=proportion) return corpus return make_corpus def make_extractor_factory(neural, fast, gpus, plot, threshold, timesteps, synapse): # pick an extraction algorithm def make_extractor(id_vectors, semantic_pointers, probe_keys, output_dir): if neural: if fast and gpus: extractor = FastNeuralExtractor(id_vectors, semantic_pointers, threshold=threshold, probe_keys=probe_keys, timesteps=timesteps, synapse=synapse, plot=plot, gpus=gpus, identical=identical, output_dir=output_dir) else: extractor = NeuralExtractor(id_vectors, semantic_pointers, threshold=threshold, probe_keys=probe_keys, timesteps=timesteps, synapse=synapse, plot=plot, gpus=gpus, identical=identical, output_dir=output_dir) else: extractor = Extractor(id_vectors, semantic_pointers, threshold, output_dir=output_dir) return extractor return make_extractor corpus_factory = make_corpus_factory(dimension, input_dir, unitary_relations, id_vecs, proportion, num_synsets, sp_noise, normalize) extractor_factory = make_extractor_factory(neural, fast, gpus, plot, threshold, timesteps, synapse) if seed != -1: random.seed(seed) corpus_seed = random.randrange(1000) extractor_seed = random.randrange(1000) test_seed = random.randrange(1000) else: if corpus_seed == -1: corpus_seed = random.randrange(1000) if extractor_seed == -1: extractor_seed = random.randrange(1000) if test_seed == -1: test_seed = random.randrange(1000) np.random.seed(test_seed) random.seed(test_seed) test_runner = ExtractionTester(corpus_factory, extractor_factory, corpus_seed, extractor_seed, test_seed, probe_all, directory) if jump_trials > 0: test = JumpTest(jump_trials) test_runner.add_test(test) if hier_trials > 0: test = HierarchicalTest(hier_trials, do_neg=do_neg) test_runner.add_test(test) if sent_trials > 0: test = SentenceTest(sent_trials, deep=False, unitary=unitary_roles, short=short_sentence) test_runner.add_test(test) if deep_trials > 0: test = SentenceTest(deep_trials, deep=True, unitary=unitary_roles, short=short_sentence) test_runner.add_test(test) if expr: expr_trials = expr[0] expr = expr[1] test = ExpressionTest(expr_trials, expression=expr) test_runner.add_test(test) test_runner.run_bootstrap(num_runs)