OpenNMT

Ctranslate2 : target_prefix option

Hello,

I’ve been trying to use Ctranslate2 with the option “target_prefix”, but to no avail. I keep getting this error:

TypeError: translate_batch(): incompatible function arguments. The following argument types are supported:
    1. (self: ctranslate2.translator.Translator, source: List[List[str]], target_prefix: Optional[List[Optional[List[str]]]] = None, *, max_batch_size: int = 0, batch_type: str = 'examples', beam_size: int = 2, num_hypotheses: int = 1, length_penalty: float = 0, coverage_penalty: float = 0, prefix_bias_beta: float = 0, allow_early_exit: bool = True, max_decoding_length: int = 250, min_decoding_length: int = 1, use_vmap: bool = False, normalize_scores: bool = False, return_scores: bool = False, return_attention: bool = False, return_alternatives: bool = False, sampling_topk: int = 1, sampling_temperature: float = 1, replace_unknowns: bool = False) -> list

and this is my piece of code:

translation_ob = translator.translate_batch(dfChunk['SourceTokenized'].values.tolist(), target_prefix=dfChunk['TargetTokenizedKnown'].values.tolist(), return_scores=predictScore, normalize_scores=True)
        

dfChunk is a dataframe.

I tried few things, but i’m always getting the same error. Help would be much appreciated! :slight_smile:

Note: if I don’t use the target_prefix option, everything is working fine.

Best regards,
Samuel

Hi,

What’s the structure returned by dfChunk['TargetTokenizedKnown'].values.tolist()? Does it match the type List[List[str]]?

1 Like

Hello,

I indeed was sure that i was providing exactly just like there error stated, but just in case before replying to you; I checked again. Turn out it was a Code 18. (the issue was 18 inch away from the screen). I don’t know if I was just too tired… but I completely forgot to call the tokenization function for the target part, which also take care of structuring my data in the proper way…

Really sorry about that.

Best regards,
Samuel

1 Like