Removes vocabs and propogates fixes for breaks (#79)

* Removes vocabs and propogates fixes for breaks

* Prettify diff: Undoing comment shuffles due to merge conflict edits

* 20% of time actual work, 80% prettifying diff

* Histories members -> poof!

We however have Histories in constructor, which we will remove out of the way
soon.

Co-authored-by: Kenneth Heafield <kpu@users.noreply.github.com>
This commit is contained in:
Jerin Philip 2021-04-07 12:15:46 +01:00 коммит произвёл GitHub
Родитель 27a3a3253f
Коммит b71b3a18d8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 8 добавлений и 36 удалений

Просмотреть файл

@ -14,25 +14,11 @@
#include "translator/response.h" #include "translator/response.h"
#include "translator/service.h" #include "translator/service.h"
void marian_decoder_minimal(const marian::Histories &histories, void marian_decoder_minimal(const marian::bergamot::Response &response,
marian::Ptr<marian::Vocab const> targetVocab,
marian::Ptr<marian::Options> options) { marian::Ptr<marian::Options> options) {
// We are no longer marian-decoder compatible. Server ideas are on hold.
bool doNbest = options->get<bool>("n-best"); for (size_t sentenceIdx = 0; sentenceIdx < response.size(); sentenceIdx++) {
auto collector = std::cout << response.target.sentence(sentenceIdx) << "\n";
marian::New<marian::OutputCollector>(options->get<std::string>("output"));
// There is a dependency of vocabs here.
auto printer = marian::New<marian::OutputPrinter>(options, targetVocab);
if (options->get<bool>("quiet-translation"))
collector->setPrintingStrategy(marian::New<marian::QuietPrinting>());
for (auto &history : histories) {
std::stringstream best1;
std::stringstream bestn;
printer->print(history, best1, bestn);
collector->Write((long)history->getLineNum(), best1.str(), bestn.str(),
doNbest);
} }
} }
@ -53,7 +39,7 @@ int main(int argc, char *argv[]) {
responseFuture.wait(); responseFuture.wait();
const Response &response = responseFuture.get(); const Response &response = responseFuture.get();
marian_decoder_minimal(response.histories(), service.targetVocab(), options); marian_decoder_minimal(response, options);
LOG(info, "Total time: {:.5f}s wall", decoderTimer.elapsed()); LOG(info, "Total time: {:.5f}s wall", decoderTimer.elapsed());
return 0; return 0;

Просмотреть файл

@ -10,7 +10,7 @@ namespace bergamot {
Response::Response(AnnotatedText &&source, Histories &&histories, Response::Response(AnnotatedText &&source, Histories &&histories,
std::vector<Ptr<Vocab const>> &vocabs) std::vector<Ptr<Vocab const>> &vocabs)
: source(std::move(source)), histories_(std::move(histories)) { : source(std::move(source)) {
// Reserving length at least as much as source_ seems like a reasonable thing // Reserving length at least as much as source_ seems like a reasonable thing
// to do to avoid reallocations. // to do to avoid reallocations.
target.text.reserve(source.text.size()); target.text.reserve(source.text.size());
@ -24,7 +24,7 @@ Response::Response(AnnotatedText &&source, Histories &&histories,
size_t offset{0}; size_t offset{0};
bool first{true}; bool first{true};
for (auto &history : histories_) { for (auto &history : histories) {
// TODO(jerin): Change hardcode of nBest = 1 // TODO(jerin): Change hardcode of nBest = 1
NBestList onebest = history->nBest(1); NBestList onebest = history->nBest(1);

Просмотреть файл

@ -52,8 +52,7 @@ public:
Response(Response &&other) Response(Response &&other)
: source(std::move(other.source)), target(std::move(other.target)), : source(std::move(other.source)), target(std::move(other.target)),
alignments(std::move(other.alignments)), alignments(std::move(other.alignments)),
qualityScores(std::move(other.qualityScores)), qualityScores(std::move(other.qualityScores)){};
histories_(std::move(other.histories_)){};
// The following copy bans are not stricitly required anymore since Annotation // The following copy bans are not stricitly required anymore since Annotation
// is composed of the ByteRange primitive (which was previously string_view // is composed of the ByteRange primitive (which was previously string_view
@ -87,13 +86,6 @@ public:
/// sparse matrix representation with indices corresponding /// sparse matrix representation with indices corresponding
/// to (sub-)words accessible through Annotation. /// to (sub-)words accessible through Annotation.
std::vector<Alignment> alignments; std::vector<Alignment> alignments;
/// Access to histories, which holds rich information on translated text.
/// Not recommended to use, will be removed in future.
const Histories &histories() const { return histories_; }
private:
Histories histories_;
}; };
} // namespace bergamot } // namespace bergamot
} // namespace marian } // namespace marian

Просмотреть файл

@ -59,12 +59,6 @@ public:
/// asynchronous operation mode. /// asynchronous operation mode.
~Service(); ~Service();
/// Shared pointer to source-vocabulary.
Ptr<Vocab const> sourceVocab() const { return vocabs_.front(); }
/// Shared pointer to target vocabulary.
Ptr<Vocab const> targetVocab() const { return vocabs_.back(); }
/// To stay efficient and to refer to the string for alignments, expects /// To stay efficient and to refer to the string for alignments, expects
/// ownership be moved through std::move(..) /// ownership be moved through std::move(..)
/// ///