File size: 751 Bytes
6c54217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import torch
from transformers import BertTokenizer, BertModel, GPT2LMHeadModel, GPT2Tokenizer

# Load pre-trained models and tokenizers
bert_model_name = 'bert-base-uncased'
bert_tokenizer = BertTokenizer.from_pretrained(bert_model_name)
bert_model = BertModel.from_pretrained(bert_model_name)

gpt2_model_name = 'gpt2'
gpt2_tokenizer = GPT2Tokenizer.from_pretrained(gpt2_model_name)
gpt2_model = GPT2LMHeadModel.from_pretrained(gpt2_model_name)

# Save BERT model and tokenizer
bert_model.save_pretrained("bert_model")
bert_tokenizer.save_pretrained("bert_model")

# Save GPT-2 model and tokenizer
gpt2_model.save_pretrained("gpt2_model")
gpt2_tokenizer.save_pretrained("gpt2_model")


# In[ ]: