OpenNMT Forum

Ctranslate2 - TypeError: 'str' object is collable


After required installation, I make a script i.e 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."

    target_prefix=[tokenize("Ein Beispiel")],
    for hypothesis in results[0]:

Unfortunately, I am getting this follwing error:

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.


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.