Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program still running when i call the translate_batch #1796

Open
itperson2024 opened this issue Oct 11, 2024 · 0 comments
Open

Program still running when i call the translate_batch #1796

itperson2024 opened this issue Oct 11, 2024 · 0 comments

Comments

@itperson2024
Copy link

hi,
I am writing a program using qt. and When I call the function translate_batch, the program not stopping, my code is below:
I found the solution in the documentation and other references, but not find useful information. please help me to solve the problem, thanks.

int main()
{
SetConsoleOutputCP(CP_UTF8);
sentencepiece::SentencePieceProcessor processor;
const auto status = processor.Load("./spm.model");

std::vector<std::string> tokens;
processor.Encode("我参加了毕业典礼", &tokens);


for (const std::string &token : tokens) {
    std::cout << token << std::endl;
}

std::vector<std::vector<std::string>> batch;

std::vector<std::string>::iterator it;
it = tokens.begin();
tokens.insert(it, "zho_Hans");

it = tokens.end();
tokens.insert(it, "</s>");
batch.push_back(tokens);

ctranslate2::Translator translator("./nllb", ctranslate2::Device::CPU);
std::vector<std::vector<std::string>> target_prefix;

for (int i = 0; i < batch.size(); i++) {
    target_prefix.push_back({"eng_Latn"});
}

TranslationOptions options1 = TranslationOptions();
//options1.beam_size = 1;

std::vector<ctranslate2::TranslationResult> results = translator.translate_batch(batch, target_prefix, options1, 1, BatchType::Tokens);

for (const auto& translatedTokens : results) {
    std::string text;
    processor.Decode(translatedTokens.output(), &text);
    //std::string result = tokenizer.detokenize(translatedTokens.output());
    text = text.substr(9);
    std::cout << text << ' ';
    std::cout << std::endl;
}

return 1;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant