Пример #1
0
    def build(self, input_shape):
        if isinstance(input_shape, list):
            assert len(input_shape) == 2
            input_ids_shape, token_type_ids_shape = input_shape
            self.input_spec = [tf.keras.layers.InputSpec(shape=input_ids_shape),
                               tf.keras.layers.InputSpec(shape=token_type_ids_shape)]
        else:
            input_ids_shape = input_shape
            self.input_spec = tf.keras.layers.InputSpec(shape=input_ids_shape)

        self.embeddings_layer = AdvBertEmbeddingsLayer.from_params(
            self.params,
            name="embeddings"
        )

        # create all transformer encoder sub-layers
        self.encoders_layer = TransformerEncoderLayer.from_params(
            self.params,
            name="encoder"
        )

        self.dropout_layer = tf.keras.layers.Dropout(rate=self.params.hidden_dropout)
        self.pooler_layer = PoolerLayer(self.params.hidden_size, name="pooler")

        super(BertModelLayer, self).build(input_shape)
Пример #2
0
    def _construct(self, **kwargs):
        super()._construct(**kwargs)
        self.embeddings_layer = BertEmbeddingsLayer.from_params(
            self.params, name="embeddings")
        # create all transformer encoder sub-layers
        self.encoders_layer = TransformerEncoderLayer.from_params(
            self.params, name="encoder")

        self.support_masking = True
Пример #3
0
    def build(self, input_shape):
        if isinstance(input_shape, list):
            assert len(input_shape) == 2
            input_ids_shape, token_type_ids_shape = input_shape
            self.input_spec = [
                keras.layers.InputSpec(shape=input_ids_shape),
                keras.layers.InputSpec(shape=token_type_ids_shape)
            ]
        else:
            input_ids_shape = input_shape
            self.input_spec = keras.layers.InputSpec(shape=input_ids_shape)

        self.embeddings_layer = BertEmbeddingsLayer.from_params(self.params, name="embeddings")

        # create all transformer encoder sub-layers
        self.encoders_layer = TransformerEncoderLayer.from_params(self.params, name="encoder")

        super(BertModelLayer, self).build(input_shape)