Пример #1
0
    def build(self):
        query_input = self.new_query_input(size=20)
        url_input = self.new_url_input()
        title_input = self.new_title_input()
        body_input = self.new_body_input()
        inputs = [query_input, url_input, title_input, body_input]

        word_embedding = layers.Embedding(self.total_words, self.embedding_dim)
        query = layers.GlobalMaxPooling1D()(word_embedding(query_input))
        url = layers.GlobalMaxPooling1D()(word_embedding(url_input))
        title = layers.GlobalMaxPooling1D()(word_embedding(title_input))
        body = layers.GlobalMaxPooling1D()(word_embedding(body_input))
        input_features = [query, url, title, body]

        num_fields = len(input_features)
        features = tf.concat(input_features, axis=1)
        interactions = WeightedQueryFieldInteraction(num_fields, name='field_weights')(features)

        features = []
        for feature in input_features:
            feature = layers.Dense(1, activation='relu')(feature)
            features.append(feature)
        features = layers.Add()(features)
        features = AddBias0()(features)

        output = layers.Activation('sigmoid', name='label')(features + interactions)
        return tf.keras.Model(inputs=inputs, outputs=output, name=self.name)
Пример #2
0
    def build(self):
        text_inputs = [
            self.new_query_input(size=20),
            self.new_url_input(),
            self.new_title_input(),
            self.new_body_input(),
        ]
        inputs = text_inputs

        word_embedding = layers.Embedding(self.total_words, self.embedding_dim)
        text_features = [word_embedding(text_input) for text_input in text_inputs]
        text_features = [layers.GlobalMaxPooling1D()(feature) for feature in text_features]
        input_features = text_features

        interactions = []
        for feature1, feature2 in itertools.combinations(input_features, 2):
            interactions.append(layers.Dot(axes=1)([feature1, feature2]))
        interactions = layers.Add()(interactions)

        features = []
        for feature in input_features:
            feature = layers.Dense(1, activation='relu')(feature)
            features.append(feature)
        features = layers.Add()(features)
        features = AddBias0()(features)

        output = layers.Activation('sigmoid', name='label')(features + interactions)
        return tf.keras.Model(inputs=inputs, outputs=output, name=self.name)
Пример #3
0
    def build(self):
        query_input = self.new_query_input(size=20)
        url_input = self.new_url_input()
        title_input = self.new_title_input()
        body_input = self.new_body_input()
        inputs = [query_input, url_input, title_input, body_input]

        word_embedding = layers.Embedding(self.total_words, self.embedding_dim)
        query = layers.GlobalMaxPooling1D()(word_embedding(query_input))
        url = layers.GlobalMaxPooling1D()(word_embedding(url_input))
        title = layers.GlobalMaxPooling1D()(word_embedding(title_input))
        body = layers.GlobalMaxPooling1D()(word_embedding(body_input))
        input_features = [query, url, title, body]

        query_url = layers.Dot(axes=1)([query, url])
        query_title = layers.Dot(axes=1)([query, title])
        query_body = layers.Dot(axes=1)([query, body])
        interactions = layers.Add()([query_url, query_title, query_body])

        features = []
        for feature in input_features:
            feature = layers.Dense(1, activation='relu')(feature)
            features.append(feature)
        features = layers.Add()(features)
        features = AddBias0()(features)

        output = layers.Activation('sigmoid', name='label')(features + interactions)
        return tf.keras.Model(inputs=inputs, outputs=output, name=self.name)
Пример #4
0
    def build(self):
        text_inputs = [
            self.new_query_input(size=20),
            self.new_url_input(),
            self.new_title_input(),
            self.new_body_input(),
        ]
        inputs = text_inputs

        word_embedding = layers.Embedding(self.total_words, self.embedding_dim, name='text_embedding')
        text_features = [word_embedding(text_input) for text_input in text_inputs]
        text_features = [layers.GlobalMaxPooling1D()(feature) for feature in text_features]
        input_features = text_features

        num_fields = len(input_features)
        features = tf.concat(input_features, axis=1)
        interactions = WeightedFeatureInteraction(num_fields, name='field_weights')(features)

        features = []
        for feature in input_features:
            feature = layers.Dense(1, activation='relu')(feature)
            features.append(feature)
        features = layers.Add()(features)
        features = AddBias0()(features)

        output = layers.Activation('sigmoid', name='label')(features + interactions)
        return tf.keras.Model(inputs=inputs, outputs=output, name=self.name)
