前言
BERT 模型
-
BERT-Large, Uncased (Whole Word Masking)
-
语言种类:英文
-
网络结构:24-layer, 1024-hidden, 16-heads
-
参数规模:340M
-
BERT-Large, Cased (Whole Word Masking)
-
语言种类:英文
-
网络结构:24-layer, 1024-hidden, 16-heads
-
参数规模:340M
-
BERT-Base, Uncased
-
语言种类:英文
-
网络结构:12-layer, 768-hidden, 12-heads
-
参数规模:110M
-
BERT-Large, Uncased
-
语言种类:英文
-
网络结构:24-layer, 1024-hidden, 16-heads
-
参数规模:340M
-
BERT-Base, Cased
-
语言种类:英文
-
网络结构:12-layer, 768-hidden, 12-heads
-
参数规模:110M
-
BERT-Large, Cased
-
语言种类:英文
-
网络结构:24-layer, 1024-hidden, 16-heads
-
参数规模:340M
-
BERT-Base, Multilingual Cased (New, recommended)
-
语言种类:104 种语言
-
网络结构:12-layer, 768-hidden, 12-heads
-
参数规模:110M
-
BERT-Base, Multilingual Uncased (Orig, not recommended)
-
语言种类:102 种语言、
-
网络结构:12-layer, 768-hidden, 12-heads
-
参数规模:110M
-
BERT-Base, Chinese
-
语言种类:中文
-
网络结构:12-layer, 768-hidden, 12-heads
-
参数规模:110M
BERT模型具体的网络结构和原理可阅读论文 BERT ,在此不再赘述。
BERT 模型的使用
一、当作文本特征提取的工具,类似Word2vec模型一样
二、作为一个可训练的层,后面可接入客制化的网络,做迁移学习
特征提取工具
首先,需要安装 server 和 client 两个包:
然后,下载 BERT 预训练模型,可以点击上述链接下载,比如我们下载中文版本 BERT 模型BERT-Base, Chinese 。下载完成后,解压到本地某个目录下。
例如:/tmp/chinese_L-12_H-768_A-12/
然后,打开终端,输入以下命令启动服务:
])
])
Tensorflow 加载 BERT 模型
-
利用 bert 开源代码
-
利用 Tensorflow_hub(推荐)
global_variables_initializer())
save()
需要,需要安装 Tensorflow_hub,
pip install tensorflow_hub
下载完成后,解压至本地,就可以利用如下方法加载模型:
)
)
Keras 加载 BERT 模型
bert
bert_layer
后记
<pre style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;color: rgb(0, 0, 0);font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong>完<strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong></span></strong></span></strong></p><section style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section><p style="margin-bottom: 15px;padding-right: 0em;padding-left: 0em;max-width: 100%;color: rgb(127, 127, 127);font-size: 12px;font-family: sans-serif;line-height: 25.5938px;letter-spacing: 3px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;font-family: 微软雅黑;caret-color: red;box-sizing: border-box !important;overflow-wrap: break-word !important;">为您推荐</span></strong></span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 14px;">为什么魂斗罗只有128KB却可以实现那么长的剧情?</span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 14px;">GitHub重大更新:在线开发上线,是时候卸载IDE了</span><br /></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">有了这个神器,轻松用 Python 写个 App</span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">「最全」实至名归,NumPy 官方早有中文教程</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="color: rgb(87, 107, 149);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">史上最烂的项目:苦撑12年,600多万行代码...</span></p></section></section></section></section></section></section></section></section>
本篇文章来源于: 深度学习这件小事
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
内容反馈