.. _program_listing_file_src_data_alignment.h: Program Listing for File alignment.h ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/data/alignment.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include namespace marian { namespace data { class WordAlignment { public: struct Point { size_t srcPos; size_t tgtPos; float prob; }; private: std::vector data_; public: WordAlignment(); private: WordAlignment(const std::vector& align); public: WordAlignment(const std::string& line, size_t srcEosPos, size_t tgtEosPos); Point& operator[](size_t i) { return data_[i]; } auto begin() const -> decltype(data_.begin()) { return data_.begin(); } auto end() const -> decltype(data_.end()) { return data_.end(); } void push_back(size_t s, size_t t, float p) { data_.emplace_back(Point{ s, t, p }); } size_t size() const { return data_.size(); } void sort(); void normalize(bool reverse=false); std::string toString() const; }; // soft alignment = P(src pos|trg pos) for each beam and batch index, stored in a flattened CPU-side array // Also used on QuickSAND boundary where beam and batch size is 1. Then it is simply [t][s] -> P(s|t) typedef std::vector> SoftAlignment; // [trg pos][beam depth * max src length * batch size] WordAlignment ConvertSoftAlignToHardAlign(const SoftAlignment& alignSoft, float threshold = 1.f); std::string SoftAlignToString(SoftAlignment align); } // namespace data } // namespace marian