scient
scient一个用python实现科学计算相关算法的包,包括自然语言、图像、神经网络、优化算法、机器学习、图计算等模块。
scient源码和编译安装包可以在Python package index
获取。
The source code and binary installers for the latest released version are available at the [Python package index].
https://pypi.org/project/scient
可以用pip
安装scient
。
You can install scient
like this:
pip install scient
也可以用setup.py
安装。
Or in the scient
directory, execute:
python setup.py install
scient.neuralnet
神经网络相关算法模块,包括attention、transformer、bert、lstm、resnet、crf、dataset、fit等。
scient.neuralnet.transformer
实现了多个Transformer模型,包括Transformer、T5Transformer、ViTransformer、DecodeTransformer、Encoder、Decoder。
scient.neuralnet.transformer.T5Transformer(vocab_size: int, seq_len: int = 512, embed_size: int = 768,
n_head: int = 12, n_encode_layer: int = 12, n_decode_layer: int = 12, n_bucket: int = 32,
max_dist: int = 128, norm_first: bool = True, bias: bool = False, attn_scale: bool = False,
**kwargs)
Parameters
- vocab_size : int
字典规模. - seq_len : int, optional
序列长度. The default is 512. - embed_size : int, optional
embedding向量长度. The default is 768. - n_head : int, optional
multi_head_attention的head数量. The default is 12. - n_encode_layer : int, optional
编码层数. The default is 12. - n_decode_layer : int, optional
解码层数. The default is 12. - n_bucket : int, optional
multi_head_attention中相对位置编码的分桶数量. The default is 32. - max_dist : int, optional
multi_head_attention中相对位置编码的最大距离. The default is 128. - norm_first : bool, optional
在每一个编码/解码层中是否先进行Batch Normalization. The default is True. - bias : bool, optional
模型中的参数是否bias. The default is False. - attn_scale : bool, optional
multi_head_attention中是否需要对注意力矩阵进行scale. The default is False. - kwargs : 其它参数,kwargs中的参数将被传递到Encoder层和Decoder层。
Algorithms
T5采用了相对位置分桶(relative_position_bucket)的方式来处理位置编码。
在双向注意力的Encoder阶段,相对位置分桶的公式为:
在单向注意力的Decoder阶段,相对位置分桶的公式为:
式中的 n b