fastNLP.embeddings.stack_embedding¶
-
class
fastNLP.embeddings.stack_embedding.
StackEmbedding
(embeds: List[fastNLP.embeddings.embedding.TokenEmbedding], word_dropout=0, dropout=0)[源代码]¶ 基类
fastNLP.embeddings.TokenEmbedding
别名
fastNLP.embeddings.StackEmbedding
fastNLP.embeddings.stack_embedding.StackEmbedding
支持将多个embedding集合成一个embedding。
Example:
>>> from fastNLP import Vocabulary >>> from fastNLP.embeddings import StaticEmbedding, StackEmbedding >>> vocab = Vocabulary().add_word_lst("The whether is good .".split()) >>> embed_1 = StaticEmbedding(vocab, model_dir_or_name='en-glove-6b-50d', requires_grad=True) >>> embed_2 = StaticEmbedding(vocab, model_dir_or_name='en-word2vec-300', requires_grad=True) >>> embed = StackEmbedding([embed_1, embed_2])
-
__init__
(embeds: List[fastNLP.embeddings.embedding.TokenEmbedding], word_dropout=0, dropout=0)[源代码]¶ - 参数
embeds -- 一个由若干个TokenEmbedding组成的list,要求每一个TokenEmbedding的词表都保持一致
word_dropout (float) -- 以多大的概率将一个词替换为unk。这样既可以训练unk也是一定的regularize。不同embedidng会在相同的位置 被设置为unknown。如果这里设置了dropout,则组成的embedding就不要再设置dropout了。
dropout (float) -- 以多大的概率对embedding的表示进行Dropout。0.1即随机将10%的值置为0。
-
append
(embed: fastNLP.embeddings.embedding.TokenEmbedding)[源代码]¶ 添加一个embedding到结尾。 :param embed: :return:
-
property
embed_size
¶ 该Embedding输出的vector的最后一维的维度。 :return:
-
forward
(words)[源代码]¶ 得到多个embedding的结果,并把结果按照顺序concat起来。
- 参数
words -- batch_size x max_len
- 返回
返回的shape和当前这个stack embedding中embedding的组成有关
-
training
: bool¶
-