Exemplo n.º 1
0
    def setUp(self):
        self._neighbourhood_sizes = (2, 3)
        self._num_example_things = 2

        self._builder = array.ArrayConverter(self._neighbourhood_sizes)

        self._expected_dims = [self._num_example_things] + list(
            reversed(self._neighbourhood_sizes)) + [1]
Exemplo n.º 2
0
    def __init__(
        self,
        neighbour_sample_sizes,
        features_size,
        example_concepts_features_size,
        aggregated_size,
        embedding_size,
        schema_encoding_transaction,
        batch_size,
        embedding_normalisation=tf.nn.l2_normalize,
        neighbour_sampling_method=ordered.ordered_sample,
        neighbour_sampling_limit_factor=1,
        formatters={'neighbour_value_date': preprocess.datetime_to_unixtime},
        features_to_exclude=()):

        self._embedding_normalisation = embedding_normalisation
        self.embedding_size = embedding_size
        self.aggregated_size = aggregated_size
        self.neighbour_sample_sizes = neighbour_sample_sizes

        self.feature_sizes = [features_size] * len(self.neighbour_sample_sizes)
        self.feature_sizes[-1] = example_concepts_features_size
        print(f'feature sizes: {self.feature_sizes}')

        self._schema_encoding_transaction = schema_encoding_transaction
        self._encode = encode.Encoder(self._schema_encoding_transaction)

        self.batch_size = batch_size
        self._formatters = formatters
        self._features_to_exclude = features_to_exclude

        traversal_samplers = []
        for sample_size in neighbour_sample_sizes:
            traversal_samplers.append(
                sample.Sampler(sample_size,
                               neighbour_sampling_method,
                               limit=int(sample_size *
                                         neighbour_sampling_limit_factor)))

        self._array_builder = array.ArrayConverter(neighbour_sample_sizes)

        self._context_builder = builder.ContextBuilder(traversal_samplers)

        self._embed = embed.Embedder(
            self.feature_sizes,
            self.aggregated_size,
            self.embedding_size,
            self.neighbour_sample_sizes,
            normalisation=self._embedding_normalisation)

        features_to_exclude = {
            feat_name: None
            for feat_name in self._features_to_exclude
        }
        self.neighbourhood_dataset, self.array_placeholders = preprocess.build_dataset(
            self.neighbour_sample_sizes, **features_to_exclude)
Exemplo n.º 3
0
    def setUp(self):
        import grakn
        entity_query = "match $x isa company, has name 'Google'; get;"
        uri = "localhost:48555"
        keyspace = "test_schema"
        client = grakn.Grakn(uri=uri)
        session = client.session(keyspace=keyspace)
        self._tx = session.transaction(grakn.TxType.WRITE)

        neighbour_sample_sizes = (6, 4, 4)
        sampling_method = ordered.ordered_sample

        samplers = []
        for sample_size in neighbour_sample_sizes:
            samplers.append(
                samp.Sampler(sample_size,
                             sampling_method,
                             limit=sample_size * 2))

        grakn_things = [
            answermap.get('x')
            for answermap in list(self._tx.query(entity_query))
        ]

        things = [
            neighbour.build_thing(grakn_thing) for grakn_thing in grakn_things
        ]

        context_builder = builder.ContextBuilder(samplers)

        neighbourhood_depths = [
            context_builder.build(self._tx, thing) for thing in things
        ]

        neighbour_roles = builder.convert_thing_contexts_to_neighbours(
            neighbourhood_depths)

        # flat = builder.flatten_tree(neighbour_roles)
        # [builder.collect_to_tree(neighbourhood_depth) for neighbourhood_depth in neighbourhood_depths]

        ################################################################################################################
        # Context Array Building
        ################################################################################################################

        self._array_builder = array.ArrayConverter(neighbour_sample_sizes)
        self._context_arrays = self._array_builder.convert_to_array(
            neighbour_roles)
Exemplo n.º 4
0
    def setUp(self):

        self._neighbour_sample_sizes = (2, 3)

        neighbourhood_depths = [mock.mock_traversal_output()]

        neighbour_roles = builder.convert_thing_contexts_to_neighbours(
            neighbourhood_depths)

        ################################################################################################################
        # Context Array Building
        ################################################################################################################

        self._array_builder = array.ArrayConverter(
            self._neighbour_sample_sizes)
        self._context_arrays = self._array_builder.convert_to_array(
            neighbour_roles)
Exemplo n.º 5
0
    def test_date(self):
        neighbour_roles = [
            builder.Neighbour(
                None, None,
                builder.ThingContext(
                    neighbour.Thing("1",
                                    "start-date",
                                    "attribute",
                                    data_type='date',
                                    value=datetime.datetime(day=1,
                                                            month=1,
                                                            year=2018)),
                    mock.gen([]))),
        ]

        self._array_builder = array.ArrayConverter((2, 3))
        self._context_arrays = self._array_builder.convert_to_array(
            neighbour_roles)