Created
January 15, 2021 09:33
-
-
Save IlievskiV/2bb3d315cacd8309e205fa1d41a6a74b to your computer and use it in GitHub Desktop.
How to use a pre-trained BERT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import BertTokenizer, BertModel | |
import torch | |
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') | |
model = BertModel.from_pretrained('bert-base-uncased') | |
inputs = tokenizer("[CLS] This is very awesome!", return_tensors="pt") | |
outputs = model(**inputs) | |
# the learned representation for the [CLS] token | |
cls = outputs.last_hidden_state[0, 0, :] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment