python - 从 BERT 编码器(张量流)获取序列输出
问题描述
我正在尝试按照官方指南在 tensorflow 中微调 BERT,目的是将输出进一步输入 LSTM/GRU。我能够进行微调,但我从中得到的输出形状bert_encoder
是[num_samples, hidden_units]和[num_samples, 1, 768]。我相信这些分别是汇集输出和序列输出,但我很困惑为什么序列输出不是[num_samples, max_seq_length, hidden_units]。
bert_classifier
替换为bert_encoder
on compile and fit后运行此代码:
bert_encoder([glue_train["input_word_ids"][0:10],
glue_train["input_mask"][0:10],
glue_train["input_type_ids"][0:10]])
产生:
[<tf.Tensor: shape=(10, 1, 768), dtype=float32, numpy= ...>, <tf.Tensor: shape=(10, 768), dtype=float32, numpy= ...>]
由于我要传递给序列模型,因此我需要获取序列输出,但我一直只获得 1 个形状的序列长度。我一直试图理解为什么,但找不到任何东西。任何帮助和澄清将不胜感激。谢谢!
解决方案
推荐阅读
- javascript - 通过更改其签名导出反应钩子
- php - 创建大型邮件草稿
- mysql - MariaDB Select Distinct ON(预期有表达式(接近 ON)
- apache-poi - Apache-poi 如何在创建 Excel 文件时取消隐藏列
- ruby-on-rails - 如何从数组字符串中删除一些特殊字符
- image-processing - 如何使用 GIMP 缩放图像?
- html - 如何在 HTML css 中修复文本中心
- vb.net - 该进程试图写入一个不存在的管道 vb.net
- javascript - 如何在整个 angularjs 应用程序中将高亮 js 带入 pre 标签?
- javascript - 多个产品的 Javascript 自定义输入增量