| 542 | } |
| 543 | |
| 544 | EncodeResult Model::SampleEncode(absl::string_view normalized, |
| 545 | float theta) const { |
| 546 | if (!status().ok() || normalized.empty()) { |
| 547 | return {}; |
| 548 | } |
| 549 | |
| 550 | Lattice lattice; |
| 551 | lattice.SetSentence(normalized); |
| 552 | PopulateNodes(&lattice); |
| 553 | |
| 554 | EncodeResult results; |
| 555 | for (const auto *node : lattice.Sample(theta)) { |
| 556 | results.emplace_back(node->piece, node->id); |
| 557 | } |
| 558 | |
| 559 | return results; |
| 560 | } |
| 561 | |
| 562 | } // namespace unigram |
| 563 | } // namespace sentencepiece |