transformers icon indicating copy to clipboard operation
transformers copied to clipboard

How to use BartEncoder and BartDecoder

Open ryliu68 opened this issue 3 years ago • 0 comments

System Info

I'm a CVer, I want to use Bart as Auto-Encoder in CV task.

Here I have a question, how to use BartEncoder to encode A to z, and then how to decode z to "A"? I need an example code; please help me, than you very much.

Maybe like this two?

one:

model = BartForConditionalGeneration.from_pretrained('facebook/bart-base')
tokenizer = BartTokenizer.from_pretrained('facebook/bart-base')

inputs = A

encoder = model.model.encoder
decoder = model.model.decoder

z= encoder(input_ids = inputs["input_ids"])

A= decoder(z)

it will meet following error: ValueError: You have to specify either decoder_input_ids or decoder_inputs_embeds.

two:

from transformers.models.bart.modeling_bart import BartEncoder
from transformers.models.bart.modeling_bart import BartDecoder

inputs = A

z= BartEncoder(input_ids = inputs["input_ids"])

A= BartDecoder(z)

So, what should I do? I didn't find a document for this; please help me with this, thank you again.

@ArthurZucker @gante @Narsil 


### Who can help?

_No response_

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

as I provided code.

### Expected behavior

Write an example code or document

ryliu68 avatar Apr 30 '23 11:04 ryliu68