Welcome to mirror list, hosted at ThFree Co, Russian Federation.

history.h « common « amun « src - github.com/marian-nmt/marian.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 62d44ae0385026eb90daef44e8672aa870a7c086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include <queue>
#include <algorithm>

#include "hypothesis.h"
#include "beam.h"

namespace amunmt {

class Sentences;

class History {
  private:
    struct HypothesisCoord {
      bool operator<(const HypothesisCoord& hc) const {
        return cost < hc.cost;
      }

      unsigned i;
      unsigned j;
      float cost;
    };

    History(const History&) = delete;

  public:
    History(const Sentence &sentence, bool normalizeScore, unsigned maxLength);

    void Add(const Beam& beam);

    unsigned size() const {
      return history_.size();
    }

    Beam& front() {
      return history_.front();
    }

    NBestList NBest(unsigned n) const;

    Result Top() const {
      return NBest(1)[0];
    }

    unsigned GetLineNum() const
    { return lineNo_; }

    void SetActive(bool active);
    bool GetActive() const;

  private:
    std::vector<Beam> history_;
    std::priority_queue<HypothesisCoord> topHyps_;
    bool normalize_;
    unsigned lineNo_;
    unsigned maxLength_;
    bool active_;
};


}