Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: components/translate/core/browser/translate_ranker_unittest.cc

Issue 2565873002: [translate] Add translate ranker model loader. (Closed)
Patch Set: Initial CL Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/translate/core/browser/translate_ranker.h" 5 #include "components/translate/core/browser/translate_ranker.h"
6 6
7 #include <initializer_list> 7 #include <initializer_list>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 double expected = Sigmoid(0.5 * 0.02f + // accept ratio * weight 159 double expected = Sigmoid(0.5 * 0.02f + // accept ratio * weight
160 0.5 * 0.03f + // decline ratio * weight 160 0.5 * 0.03f + // decline ratio * weight
161 0.0 * 0.00f + // ignore ratio * (default) weight 161 0.0 * 0.00f + // ignore ratio * (default) weight
162 1.0 * 0.04f + // one-hot src-language "en" * weight 162 1.0 * 0.04f + // one-hot src-language "en" * weight
163 1.0 * 0.00f + // one-hot dst-language "fr" * weight 163 1.0 * 0.00f + // one-hot dst-language "fr" * weight
164 1.0 * 0.07f + // one-hot country * weight 164 1.0 * 0.07f + // one-hot country * weight
165 1.0 * 0.12f + // one-hot locale * weight 165 1.0 * 0.12f + // one-hot locale * weight
166 0.01f); // bias 166 0.01f); // bias
167 167
168 EXPECT_NEAR(expected, 168 EXPECT_NEAR(expected,
169 ranker->CalculateScore(0.5, 0.5, 0.0, "en", "fr", "zh-CN", "us"), 169 ranker->CalculateScore(ranker->GetSharedModelPtr()->data, 0.5,
170 0.5, 0.0, "en", "fr", "zh-CN", "us"),
170 0.000001); 171 0.000001);
171 } 172 }
172 173
173 TEST_F(TranslateRankerTest, ShouldOfferTranslation) { 174 TEST_F(TranslateRankerTest, ShouldOfferTranslation) {
174 InitFeatures({kTranslateRankerQuery, kTranslateRankerEnforcement}, {}); 175 InitFeatures({kTranslateRankerQuery, kTranslateRankerEnforcement}, {});
175 // With a bias of -0.5 en->fr is not over the threshold. 176 // With a bias of -0.5 en->fr is not over the threshold.
176 EXPECT_FALSE(GetRankerForTest(-0.5f)->ShouldOfferTranslation( 177 EXPECT_FALSE(GetRankerForTest(-0.5f)->ShouldOfferTranslation(
177 *translate_prefs_, "en", "fr")); 178 *translate_prefs_, "en", "fr"));
178 // With a bias of 0.25 en-fr is over the threshold. 179 // With a bias of 0.25 en-fr is over the threshold.
179 EXPECT_TRUE(GetRankerForTest(0.25f)->ShouldOfferTranslation(*translate_prefs_, 180 EXPECT_TRUE(GetRankerForTest(0.25f)->ShouldOfferTranslation(*translate_prefs_,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 ranker->RecordTranslateEvent(event_1); 223 ranker->RecordTranslateEvent(event_1);
223 ranker->RecordTranslateEvent(event_2); 224 ranker->RecordTranslateEvent(event_2);
224 ranker->RecordTranslateEvent(event_3); 225 ranker->RecordTranslateEvent(event_3);
225 226
226 // Logging is disabled, so no events should be cached. 227 // Logging is disabled, so no events should be cached.
227 ranker->FlushTranslateEvents(&flushed_events); 228 ranker->FlushTranslateEvents(&flushed_events);
228 EXPECT_EQ(0U, flushed_events.size()); 229 EXPECT_EQ(0U, flushed_events.size());
229 } 230 }
230 231
231 } // namespace translate 232 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698