Пример #5
0
    def build(self):
        query_input = self.new_query_input()
        title_input = self.new_title_input()
        ingredients_input = self.new_ingredients_input()
        description_input = self.new_description_input()
        country_input = self.new_country_input()
        doc_id_input = self.new_doc_id_input()
        inputs = [
            query_input, title_input, ingredients_input, description_input,
            country_input, doc_id_input
        ]

        word_embedding = layers.Embedding(self.total_words,
                                          self.embedding_dim,
                                          name='word_embedding')
        query = layers.GlobalMaxPooling1D()(word_embedding(query_input))
        title = layers.GlobalMaxPooling1D()(word_embedding(title_input))
        ingredients = layers.GlobalMaxPooling1D()(
            word_embedding(ingredients_input))
        description = layers.GlobalMaxPooling1D()(
            word_embedding(description_input))
        country_embedding = layers.Embedding(self.total_countries,
                                             self.embedding_dim)
        country = country_embedding(country_input)
        country = tf.reshape(country, shape=(
            -1,
            self.embedding_dim,
        ))
        image_embedding = self.load_pretrained_embedding(
            embedding_filepath=
            f'{project_dir}/data/raw/en_2020-03-16T00_04_34_recipe_image_tagspace5000_300.pkl',
            embedding_dim=300,
            name='image_embedding')
        image = image_embedding(doc_id_input)
        image = tf.reshape(image, shape=(
            -1,
            300,
        ))
        image = layers.Dropout(.2)(image)
        image = layers.Dense(self.embedding_dim)(image)
        input_features = [
            query, title, ingredients, description, country, image
        ]

        num_fields = len(input_features)
        features = tf.concat(input_features, axis=1)
        interactions = WeightedSelectedFeatureInteraction(
            num_fields, name='field_weights')(features)

        features = []
        for feature in input_features:
            feature = layers.Dense(1, activation='relu')(feature)
            features.append(feature)
        features = layers.Add()(features)
        features = AddBias0()(features)

        output = layers.Activation('sigmoid',
                                   name='label')(features + interactions)
        return tf.keras.Model(inputs=inputs, outputs=output, name=self.name)
Пример #6
0
    def build(self):
        text_inputs = [
            self.new_query_input(),
            self.new_title_input(),
            self.new_ingredients_input(),
            self.new_description_input(),
        ]
        country_input = self.new_country_input()
        doc_id_input = self.new_doc_id_input()
        inputs = text_inputs + [country_input, doc_id_input]

        word_embedding = layers.Embedding(self.total_words,
                                          self.embedding_dim,
                                          name='word_embedding')
        texts = [
            layers.GlobalMaxPooling1D()(word_embedding(text_input))
            for text_input in text_inputs
        ]
        country_embedding = layers.Embedding(self.total_countries,
                                             self.embedding_dim)
        country = country_embedding(country_input)
        country = tf.reshape(country, shape=(
            -1,
            self.embedding_dim,
        ))
        image_embedding = self.load_pretrained_embedding(
            embedding_filepath=
            f'{project_dir}/data/raw/en_2020-03-16T00_04_34_recipe_image_tagspace5000_300.pkl',
            embedding_dim=300,
            name='image_embedding')
        image = image_embedding(doc_id_input)
        image = tf.reshape(image, shape=(
            -1,
            300,
        ))
        image = layers.Dropout(.2)(image)
        image = layers.Dense(self.embedding_dim)(image)
        input_features = texts + [country, image]

        interactions = []
        for feature1, feature2 in itertools.combinations(input_features, 2):
            interactions.append(layers.Dot(axes=1)([feature1, feature2]))
        interactions = layers.Add()(interactions)

        features = []
        for feature in input_features:
            feature = layers.Dense(1, activation='relu')(feature)
            features.append(feature)
        features = layers.Add()(features)
        features = AddBias0()(features)

        output = layers.Activation('sigmoid',
                                   name='label')(features + interactions)
        return tf.keras.Model(inputs=inputs, outputs=output, name=self.name)