python - 为什么输入掩码在 BERT 语言模型中都是相同的数字?
问题描述
对于文本分类任务,我应用了 Bert(fine tune),得到的输出如下: 为什么 input_mask 都是 1 ?
#to_feature_map is a function.
to_feature_map("hi how are you doing",0)
({'input_mask': <tf.Tensor: shape=(64,), dtype=int32, numpy=
array([1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
dtype=int32)>,
'input_type_ids': <tf.Tensor: shape=(64,), dtype=int32, numpy=
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
dtype=int32)>,
'input_word_ids': <tf.Tensor: shape=(64,), dtype=int32, numpy=
array([ 101, 7632, 2129, 2024, 2017, 2725, 102, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)>},
<tf.Tensor: shape=(), dtype=int32, numpy=0>)```
解决方案
输入掩码——允许模型清楚地区分内容和填充。掩码与输入 ID 具有相同的形状,并且在输入 ID 未填充的任何位置都包含 1。
推荐阅读
- django - 使用 Django API 中的 VueJ 迭代对象列表
- matlab - 当我使用在迭代 1 中创建的 gmfitdist 病态协方差时出现此错误
- php - Symfony4复选框不保存
- javascript - 如何在表格行鼠标事件上限制多个添加和删除类名
- c++ - list.push_back 的分段错误
- react-native - 在调用 `reduxifyNavigator` 之前,请先调用 `createReactNavigationReduxMiddleware`,以便我们知道何时触发您的监听器
- r - 没有循环的数据帧的复杂过滤
- python - 如何从函数外部调用函数内的变量?
- sybase - Sybase ASE - 列出数据库中的表名、列名、约束名
- html - 响应式四列布局 Flexbox 所需的意见