@@ -15,6 +15,7 @@ module nf_embedding_layer
1515 ! ! This layer converts them into a table of shape
1616 ! ! (`sequence_length`, `model_dimension`)
1717 integer :: sequence_length, vocab_size, model_dimension
18+ logical :: positional
1819
1920 real , allocatable :: weights(:, :)
2021 real , allocatable :: output(:, :)
@@ -24,6 +25,7 @@ module nf_embedding_layer
2425
2526 procedure :: backward
2627 procedure :: forward
28+ procedure :: positional_encoding
2729 procedure :: init
2830 procedure :: get_num_params
2931 procedure :: get_params
@@ -33,8 +35,9 @@ module nf_embedding_layer
3335 end type embedding_layer
3436
3537 interface embedding_layer
36- module function embedding_layer_cons (vocab_size , model_dimension ) result(res)
38+ module function embedding_layer_cons (vocab_size , model_dimension , positional ) result(res)
3739 integer , intent (in ) :: vocab_size, model_dimension
40+ logical , optional :: positional
3841 type (embedding_layer) :: res
3942 end function embedding_layer_cons
4043 end interface embedding_layer
@@ -54,6 +57,11 @@ pure module subroutine backward(self, input, gradient)
5457 real , intent (in ) :: gradient(:, :)
5558 end subroutine backward
5659
60+ pure module subroutine positional_encoding(self, pos)
61+ class(embedding_layer), intent (in out ) :: self
62+ integer , intent (in ) :: pos
63+ end subroutine positional_encoding
64+
5765 module subroutine init (self , input_shape )
5866 class(embedding_layer), intent (in out ) :: self
5967 integer , intent (in ) :: input_shape(:)
0 commit comments