Views
No views yet
1from bert4torch.models import build_transformer_model
2
3# 1. 仅指定config_path: 从头初始化模型结构, 不加载预训练模型
4model = build_transformer_model('./model/bert4torch_config.json')
5
6# 2. 仅指定checkpoint_path:
7## 2.1 文件夹路径: 自动寻找路径下的*.bin/*.safetensors权重文件 + bert4torch_config.json/config.json文件
8model = build_transformer_model(checkpoint_path='./model')
9
10## 2.2 文件路径/列表: 文件路径即权重路径/列表, config会从同级目录下寻找
11model = build_transformer_model(checkpoint_path='./pytorch_model.bin')
12
13## 2.3 model_name: hf上预训练权重名称, 会自动下载hf权重以及bert4torch_config.json文件
14model = build_transformer_model(checkpoint_path='bert-base-chinese')
15
16# 3. 同时指定config_path和checkpoint_path(本地路径名或model_name排列组合):
17config_path = './model/bert4torch_config.json' # 或'bert-base-chinese'
18checkpoint_path = './model/pytorch_model.bin' # 或'bert-base-chinese'
19model = build_transformer_model(config_path, checkpoint_path)