You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Khi chạy đoạn code bên dưới thì em nhận được list id của các từ đã bị bỏ dấu so với câu đầu vào. Em muốn hỏi cách để encode và sử dụng thư viện cho đúng ạ. Em mong muốn encoded_ids là [2, 9, 10, 11, 3]. Em cảm ơn mọi người đã giải đáp ạ.
import torch
from transformers import AutoTokenizer, AutoModel
if __name__ == "__main__":
#model_name = "FPTAI/velectra-base-discriminator-cased"
model_name = "FPTAI/vibert-base-cased"
tokenizer = AutoTokenizer.from_pretrained(model_name)
vocab = tokenizer.get_vocab()
id2token = {idx: token for token, idx in vocab.items()}
word_ids = [9, 10, 11]
sent = tokenizer.decode(word_ids)
print(sent) # có là và
encoded_ids = tokenizer.encode(sent)
for word_id in encoded_ids:
print(word_id, id2token[word_id])
# 2 [CLS]
# 382 co
# 523 la
# 391 va
# 3 [SEP]
The text was updated successfully, but these errors were encountered:
Khi chạy đoạn code bên dưới thì em nhận được list id của các từ đã bị bỏ dấu so với câu đầu vào. Em muốn hỏi cách để encode và sử dụng thư viện cho đúng ạ. Em mong muốn encoded_ids là [2, 9, 10, 11, 3]. Em cảm ơn mọi người đã giải đáp ạ.
The text was updated successfully, but these errors were encountered: