Skip to content

Commit

Permalink
New goldens for text embedder, classifier tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 666887484
  • Loading branch information
talumbau authored and copybara-github committed Aug 23, 2024
1 parent 46b800a commit 73ea396
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST(TextClassifierTest, SmokeTest) {
EXPECT_EQ(result.classifications[0].categories_count, 2);
EXPECT_EQ(std::string{result.classifications[0].categories[0].category_name},
"positive");
EXPECT_NEAR(result.classifications[0].categories[0].score, 0.999371,
EXPECT_NEAR(result.classifications[0].categories[0].score, 0.999465,
kPrecision);

text_classifier_close_result(&result);
Expand Down
2 changes: 1 addition & 1 deletion mediapipe/tasks/c/text/text_embedder/text_embedder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST(TextEmbedderTest, SucceedsWithCosineSimilarity) {
double similarity;
text_embedder_cosine_similarity(&result0.embeddings[0],
&result1.embeddings[0], &similarity, nullptr);
double expected_similarity = 0.98077;
double expected_similarity = 0.97565;
EXPECT_LE(abs(similarity - expected_similarity), kPrecision);

text_embedder_close_result(&result0);
Expand Down
14 changes: 4 additions & 10 deletions mediapipe/tasks/cc/text/text_classifier/text_classifier_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,11 @@ TEST_F(TextClassifierTest, TextClassifierWithBert) {
/*head_name=*/"probability"});
#else
negative_expected.classifications.emplace_back(Classifications{
/*categories=*/{
{/*index=*/0, /*score=*/0.956316, /*category_name=*/"negative"},
{/*index=*/1, /*score=*/0.043683, /*category_name=*/"positive"}},
/*categories=*/{{0, 0.963325, "negative"}, {1, 0.036674, "positive"}},
/*head_index=*/0,
/*head_name=*/"probability"});
positive_expected.classifications.emplace_back(Classifications{
/*categories=*/{
{/*index=*/1, /*score=*/0.999945, /*category_name=*/"positive"},
{/*index=*/0, /*score=*/0.000056, /*category_name=*/"negative"}},
/*categories=*/{{1, 0.9999413, "positive"}, {0, 0.000058, "negative"}},
/*head_index=*/0,
/*head_name=*/"probability"});
#endif // _WIN32
Expand Down Expand Up @@ -255,10 +251,8 @@ TEST_F(TextClassifierTest, BertLongPositive) {
categories.push_back(
{/*index=*/0, /*score=*/0.023313, /*category_name=*/"negative"});
#else
categories.push_back(
{/*index=*/1, /*score=*/0.985889, /*category_name=*/"positive"});
categories.push_back(
{/*index=*/0, /*score=*/0.014112, /*category_name=*/"negative"});
categories.push_back({1, 0.981590, "positive"});
categories.push_back({0, 0.018409, "negative"});
#endif // _WIN32

expected.classifications.emplace_back(
Expand Down
4 changes: 2 additions & 2 deletions mediapipe/tasks/cc/text/text_embedder/text_embedder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TEST_F(EmbedderTest, SucceedsWithMobileBert) {
#elif defined(__FMA__)
ASSERT_NEAR(result0.embeddings[0].float_embedding[0], 21.3605f, kEpsilon);
#else
ASSERT_NEAR(result0.embeddings[0].float_embedding[0], 19.9016f, kEpsilon);
ASSERT_NEAR(result0.embeddings[0].float_embedding[0], 21.1785f, kEpsilon);
#endif // _WIN32

MP_ASSERT_OK_AND_ASSIGN(
Expand All @@ -92,7 +92,7 @@ TEST_F(EmbedderTest, SucceedsWithMobileBert) {
#ifdef __FMA__
ASSERT_NEAR(result1.embeddings[0].float_embedding[0], 21.254150f, kEpsilon);
#else
ASSERT_NEAR(result1.embeddings[0].float_embedding[0], 22.626251f, kEpsilon);
ASSERT_NEAR(result1.embeddings[0].float_embedding[0], 20.322639f, kEpsilon);
#endif

// Check cosine similarity.
Expand Down

0 comments on commit 73ea396

Please sign in to comment.