| 311 | } |
| 312 | |
| 313 | void FixedUnigramSampler::LoadFromUnigrams(const std::vector<float>& unigrams, |
| 314 | float distortion) { |
| 315 | int32 word_id = weights_.size(); |
| 316 | for (float w : unigrams) { |
| 317 | // Skip entries that do not belong to this shard. |
| 318 | if (word_id % num_shards_ == shard_) { |
| 319 | w = std::pow(w, distortion); |
| 320 | total_weight_ += w; |
| 321 | weights_.push_back(w); |
| 322 | } |
| 323 | ++word_id; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | } // namespace tensorflow |