MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / build_attention

Function build_attention

src/decoding.cc:141–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) {

Callers 1

searchMethod · 0.85

Calls 1

dimMethod · 0.80

Tested by

no test coverage detected