API Reference
Transformers.HuggingFace.HGFConfig
Transformers.Layers.ApplyEmbed
Transformers.Layers.CrossAttention
Transformers.Layers.CrossAttention
Transformers.Layers.Embed
Transformers.Layers.EmbedDecoder
Transformers.Layers.FixedLenPositionEmbed
Transformers.Layers.Fork
Transformers.Layers.NSplit
Transformers.Layers.PostNormTransformerBlock
Transformers.Layers.PostNormTransformerDecoderBlock
Transformers.Layers.PreNormTransformerBlock
Transformers.Layers.PreNormTransformerDecoderBlock
Transformers.Layers.SelfAttention
Transformers.Layers.SelfAttention
Transformers.Layers.SinCosPositionEmbed
Transformers.Layers.Transformer
Transformers.Layers.TransformerBlock
Transformers.Layers.TransformerDecoderBlock
Transformers.TextEncoders.TrfTextEncoder
Transformers.TextEncoders.TrfTextEncoder
Flux.Losses.crossentropy
Flux.Losses.logitcrossentropy
Transformers.HuggingFace.get_model_type
Transformers.HuggingFace.get_state_dict
Transformers.HuggingFace.load_config
Transformers.HuggingFace.load_config
Transformers.HuggingFace.load_hgf_pretrained
Transformers.HuggingFace.load_model
Transformers.HuggingFace.load_model
Transformers.HuggingFace.load_state_dict
Transformers.HuggingFace.load_tokenizer
Transformers.HuggingFace.save_config
Transformers.HuggingFace.save_model
Transformers.HuggingFace.state_dict_to_namedtuple
Transformers.Layers.no_dropout
Transformers.Layers.set_dropout
Transformers.Layers.testmode
Transformers.TextEncoders.bert_cased_tokenizer
Transformers.TextEncoders.bert_uncased_tokenizer
Transformers.TextEncoders.gpt_tokenizer
Transformers.TextEncoders.set_annotate
Transformers.TextEncoders.set_config
Transformers.TextEncoders.set_decode
Transformers.TextEncoders.set_onehot
Transformers.TextEncoders.set_process
Transformers.TextEncoders.set_textprocess
Transformers.TextEncoders.set_tokenizer
Transformers.TextEncoders.set_vocab
Transformers.TextEncoders.text_standardize
Transformers.enable_gpu
Transformers.enable_gpu
Transformers.firsttoken
Transformers.firsttoken
Transformers.lasttoken
Transformers.lasttoken
Transformers.lengthselect
Transformers.safe_crossentropy
Transformers.safe_logitcrossentropy
Transformers.skipboundarytoken
Transformers.skipfirsttoken
Transformers.skiplasttoken
Transformers.todevice
Transformers.todevice
Transformers.togpudevice
Transformers.togpudevice
Transformers.unsafe_crossentropy
Transformers.unsafe_logitcrossentropy
Transformers.HuggingFace.@hgf_str
Flux.Losses.crossentropy
— Methodcrossentropy(ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask; ϵ)
crossentropy(sum, ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask; ϵ)
Flux.crossentropy
with an extra sequence mask for masking out non-needed token loss. y
is the labels. By default it take the mean by dividing the number of valid tokens. This can be change to simply sum the valid losses by add the first argument sum
. See also safe_crossentropy
Flux.Losses.logitcrossentropy
— Methodlogitcrossentropy(ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask)
logitcrossentropy(sum, ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask)
Flux.logitcrossentropy
with an extra sequence mask for masking out non-needed token loss. y
is the labels. By default it take the mean by dividing the number of valid tokens. This can be change to simply sum the valid losses by add the first argument sum
. See also safe_logitcrossentropy
Transformers.enable_gpu
— Functionenable_gpu(t=true)
Enable gpu for todevice
, disable with enable_gpu(false)
. The backend is selected by Flux.gpu_backend!
. Should only be used in user scripts.
Transformers.firsttoken
— Methodfirsttoken(x, m::AbstractSeqMask)
Slice the first token from the hidden states. The "first" token is defined by the sequence mask.
Transformers.firsttoken
— Methodfirsttoken(x)
Slice the first tokens from the hidden states, normally equivalent to x[:, begin, :]
.
See also: lengthselect
, skipboundarytoken
Transformers.lasttoken
— Methodlasttoken(x, m::AbstractSeqMask)
Slice the last token from the hidden states. The "last" token is defined by the sequence mask.
Transformers.lasttoken
— Methodlasttoken(x)
Slice the first tokens from the hidden states, normally equivalent to x[:, end, :]
.
See also: lengthselect
, skipboundarytoken
Transformers.lengthselect
— Methodlengthselect(x, i)
selectdim
on the "length" dimension (2 for most array and 1 for integer array).
Transformers.safe_crossentropy
— Methodsafe_crossentropy(ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask; ϵ)
safe_crossentropy(sum, ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask; ϵ)
crossentropy
. If the label y
is an integer array, then it would also call maximum
on the label to make sure no label number is large then the first dimension of ŷ
. See also unsafe_crossentropy
.
Transformers.safe_logitcrossentropy
— Methodsafe_logitcrossentropy(ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask)
safe_logitcrossentropy(sum, ŷ::AbstractArray, y::AbstractArray, m::AbstractSeqMask)
logitcrossentropy
. If the label y
is an integer array, then it would also call maximum
on the label to make sure no label number is large then the first dimension of ŷ
. See also unsafe_logitcrossentropy
.
Transformers.skipboundarytoken
— Methodskipboundarytoken(x; first=1, last=1)
Select (lengthselect
) the non-boundary tokens from the hidden states, normally equivalent to x[:, begin+first:end-last, :]
.
See also: lengthselect
Transformers.skipfirsttoken
— Methodskipfirsttoken(x)
Slice the non-first tokens from the hidden states, normally equivalent to x[:, 2:end, :]
.
See also: lengthselect
, skipboundarytoken
, skiplasttoken
Transformers.skiplasttoken
— Methodskiplasttoken(x)
Slice the non-last tokens from the hidden states, normally equivalent to x[:, 1:end-1, :]
.
See also: lengthselect
, skipboundarytoken
, skipfirsttoken
Transformers.todevice
— Methodtodevice(x)
Move data to device, only when gpu is enable with enable_gpu
, basically equal Flux.gpu
. Otherwise just Flux.cpu
.
Transformers.togpudevice
— Methodtogpudevice(x)
Move data to gpu device, backend selected by Flux.gpu_backend!
.
Transformers.unsafe_crossentropy
— Methodunsafe_crossentropy(ŷ::AbstractArray, y::AbstractArray{<:Integer}, m::AbstractSeqMask; ϵ)
unsafe_crossentropy(sum, ŷ::AbstractArray, y::AbstractArray{<:Integer}, m::AbstractSeqMask; ϵ)
Compute crossentropy
with integer labels. The prefix "unsafe" means that if y
contain any number larger than the first dimension of ŷ
, the behavior is undefined. See also safe_crossentropy
.
Transformers.unsafe_logitcrossentropy
— Methodunsafe_logitcrossentropy(ŷ::AbstractArray, y::AbstractArray{<:Integer}, m::AbstractSeqMask)
unsafe_logitcrossentropy(sum, ŷ::AbstractArray, y::AbstractArray{<:Integer}, m::AbstractSeqMask)
Compute logitcrossentropy
with integer labels. The prefix "unsafe" means that if y
contain any number larger than the first dimension of ŷ
, the behavior is undefined. See also safe_logitcrossentropy
.