Word Embedding or Sentence Embedding
#9
by
ShariatMohamadreza
- opened
how to get vector embedding from this model? unlike bert and ... it doesnt have .last_hidden_state attribute
This comment has been hidden
Hi,
You should use it like the below code:
# Tokenize the input
inputs = tokenizer(text, return_tensors="pt", add_special_tokens=True, padding=True, truncation=True)
# Get the input IDs and attention mask
input_ids = inputs["input_ids"]
attention_mask = inputs["attention_mask"]
# Pass through the model
with torch.no_grad():
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
# Get the last hidden state
last_hidden_state = outputs.last_hidden_state
mohalisad
changed discussion status to
closed