Ctranslate2 - TypeError: 'str' object is collable

Hi,

After required installation, I make a script i.e test.py and write this following code.

    import ctranslate2
    from tokenize import tokenize

    translator = ctranslate2.Translator("ende_ctranslate2/")
    results = translator.translate_batch(
    Input = "This project is geared towards efficient serving of standard translation models but is also a place for experimentation around model compression and inference acceleration."

    [tokenize(Input)],
    target_prefix=[tokenize("Ein Beispiel")],
    num_hypotheses=5,
    return_alternatives=True)
    for hypothesis in results[0]:
    print(detokenize(hypothesis["tokens"]))

Unfortunately, I am getting this follwing error:

[tokenize(Input)],
TypeError: ‘str’ object is not collable

I am trying to run decoding (Alternatives at a position)

Could please tell me where I am doing mistake or how I can get rid of this error.

Thanks

Your code does not look right, it’s quite hard to help you out here.
Can you format it properly? (with backquotes)

Also, is your tokenize module/function properly defined?

1 Like

Thanks @francoishernandez

After defined ‘tokenize’ function, it works.