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:
Родитель
27a3a3253f
Коммит
b71b3a18d8
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<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
|
||||
|
|
|
@ -59,12 +59,6 @@ public:
|
|||
/// 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(..)
|
||||
///
|
||||
|
|
Загрузка…
Ссылка в новой задаче