示例#1
0
def test_embedding_block():
    utils.block_basic_exam(
        basic.Embedding(),
        tf.keras.Input(shape=(32,), dtype=tf.float32),
        [
            'pretraining',
            'embedding_dim',
        ])
示例#2
0
def test_embedding_block():
    input_shape = (32,)
    block = basic.Embedding()
    block.max_features = 100
    hp = kerastuner.HyperParameters()

    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('pretraining', hp)
    assert utils.name_in_hps('embedding_dim', hp)
示例#3
0
 def build(self, hp, inputs=None):
     input_node = nest.flatten(inputs)[0]
     output_node = input_node
     vectorizer = self.vectorizer or hp.Choice('vectorizer',
                                               ['sequence', 'ngram'],
                                               default='sequence')
     if vectorizer == 'ngram':
         output_node = preprocessing.TextToNgramVector().build(hp, output_node)
         output_node = basic.DenseBlock().build(hp, output_node)
     else:
         output_node = preprocessing.TextToIntSequence().build(hp, output_node)
         output_node = basic.Embedding(
             pretraining=self.pretraining).build(hp, output_node)
         output_node = basic.ConvBlock().build(hp, output_node)
         output_node = reduction.SpatialReduction().build(hp, output_node)
         output_node = basic.DenseBlock().build(hp, output_node)
     return output_node