| 139 | } |
| 140 | |
| 141 | static std::vector<std::vector<float>> build_attention(const StorageView& history, |
| 142 | const dim_t batch, |
| 143 | const dim_t beam, |
| 144 | const dim_t start, |
| 145 | const dim_t end) { |
| 146 | if (!history) |
| 147 | return {}; |
| 148 | |
| 149 | const auto source_length = history.dim(-1); |
| 150 | |
| 151 | std::vector<std::vector<float>> attention; |
| 152 | attention.reserve(end - start); |
| 153 | for (dim_t t = start; t < end; ++t) { |
| 154 | const auto* vector = history.index<float>({batch, beam, t, 0}); |
| 155 | attention.emplace_back(vector, vector + source_length); |
| 156 | } |
| 157 | return attention; |
| 158 | } |
| 159 | |
| 160 | static std::vector<StorageView> build_logits(const StorageView& history, |
| 161 | const dim_t batch) { |