Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cách sử dụng tokenizer của thư viện Transformers để encode input #1

Open
quancq opened this issue Nov 10, 2020 · 2 comments

Comments

@quancq
Copy link

quancq commented Nov 10, 2020

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]
@ngocnp
Copy link

ngocnp commented Dec 17, 2021

Mình dùng BertJapaneseTokenizer thì tokenize được token có dấu nhé

@sinhvtr
Copy link

sinhvtr commented Dec 31, 2021

Mình cũng cùng câu hỏi. Làm sao để lúc decode mình recover được đầy đủ dấu má vậy tác giả?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants