candle-tutorial icon indicating copy to clipboard operation
candle-tutorial copied to clipboard

getting decoded output

Open ingride opened this issue 1 year ago • 3 comments

hi.

any suggestions on how to get a decoded output once I have done

let output = model.forward(&input_ids, &token_ids)?;

Am trying to go from a text input, extract input and token_ids, and then decode to a text output. I tried to do some basic convert but didn't get anywhere. if you have an example, I would appreciate it, am kinda struggling to connect the bits.

ingride avatar Dec 08 '23 14:12 ingride

Hi @ingride ,

Oh when you get the output_ids, you can decode back to text using the model tokenizer

tokenizer.decode(output)

source: https://github.com/huggingface/candle/blob/9bd94c1ffa0ccfd2bbc9526569b8b8a2a3812027/candle-examples/src/token_output_stream.rs#L27

ToluClassics avatar Dec 08 '23 19:12 ToluClassics

sorry this might be a very dumb question, but the output is a two dimensional tensor - Base Roberta.

are you suggesting to flatten it similarly to here https://github.com/ToluClassics/candle-tutorial/blob/main/tests/test_roberta.rs#L81 ? because decode takes a &[u32] slice as param.

how do i get the output_ids from the two dimensional tensor / the config

ingride avatar Dec 14 '23 18:12 ingride

@ToluClassics any thoughts on this?

ingride avatar Dec 18 '23 12:12 ingride