I am using using MarianModel from the hub of HuggingFace for a translation task. Now I want to extract the embedding from the output of the last MarianEncoderLayer
layer. Specifically, given a text, I want to get the middle embedding of the text for another task. Here is what I did:
text = 'hello how are you?'
inputs = tokenizer(text,max_length=512,truncation=True,return_tensors='pt',padding=True)
model.model.encoder.layers[5](**inputs)
But it throws the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\dohuut\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'input_ids'
What is the proper way to extract this embedding?