Comments (4)
The attention module uses both the history_only
parameter and the given mask.
from keras-bert.
Yes, the attention module in the keras_self_attention has parameter mask. But the _attention_builder returned by attention_builder only receives one parameters x (i.e. the parameter inputs in ScaledDotProductAttention) and the parameter mask is None. So only the history_only parameter controls the self-attention mask in transformer encoder.
Below is the code in keras-transformer/keras_transformer/transformer.py
def attention_builder(name,
head_num,
activation,
history_only,
trainable=True):
"""Get multi-head self-attention builder.
:param name: Prefix of names for internal layers.
:param head_num: Number of heads in multi-head self-attention.
:param activation: Activation for multi-head self-attention.
:param history_only: Only use history data.
:param trainable: Whether the layer is trainable.
:return:
"""
def _attention_builder(x):
return MultiHeadAttention(
head_num=head_num,
activation=activation,
history_only=history_only,
trainable=trainable,
name=name,
)(x)
return _attention_builder
from keras-bert.
Note that the second ()
in MultiHeadAttention(...)(x)
calls __call__(...)
but not call(...)
.
from keras-bert.
Oh, god, thand you very much. I have read the <Understanding masking & padding> in the keras docs, and understand the _keras_mask. Thank you again taking time out to answer my questions.
from keras-bert.
Related Issues (20)
- keras-bert load pre model failed in keras 2.2.4, maybe it is a bug
- could you provide an albert loader ? HOT 1
- 如何实现在自己的数据上很少的预训练? HOT 1
- 如何提取长度一致的bert词向量? HOT 1
- Input sentence for extract_embeddings HOT 1
- List index out of range for example code HOT 2
- 在哪里可以找到之前的版本呢? HOT 2
- Keras Bert with character embeddings HOT 1
- API reference list
- which version of keras-bert is compatible for tensorflow 1.13? HOT 2
- 关于显存巨量占用的疑惑 HOT 1
- Improve Tokenizer for uppercase text HOT 1
- Error in getting attention map HOT 3
- Masked LM pre-training HOT 1
- AttributeError: module 'keras' has no attribute 'applications' HOT 5
- module 'tensorflow.compat.v2' has no attribute '__internal__' HOT 1
- load_trained_model_from_checkpoint(config_path,checkpoint_file=checkpoint_path) AttributeError: 'tuple' object has no attribute 'layer'
- load_trained_model_from_checkpoint(config_path,checkpoint_file=checkpoint_path)
- 'adamwarmup' object has no attribute '_set_hyper'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras-bert.