From b71b3a18d815de21adcf4b222e1b76f23bf50ee7 Mon Sep 17 00:00:00 2001 From: Jerin Philip Date: Wed, 7 Apr 2021 12:15:46 +0100 Subject: [PATCH] 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 --- app/marian-decoder-new.cpp | 24 +++++------------------- src/translator/response.cpp | 4 ++-- src/translator/response.h | 10 +--------- src/translator/service.h | 6 ------ 4 files changed, 8 insertions(+), 36 deletions(-) diff --git a/app/marian-decoder-new.cpp b/app/marian-decoder-new.cpp index dea49eb..a2516d9 100644 --- a/app/marian-decoder-new.cpp +++ b/app/marian-decoder-new.cpp @@ -14,25 +14,11 @@ #include "translator/response.h" #include "translator/service.h" -void marian_decoder_minimal(const marian::Histories &histories, - marian::Ptr targetVocab, +void marian_decoder_minimal(const marian::bergamot::Response &response, marian::Ptr options) { - - bool doNbest = options->get("n-best"); - auto collector = - marian::New(options->get("output")); - - // There is a dependency of vocabs here. - auto printer = marian::New(options, targetVocab); - if (options->get("quiet-translation")) - collector->setPrintingStrategy(marian::New()); - - 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); + // We are no longer marian-decoder compatible. Server ideas are on hold. + for (size_t sentenceIdx = 0; sentenceIdx < response.size(); sentenceIdx++) { + std::cout << response.target.sentence(sentenceIdx) << "\n"; } } @@ -53,7 +39,7 @@ int main(int argc, char *argv[]) { responseFuture.wait(); 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()); return 0; diff --git a/src/translator/response.cpp b/src/translator/response.cpp index faa42da..e5bc38f 100644 --- a/src/translator/response.cpp +++ b/src/translator/response.cpp @@ -10,7 +10,7 @@ namespace bergamot { Response::Response(AnnotatedText &&source, Histories &&histories, std::vector> &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 // to do to avoid reallocations. target.text.reserve(source.text.size()); @@ -24,7 +24,7 @@ Response::Response(AnnotatedText &&source, Histories &&histories, size_t offset{0}; bool first{true}; - for (auto &history : histories_) { + for (auto &history : histories) { // TODO(jerin): Change hardcode of nBest = 1 NBestList onebest = history->nBest(1); diff --git a/src/translator/response.h b/src/translator/response.h index 385735c..4f87b8d 100644 --- a/src/translator/response.h +++ b/src/translator/response.h @@ -52,8 +52,7 @@ public: Response(Response &&other) : source(std::move(other.source)), target(std::move(other.target)), alignments(std::move(other.alignments)), - qualityScores(std::move(other.qualityScores)), - histories_(std::move(other.histories_)){}; + qualityScores(std::move(other.qualityScores)){}; // The following copy bans are not stricitly required anymore since Annotation // is composed of the ByteRange primitive (which was previously string_view @@ -87,13 +86,6 @@ public: /// sparse matrix representation with indices corresponding /// to (sub-)words accessible through Annotation. std::vector 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 marian diff --git a/src/translator/service.h b/src/translator/service.h index f3502da..72f6d92 100644 --- a/src/translator/service.h +++ b/src/translator/service.h @@ -59,12 +59,6 @@ public: /// asynchronous operation mode. ~Service(); - /// Shared pointer to source-vocabulary. - Ptr sourceVocab() const { return vocabs_.front(); } - - /// Shared pointer to target vocabulary. - Ptr targetVocab() const { return vocabs_.back(); } - /// To stay efficient and to refer to the string for alignments, expects /// ownership be moved through std::move(..) ///