-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
704860a
commit 1c16cfe
Showing
6 changed files
with
121 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "pch.h" | ||
|
||
#include "../opennn/embedding_layer.h" | ||
|
||
|
||
TEST(EmbeddingLayer, DefaultConstructor) | ||
{ | ||
EmbeddingLayer embedding_layer; | ||
|
||
EXPECT_EQ(embedding_layer.get_vocabulary_size(), 0); | ||
EXPECT_EQ(embedding_layer.get_sequence_length(), 0); | ||
EXPECT_EQ(embedding_layer.get_embedding_dimension(), 0); | ||
} | ||
|
||
|
||
TEST(EmbeddingLayer, GeneralConstructor) | ||
{ | ||
EmbeddingLayer embedding_layer(1,2,3); | ||
|
||
EXPECT_EQ(embedding_layer.get_vocabulary_size(), 1); | ||
EXPECT_EQ(embedding_layer.get_sequence_length(), 2); | ||
EXPECT_EQ(embedding_layer.get_embedding_dimension(), 3); | ||
} | ||
|
||
|
||
TEST(EmbeddingLayer, ForwardPropagate) | ||
{ | ||
const Index samples_number = get_random_index(1, 10); | ||
const Index vocabulary_size = get_random_index(1, 10); | ||
const Index sequence_length = get_random_index(1, 10); | ||
const Index embedding_dimension = get_random_index(1, 10); | ||
|
||
EmbeddingLayer embedding_layer(vocabulary_size, sequence_length, embedding_dimension); | ||
embedding_layer.set_parameters_constant(type(0)); | ||
|
||
unique_ptr<LayerForwardPropagation> embedding_layer_forward_propagation | ||
= make_unique<EmbeddingLayerForwardPropagation>(samples_number, &embedding_layer); | ||
|
||
Tensor<type, 2> inputs(samples_number, sequence_length); | ||
inputs.setConstant(type(0)); | ||
|
||
embedding_layer.forward_propagate({ make_pair(inputs.data(), dimensions{samples_number, sequence_length}) }, | ||
embedding_layer_forward_propagation, | ||
true); | ||
|
||
EXPECT_EQ(embedding_layer_forward_propagation->batch_samples_number, samples_number); | ||
EXPECT_EQ(embedding_layer_forward_propagation->get_outputs_pair().second[0], samples_number); | ||
EXPECT_EQ(embedding_layer_forward_propagation->get_outputs_pair().second[1], sequence_length); | ||
EXPECT_EQ(embedding_layer_forward_propagation->get_outputs_pair().second[2], embedding_dimension); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "pch.h" | ||
|
||
#include "../opennn/multihead_attention_layer.h" | ||
|
||
|
||
TEST(MultiheadAttentionLayer, DefaultConstructor) | ||
{ | ||
MultiheadAttentionLayer multihead_attention_layer; | ||
|
||
// EXPECT_EQ(multihead_attention_layer.get_vocabulary_size(), 0); | ||
// EXPECT_EQ(multihead_attention_layer.get_sequence_length(), 0); | ||
// EXPECT_EQ(multihead_attention_layer.get_embedding_dimension(), 0); | ||
} | ||
|
||
|
||
TEST(MultiheadAttentionLayer, GeneralConstructor) | ||
{ | ||
// MultiheadAttentionLayer multihead_attention_layer; | ||
|
||
// EXPECT_EQ(embedding_layer.get_vocabulary_size(), 1); | ||
// EXPECT_EQ(embedding_layer.get_sequence_length(), 2); | ||
// EXPECT_EQ(embedding_layer.get_embedding_dimension(), 3); | ||
} | ||
|
||
|
||
TEST(MultiheadAttentionLayer, ForwardPropagate) | ||
{ | ||
/* | ||
const Index samples_number = get_random_index(1, 10); | ||
const Index vocabulary_size = get_random_index(1, 10); | ||
const Index sequence_length = get_random_index(1, 10); | ||
const Index embedding_dimension = get_random_index(1, 10); | ||
EmbeddingLayer embedding_layer(vocabulary_size, sequence_length, embedding_dimension); | ||
embedding_layer.set_parameters_constant(type(0)); | ||
unique_ptr<LayerForwardPropagation> embedding_layer_forward_propagation | ||
= make_unique<EmbeddingLayerForwardPropagation>(samples_number, &embedding_layer); | ||
Tensor<type, 2> inputs(samples_number, sequence_length); | ||
inputs.setConstant(type(0)); | ||
embedding_layer.forward_propagate({ make_pair(inputs.data(), dimensions{samples_number, sequence_length}) }, | ||
embedding_layer_forward_propagation, | ||
true); | ||
EXPECT_EQ(embedding_layer_forward_propagation->batch_samples_number, samples_number); | ||
EXPECT_EQ(embedding_layer_forward_propagation->get_outputs_pair().second[0], samples_number); | ||
EXPECT_EQ(embedding_layer_forward_propagation->get_outputs_pair().second[1], sequence_length); | ||
EXPECT_EQ(embedding_layer_forward_propagation->get_outputs_pair().second[2], embedding_dimension); | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters