I have a small dataset for sentiment analysis. The classifier will be a simple KNN but I wanted to get the word embedding with the Bert model from the transformers library. Note that I just found out about this library - I am still learning.
So looking at online example, I am trying to understand the dimensions that are returned from the model.
Example:
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
tokens = tokenizer.encode(["Hello, my dog is cute", "He is really nice"])
print(tokens)
tokens = tokenizer.encode("Hello, my dog is cute", "He is really nice")
print(tokens)
tokens = tokenizer.encode(["Hello, my dog is cute"])
print(tokens)
tokens = tokenizer.encode("Hello, my dog is cute")
print(tokens)
The output is the following:
[101, 100, 100, 102]
[101, 7592, 1010, 2026, 3899, 2003, 10140, 102, 2002, 2003, 2428, 3835, 102]
[101, 100, 102]
[101, 7592, 1010, 2026, 3899, 2003, 10140, 102]
I can't seem to find the docs for encode() - I have no idea why it returns different stuff when the input is passed as a list. What is this doing?
Additionally, is there a method to pass a word token and get the actual word back - to troubleshoot the above?
Thank you in advance