summaryrefslogtreecommitdiff
path: root/fine_tune/bert
diff options
context:
space:
mode:
Diffstat (limited to 'fine_tune/bert')
-rw-r--r--fine_tune/bert/tutorials/03_bert_input_embedding.py20
-rw-r--r--fine_tune/bert/tutorials/samples/BERT-embeddings-2.pngbin0 -> 23064 bytes
2 files changed, 20 insertions, 0 deletions
diff --git a/fine_tune/bert/tutorials/03_bert_input_embedding.py b/fine_tune/bert/tutorials/03_bert_input_embedding.py
new file mode 100644
index 0000000..41bdd29
--- /dev/null
+++ b/fine_tune/bert/tutorials/03_bert_input_embedding.py
@@ -0,0 +1,20 @@
+
+from transformers import BertTokenizer, BertModel
+from transformers.models.bert import BertModel
+import torch
+from torch import nn
+
+
+model_name = 'bert-base-uncased'
+
+tokenizer = BertTokenizer.from_pretrained(model_name)
+model = BertModel.from_pretrained(model_name, output_hidden_states=True)
+
+test_sent = 'this is a test sentence'
+
+model_input = tokenizer(test_sent, return_tensors='pt')
+
+
+model.eval()
+with torch.no_grad():
+ output = model(**model_input)
diff --git a/fine_tune/bert/tutorials/samples/BERT-embeddings-2.png b/fine_tune/bert/tutorials/samples/BERT-embeddings-2.png
new file mode 100644
index 0000000..9b7072e
--- /dev/null
+++ b/fine_tune/bert/tutorials/samples/BERT-embeddings-2.png
Binary files differ