Skip to content

Commit

Permalink
Removes vocabs and propogates fixes for breaks (#79)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Jerin Philip and kpu authored Apr 7, 2021
1 parent 27a3a32 commit b71b3a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 36 deletions.
24 changes: 5 additions & 19 deletions app/marian-decoder-new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,11 @@
#include "translator/response.h"
#include "translator/service.h"

void marian_decoder_minimal(const marian::Histories &histories,
marian::Ptr<marian::Vocab const> targetVocab,
void marian_decoder_minimal(const marian::bergamot::Response &response,
marian::Ptr<marian::Options> options) {

bool doNbest = options->get<bool>("n-best");
auto collector =
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);
// 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";
}
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/translator/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace bergamot {

Response::Response(AnnotatedText &&source, Histories &&histories,
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
// to do to avoid reallocations.
target.text.reserve(source.text.size());
Expand All @@ -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);

Expand Down
10 changes: 1 addition & 9 deletions src/translator/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class Response {
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
Expand Down Expand Up @@ -87,13 +86,6 @@ class Response {
/// sparse matrix representation with indices corresponding
/// to (sub-)words accessible through Annotation.
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 marian
Expand Down
6 changes: 0 additions & 6 deletions src/translator/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ class Service {
/// asynchronous operation mode.
~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
/// ownership be moved through std::move(..)
///
Expand Down

0 comments on commit b71b3a1

Please sign in to comment.