LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
birnn_and_deep_biaffine_attention.cpp
Go to the documentation of this file.
1// Copyright 2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include <algorithm>
7#include <chrono>
8#include <iostream>
9#include <limits>
10
12#include "static_graph/dict.h"
13
14using namespace std;
15using namespace torch;
16using torch::indexing::Slice;
17
18using namespace deeplima::nets;
19
20namespace deeplima
21{
22namespace graph_dp
23{
24namespace train
25{
26
27#define SERIALIZATION_KEY_TASKS "tasks"
28#define SERIALIZATION_KEY_INPUT_FEATURES "input_features"
29#define SERIALIZATION_KEY_INPUT_FEATURES_NAMES "input_features_names"
30#define SERIALIZATION_KEY_EMBD_FN "embd_fn"
31#define SERIALIZATION_KEY_REL_CLASSES "rel_classes"
32
33void BiRnnAndDeepBiaffineAttentionImpl::load(serialize::InputArchive& archive)
34{
36
37 //assert(m_classes.size() == 0);
38
39 c10::IValue v;
40 if (archive.try_read(SERIALIZATION_KEY_TASKS, v))
41 {
42 if (!v.isList())
43 {
44 throw std::runtime_error("List of tasks must be a list.");
45 }
46
47 const c10::List<c10::IValue>& l = v.toList();
48 m_output_class_names.reserve(l.size());
49
50 for (size_t i = 0; i < l.size(); i++)
51 {
52 if (!l.get(i).isString())
53 {
54 throw std::runtime_error("List of tasks must be a list of strings.");
55 }
56
57 m_output_class_names.push_back(l.get(i).toStringRef());
58 }
59 }
60 else
61 {
62 throw std::runtime_error("Can't load list of tasks.");
63 }
64
65 if (archive.try_read(SERIALIZATION_KEY_INPUT_FEATURES_NAMES, v))
66 {
67 if (!v.isList())
68 {
69 throw std::runtime_error("List of input feature names must be a list.");
70 }
71
72 const c10::List<c10::IValue>& l = v.toList();
73 m_input_class_names.reserve(l.size());
74
75 for (size_t i = 0; i < l.size(); i++)
76 {
77 if (!l.get(i).isString())
78 {
79 throw std::runtime_error("List of input features names must be a list of strings.");
80 }
81
82 m_input_class_names.push_back(l.get(i).toStringRef());
83 }
84 }
85 else
86 {
87 throw std::runtime_error("Can't load list of input feature names.");
88 }
89
90 if (archive.try_read(SERIALIZATION_KEY_INPUT_FEATURES, v))
91 {
92 if (!v.isList())
93 {
94 throw std::runtime_error("List of input features must be a list.");
95 }
96
97 const c10::List<c10::IValue>& l = v.toList();
98 m_input_classes.reserve(l.size());
99
100 for (size_t i = 0; i < l.size(); i++)
101 {
102 if (!l.get(i).isList())
103 {
104 throw std::runtime_error("List of input features must be a list of lists of strings.");
105 }
106
107 auto d = std::make_shared<StringDict>();
108 d->fromIValue(l.get(i));
109 m_input_classes.push_back(d);
110 }
111 }
112 else
113 {
114 throw std::runtime_error("Can't list of input features.");
115 }
116
117 if (archive.try_read(SERIALIZATION_KEY_EMBD_FN, v))
118 {
119 if (!v.isList())
120 {
121 throw std::runtime_error("embd_fn must be a list.");
122 }
123
124 const c10::List<c10::IValue>& l = v.toList();
125 const c10::IValue& s = l.get(0);
126
127 if (!s.isString())
128 {
129 throw std::runtime_error("embd_fm must be a list of strings.");
130 }
131
132 m_embd_fn = s.toStringRef();
133 }
134 else
135 {
136 throw std::runtime_error("Can't load embd_fn.");
137 }
138
139 // deprel (rel) class names: optional, absent in arc-only models.
140 if (archive.try_read(SERIALIZATION_KEY_REL_CLASSES, v))
141 {
142 if (!v.isList())
143 {
144 throw std::runtime_error("List of rel classes must be a list.");
145 }
146 const c10::List<c10::IValue>& l = v.toList();
147 m_rel_class_names.clear();
148 m_rel_class_names.reserve(l.size());
149 for (size_t i = 0; i < l.size(); i++)
150 {
151 if (!l.get(i).isString())
152 {
153 throw std::runtime_error("List of rel classes must be a list of strings.");
154 }
155 m_rel_class_names.push_back(l.get(i).toStringRef());
156 }
157 m_num_labels = (int64_t) m_rel_class_names.size();
158 }
159}
160
161void BiRnnAndDeepBiaffineAttentionImpl::save(serialize::OutputArchive& archive) const
162{
164
165 // Save output class names
166 {
167 c10::List<std::string> list_of_class_names;
168 list_of_class_names.reserve(m_output_class_names.size());
169 for (size_t i = 0; i < m_output_class_names.size(); i++)
170 {
171 list_of_class_names.push_back(m_output_class_names[i]);
172 }
173 archive.write(SERIALIZATION_KEY_TASKS, list_of_class_names);
174 }
175
176 // Save input class names
177 {
178 c10::List<std::string> list_of_class_names;
179 list_of_class_names.reserve(m_input_class_names.size());
180 for (size_t i = 0; i < m_input_class_names.size(); i++)
181 {
182 list_of_class_names.push_back(m_input_class_names[i]);
183 }
184 archive.write(SERIALIZATION_KEY_INPUT_FEATURES_NAMES, list_of_class_names);
185 }
186
187 // Save input classes
188 c10::List<c10::List<std::string>> list_of_classes;
189 for (size_t i = 0; i < m_input_classes.size(); i++)
190 {
191 c10::List<std::string> current_class;
192 shared_ptr<StringDict> d = dynamic_pointer_cast<StringDict, DictBase>(m_input_classes[i]);
193 for (size_t j = 0; j < d->size(); j++)
194 {
195 current_class.push_back(d->get_value(j));
196 }
197 list_of_classes.push_back(current_class);
198 }
199 archive.write(SERIALIZATION_KEY_INPUT_FEATURES, list_of_classes);
200
201 // Save embeddings file names
202 c10::List<std::string> list_of_embd_fn;
203 list_of_embd_fn.reserve(1);
204 list_of_embd_fn.push_back(m_embd_fn);
205 archive.write(SERIALIZATION_KEY_EMBD_FN, list_of_embd_fn);
206
207 // Save deprel (rel) class names so inference can map predicted ids to labels.
208 c10::List<std::string> list_of_rel_classes;
209 list_of_rel_classes.reserve(m_rel_class_names.size());
210 for (size_t i = 0; i < m_rel_class_names.size(); i++)
211 {
212 list_of_rel_classes.push_back(m_rel_class_names[i]);
213 }
214 archive.write(SERIALIZATION_KEY_REL_CLASSES, list_of_rel_classes);
215}
216
218 const std::vector<std::string>& output_names,
219 const IterableDataSet& train_batches,
220 const IterableDataSet& eval_batches,
221 torch::optim::Optimizer& opt,
222 double& best_eval_accuracy,
223 const torch::Device& device)
224{
225 auto train_iterator = train_batches.get_iterator();
226 train_iterator->set_batch_size(params.m_batch_size);
228 m_clip = params.m_clip;
230 const bool select_on_las = (params.m_select_on == "las");
231 if (!select_on_las && params.m_select_on != "arc")
232 {
233 throw std::invalid_argument("select-on must be arc or las, not " + params.m_select_on);
234 }
235
236 double best_eval_loss = std::numeric_limits<double>::max();
237 size_t count_below_best = 0;
238 double lr_copy = 0;
239 unsigned int epoch = 0;
240 while (true)
241 {
242 for (auto &group : opt.param_groups())
243 {
244 if (group.has_options())
245 {
246 // Generic accessors: the optimizer may be Adam or SGD (-o)
247 lr_copy = group.options().get_lr();
248 }
249 }
250
251 nets::epoch_stat_t train_stat, eval_stat;
252
253 chrono::steady_clock::time_point begin = chrono::steady_clock::now();
254
256 0,
257 output_names,
258 train_iterator,
259 opt,
260 train_stat,
261 device);
262
263 for (const std::string& tn : output_names)
264 {
265 if (train_stat[tn].m_items > 0)
266 {
267 train_stat[tn].m_accuracy = double(train_stat[tn].m_correct) / train_stat[tn].m_items;
268 train_stat[tn].m_loss /= train_stat[tn].m_items;
269 }
270 }
271
272 chrono::steady_clock::time_point train_end = chrono::steady_clock::now();
273
274 evaluate(output_names, eval_batches.get_iterator(), eval_stat, device);
275
276 for (const std::string& tn : output_names)
277 {
278 if (eval_stat[tn].m_items > 0)
279 {
280 eval_stat[tn].m_accuracy = double(eval_stat[tn].m_correct) / eval_stat[tn].m_items;
281 eval_stat[tn].m_loss /= eval_stat[tn].m_items;
282 }
283 }
284
285 chrono::steady_clock::time_point eval_end = chrono::steady_clock::now();
286
287 auto train_duration = std::chrono::duration_cast<std::chrono::milliseconds>(train_end - begin).count();
288 auto eval_duration = std::chrono::duration_cast<std::chrono::milliseconds>(eval_end - train_end).count();
289
290 if (eval_stat.count("las") && eval_stat["las"].m_items > 0)
291 {
292 eval_stat["las"].m_accuracy = double(eval_stat["las"].m_correct) / eval_stat["las"].m_items;
293 }
294
295 for (const string& task_name : output_names)
296 {
297 const auto& train = train_stat[task_name];
298 const auto& eval = eval_stat[task_name];
299 std::cout << "EPOCH " << epoch << " | " << task_name << " | LR=" << lr_copy
300 << " | TRAIN LOSS=" << train.m_loss << " ACC=" << train.m_accuracy
301 << " | EVAL LOSS=" << eval.m_loss << " ACC=" << eval.m_accuracy;
302 if (2 == eval.m_num_classes)
303 {
304 std::cout << " P=" << eval.m_precision << " R=" << eval.m_recall<< " F1=" << eval.m_f1;
305 }
306 else
307 {
308 std::cout << " CORRECT=" << eval.m_correct;
309 }
310 std::cout << std::endl << std::flush;
311 }
312 if (eval_stat.count("las") && eval_stat["las"].m_items > 0)
313 {
314 std::cout << "EPOCH " << epoch << " | las | EVAL ACC=" << eval_stat["las"].m_accuracy
315 << " CORRECT=" << eval_stat["las"].m_correct << std::endl;
316 }
317 cout << "TIME: train=" << train_duration << "[ms] eval=" << eval_duration << "[ms]" << endl;
318
319 task_stat_t& main_task_eval = eval_stat[output_names[0]];
320 // The loss stays the arc one: LAS has none
321 const double selection_accuracy = (select_on_las && eval_stat.count("las"))
322 ? eval_stat["las"].m_accuracy : main_task_eval.m_accuracy;
323
324 best_eval_loss = min(best_eval_loss, main_task_eval.m_loss);
325 if (selection_accuracy > best_eval_accuracy)
326 {
327 best_eval_accuracy = selection_accuracy;
328 if (params.m_output_model_name.size() > 0)
329 {
330 torch::save(*this, params.m_output_model_name + ".pt");
331 }
332 count_below_best = 0;
333 }
334 else if (selection_accuracy < best_eval_accuracy)
335 {
336 for (auto &group : opt.param_groups())
337 {
338 if (group.has_options())
339 {
340 auto &options = group.options();
341 options.set_lr(options.get_lr() * params.m_lr_decay);
342 lr_copy = options.get_lr();
343 }
344 }
345 if (lr_copy < 0.0000001)
346 {
347 return;
348 }
349 count_below_best++;
350 if (main_task_eval.m_loss > best_eval_loss && count_below_best > params.m_max_epochs_without_improvement)
351 {
352 return;
353 }
354 }
355 epoch++;
356 if (epoch >= params.m_max_epochs)
357 {
358 return;
359 }
360 }
361}
362
364 size_t /*seq_len*/,
365 const vector<string>& output_names,
366 shared_ptr<BatchIterator> dataset_iterator,
367 torch::optim::Optimizer& opt,
368 epoch_stat_t& stat,
369 const torch::Device& device)
370{
371 Module::train(true);
372
373 dataset_iterator->start_epoch();
374
375 while (!dataset_iterator->end())
376 {
377 const BatchIterator::Batch batch = dataset_iterator->next_batch();
378 if (batch.empty())
379 {
380 continue;
381 }
383 0,
384 output_names,
385 batch.trainable_input(),
386 batch.frozen_input(),
387 batch.gold(),
388 opt,
389 stat,
390 device);
391 }
392}
393
395 size_t seq_len,
396 const vector<string>& output_names,
397 const torch::Tensor& trainable_input,
398 const torch::Tensor& nontrainable_input,
399 const torch::Tensor& gold,
400 torch::optim::Optimizer& opt,
401 epoch_stat_t& stat,
402 const torch::Device& device)
403{
404 using torch::indexing::Slice;
405 static constexpr int64_t kIgnore = -100;
406
407 map<string, torch::Tensor> current_batch_inputs;
408 split_input(trainable_input, current_batch_inputs, device);
409 current_batch_inputs["raw"] = nontrainable_input.to(device);
410 if (m_word_dropout > 0)
411 {
412 // Zero the whole form embedding of some words ([seq, batch, dim]), so that
413 // the parser also learns from the tags and the context
414 torch::Tensor& raw = current_batch_inputs["raw"];
415 torch::Tensor keep = torch::bernoulli(
416 torch::full({ raw.size(0), raw.size(1), 1 }, 1.0 - m_word_dropout, raw.options()));
418 {
419 keep.index_put_({ 0 }, 1.0);
420 }
421 raw = raw * keep;
422 }
423
424 const int64_t B = gold.size(0);
425 const int64_t D = gold.size(1);
426 auto target = gold.reshape({-1, gold.size(2)}).to(device); // [B*D, ncols]
427
428 const bool train_rel = (m_num_labels > 0)
429 && (std::find(output_names.begin(), output_names.end(), std::string("rel")) != output_names.end());
430
431 std::vector<std::string> requested = { "arc" };
432 if (train_rel) { requested.push_back("rel_logits"); }
433
434 opt.zero_grad();
435 auto out = forward(current_batch_inputs, requested.begin(), requested.end());
436
437 // ---- arc (head prediction) ----
438 {
439 torch::Tensor o = out["arc"].reshape({ -1, out["arc"].size(2) }); // [N, heads]
440 torch::Tensor tgt = target.index({ Slice(), Slice(0, 1) }).reshape({ -1 });
441 torch::Tensor loss = torch::nn::functional::nll_loss(
442 o, tgt, torch::nn::functional::NLLLossFuncOptions().ignore_index(kIgnore));
443 torch::Tensor valid = tgt.ne(kIgnore);
444 torch::Tensor pred = o.argmax(1);
445 task_stat_t& s = stat["arc"];
446 s.m_loss += loss.sum().item<double>();
447 s.m_correct += pred.eq(tgt).logical_and(valid).sum().item<int64_t>();
448 s.m_items += valid.sum().item<int64_t>();
449 loss.backward({}, /*retain_graph=*/train_rel);
450 }
451
452 // ---- rel (deprel label), scored at the gold head ----
453 if (train_rel)
454 {
455 torch::Tensor rel_logits = out["rel_logits"]; // [B, dep, head, num_labels]
456 const int64_t L = rel_logits.size(3);
457 torch::Tensor gold_head = target.index({ Slice(), 0 }).reshape({ B, D });
458 torch::Tensor gh = gold_head.clamp_min(0); // ignored positions -> 0 (masked by loss)
459 torch::Tensor idx = gh.unsqueeze(-1).unsqueeze(-1).expand({ B, D, 1, L });
460 torch::Tensor gathered = rel_logits.gather(2, idx).squeeze(2); // [B, dep, num_labels]
461 torch::Tensor rel_log = torch::log_softmax(gathered, 2).reshape({ -1, L });
462 torch::Tensor tgt = target.index({ Slice(), Slice(1, 2) }).reshape({ -1 });
463 torch::Tensor loss = torch::nn::functional::nll_loss(
464 rel_log, tgt, torch::nn::functional::NLLLossFuncOptions().ignore_index(kIgnore));
465 torch::Tensor valid = tgt.ne(kIgnore);
466 torch::Tensor pred = rel_log.argmax(1);
467 task_stat_t& s = stat["rel"];
468 s.m_loss += loss.sum().item<double>();
469 s.m_correct += pred.eq(tgt).logical_and(valid).sum().item<int64_t>();
470 s.m_items += valid.sum().item<int64_t>();
471 loss.backward();
472 }
473
474 if (m_clip > 0)
475 {
476 torch::nn::utils::clip_grad_norm_(parameters(), m_clip);
477 }
478 opt.step();
479}
480
481void BiRnnAndDeepBiaffineAttentionImpl::evaluate(const vector<string>& output_names,
482 shared_ptr<BatchIterator> dataset_iterator,
483 epoch_stat_t& stat,
484 const torch::Device& device)
485{
486 eval();
487 dataset_iterator->set_batch_size(-1);
488
489 dataset_iterator->start_epoch();
490
491 while (!dataset_iterator->end())
492 {
493 const BatchIterator::Batch batch = dataset_iterator->next_batch();
494 if (batch.empty())
495 {
496 continue;
497 }
498
499 epoch_stat_t t;
500
501 evaluate(output_names,
502 batch.trainable_input(),
503 batch.frozen_input(),
504 batch.gold(),
505 t,
506 device);
507 for (const std::string& task_name : output_names)
508 {
509 stat[task_name].m_correct += t[task_name].m_correct;
510 stat[task_name].m_items += t[task_name].m_items;
511 stat[task_name].m_loss += t[task_name].m_loss;
512 }
513 if (t.count("las"))
514 {
515 stat["las"].m_correct += t["las"].m_correct;
516 stat["las"].m_items += t["las"].m_items;
517 }
518 }
519}
520
521void BiRnnAndDeepBiaffineAttentionImpl::evaluate(const vector<string>& output_names,
522 const torch::Tensor& trainable_input,
523 const torch::Tensor& nontrainable_input,
524 const torch::Tensor& gold,
525 epoch_stat_t& stat,
526 const torch::Device& device)
527{
528 using torch::indexing::Slice;
529 static constexpr int64_t kIgnore = -100;
530
531 map<string, torch::Tensor> current_inputs;
532 split_input(trainable_input, current_inputs, device);
533 current_inputs["raw"] = nontrainable_input.to(device);
534
535 const int64_t B = gold.size(0);
536 const int64_t D = gold.size(1);
537 auto target = gold.reshape({-1, gold.size(-1)}).to(device);
538
539 const bool eval_rel = (m_num_labels > 0)
540 && (std::find(output_names.begin(), output_names.end(), std::string("rel")) != output_names.end());
541
542 std::vector<std::string> requested = { "arc" };
543 if (eval_rel) { requested.push_back("rel_logits"); }
544
545 torch::NoGradGuard no_grad;
546 auto out = forward(current_inputs, requested.begin(), requested.end());
547
548 torch::Tensor arc_pred; // predicted head of each position, [B*D]
549 torch::Tensor arc_ok; // head correct and position scored
550 // ---- arc (UAS) ----
551 {
552 torch::Tensor o = out["arc"].reshape({ -1, out["arc"].size(2) });
553 torch::Tensor tgt = target.index({ Slice(), Slice(0, 1) }).reshape({ -1 });
554 torch::Tensor loss = torch::nn::functional::nll_loss(
555 o, tgt, torch::nn::functional::NLLLossFuncOptions().ignore_index(kIgnore));
556 torch::Tensor valid = tgt.ne(kIgnore);
557 torch::Tensor pred = o.argmax(1);
558 arc_pred = pred;
559 arc_ok = pred.eq(tgt).logical_and(valid);
560 task_stat_t& s = stat["arc"];
561 s.m_loss = loss.sum().item<double>();
562 s.m_correct = pred.eq(tgt).logical_and(valid).sum().item<int64_t>();
563 s.m_items = valid.sum().item<int64_t>();
564 }
565
566 // ---- rel (label accuracy at the gold head) ----
567 if (eval_rel)
568 {
569 torch::Tensor rel_logits = out["rel_logits"]; // [B, dep, head, num_labels]
570 const int64_t L = rel_logits.size(3);
571 torch::Tensor gold_head = target.index({ Slice(), 0 }).reshape({ B, D });
572 torch::Tensor gh = gold_head.clamp_min(0);
573 torch::Tensor idx = gh.unsqueeze(-1).unsqueeze(-1).expand({ B, D, 1, L });
574 torch::Tensor gathered = rel_logits.gather(2, idx).squeeze(2);
575 torch::Tensor rel_log = torch::log_softmax(gathered, 2).reshape({ -1, L });
576 torch::Tensor tgt = target.index({ Slice(), Slice(1, 2) }).reshape({ -1 });
577 torch::Tensor loss = torch::nn::functional::nll_loss(
578 rel_log, tgt, torch::nn::functional::NLLLossFuncOptions().ignore_index(kIgnore));
579 torch::Tensor valid = tgt.ne(kIgnore);
580 torch::Tensor pred = rel_log.argmax(1);
581 task_stat_t& s = stat["rel"];
582 s.m_loss = loss.sum().item<double>();
583 s.m_correct = pred.eq(tgt).logical_and(valid).sum().item<int64_t>();
584 s.m_items = valid.sum().item<int64_t>();
585
586 // ---- LAS: label predicted at the PREDICTED head, as at analysis time ----
587 torch::Tensor ph = arc_pred.reshape({ B, D });
588 torch::Tensor pidx = ph.unsqueeze(-1).unsqueeze(-1).expand({ B, D, 1, L });
589 torch::Tensor rel_at_pred = rel_logits.gather(2, pidx).squeeze(2).argmax(2).reshape({ -1 });
590 task_stat_t& las = stat["las"];
591 las.m_correct = rel_at_pred.eq(tgt).logical_and(arc_ok).sum().item<int64_t>();
592 las.m_items = valid.sum().item<int64_t>();
593 }
594}
595
597 const torch::Tensor& /*inputs*/,
598 int64_t /*input_begin*/,
599 int64_t /*input_end*/,
600 int64_t /*output_begin*/,
601 int64_t /*output_end*/,
602 std::shared_ptr< StdMatrix<uint8_t> >& /*output*/,
603 const std::vector<std::string>& /*outputs_names*/,
604 const torch::Device& /*device*/)
605{
606// TODO should it be implemented?
607}
608
609} // namespace train
610} // namespace graph_dp
611} // namespace deeplima
#define SERIALIZATION_KEY_TASKS
#define SERIALIZATION_KEY_EMBD_FN
#define SERIALIZATION_KEY_INPUT_FEATURES
#define SERIALIZATION_KEY_INPUT_FEATURES_NAMES
#define SERIALIZATION_KEY_REL_CLASSES
void train(const train_params_graph_dp_t &params, const std::vector< std::string > &output_names, const IterableDataSet &train_batches, const IterableDataSet &eval_batches, torch::optim::Optimizer &opt, double &best_eval_accuracy, const torch::Device &device=torch::Device(torch::kCPU))
void train_batch(size_t batch_size, size_t seq_len, const std::vector< std::string > &output_names, const torch::Tensor &trainable_input, const torch::Tensor &nontrainable_input, const torch::Tensor &gold, torch::optim::Optimizer &opt, nets::epoch_stat_t &stat, const torch::Device &device)
void train_epoch(size_t batch_size, size_t seq_len, const std::vector< std::string > &output_names, std::shared_ptr< BatchIterator > train_iterator, torch::optim::Optimizer &opt, nets::epoch_stat_t &stat, const torch::Device &device)
void predict(size_t worker_id, const torch::Tensor &inputs, int64_t input_begin, int64_t input_end, int64_t output_begin, int64_t output_end, std::shared_ptr< StdMatrix< uint8_t > > &output, const std::vector< std::string > &outputs_names, const torch::Device &device=torch::Device(torch::kCPU))
virtual void load(torch::serialize::InputArchive &archive)
virtual void save(torch::serialize::OutputArchive &archive) const
void evaluate(const std::vector< std::string > &output_names, std::shared_ptr< BatchIterator > dataset_iterator, nets::epoch_stat_t &stat, const torch::Device &device=torch::Device(torch::kCPU))
virtual std::shared_ptr< BatchIterator > get_iterator() const =0
void split_input(const torch::Tensor &src, std::map< std::string, torch::Tensor > &dst, const torch::Device &device)
virtual void load(torch::serialize::InputArchive &archive)
virtual void save(torch::serialize::OutputArchive &archive) const
virtual void to(torch::Device device, bool non_blocking=false) override
std::map< std::string, torch::Tensor > forward(const std::map< std::string, torch::Tensor > &inputs, const std::string &output_name)
std::map< std::string, task_stat_t > epoch_stat_t
Edit rules for lemmatizing words absent from the lemma dictionary.
STL namespace.