NetEncoder
NetEncoder[type]
represents an encoder that takes a given type of input and encodes it as a tensor for use in a net.
Details
- A NetEncoder object can be attached to an input port of a net by specifying "port"->NetEncoder[…] when constructing the net. Specifying "port"->"type" will create an encoder using NetEncoder["type"] and attach it.
- Possible types include:
-
"Scalar" a single numeric value "Image" any image {"Image",s} image encoded with width and height s {"Image",{w,h}} image encoded with width w and height h {"Image",opts} image with specified encoding options {"Class",{c1,c2,…}} classes ci encoded as codes i "Boolean" True and False encoded as 1 and 0 {"Function",f,dims} apply f to produce a tensor of given dimensions - Possible types for encoding sequences include:
-
"Characters" printable ASCII string encoded as integers {"Characters","c1c2…"} characters ci of string encoded as codes i "Tokens" encode common English words in string as integers {"Tokens",{"t1","t2",…}} tokens ti within input string encoded as codes i - For the types "Class", "Characters" and "Tokens", the form of output for the discrete codes can be specified by NetEncoder[{"type",spec,form}]. Settings for form are:
-
"Index" code i represented by integer i (default) "UnitVector" code i represented by the i
unit vector - NetEncoder[…][input] gives the specified encoding for input.
- NetEncoder[…][{input1,input2, …}] explicitly computes outputs for each of the inputi.
- In NetEncoder[{"Image",opts}], possible options to specify how an image should be converted before encoding include:
-
"ImageSize" Automatic image size to use for encoding "ColorChannels" Automatic color channels to use for encoding "ColorSpace" "RGB" color space to use for encoding "MeanImage" None mean image to subtract "VarianceImage" None variance image to normalize by - The following settings can be used for "MeanImage" and "VarianceImage":
-
None do not subtract anything m value to subtract from each channel of each pixel {m1,m2,…} values to be subtracted from different channels Image[…] overall image to subtract - Pixels are normalized to the range 0, 1 before doing subtraction.
- NetEncoder[{"Function",f,{d1,d2,…,dn}] can be used to define a custom encoding, such that an arbitrary function f is applied to each input and produces a tensor of dimensions d1×d2×…×dn.
- In NetEncoder[{"Characters",table}], the mapping from characters to codes is specified by table, which can have the following forms:
-
"c1c2…" map each character ci to successive available codes "c1c2…"n map all characters ci to code n "c1c2…"Automatic map all characters ci to the next available code n;;mspec map characters between n and m to spec {spec1,spec2,…} assign codes in sequence from the speci - The following symbolic character groups can be used in the table:
-
Automatic all printable ASCII characters, plus space, tab and newline LetterCharacter the letters a through z and A through Z DigitCharacter the digits 0 through 9 WordCharacter the union of LetterCharacter and DigitCharacter PunctuationCharacter all visible ASCII punctuation characters WhitespaceCharacter space, tab and newline StartOfString virtual character that occurs before the beginning of the string EndOfString virtual character that occurs after the end of the string _ any otherwise unassigned character - NetEncoder[{"Characters",spec,IgnoreCase->c}] specifies whether uppercase and lowercase letters are considered equivalent. Default is IgnoreCaseFalse.
- NetEncoder[{"Tokens",spec,IgnoreCase->c}] specifies whether uppercase and lowercase tokens are considered equivalent. Default is IgnoreCaseFalse.
- NetEncoder["Characters"] is suitable for typical English prose and consists of all printable ASCII characters, as well as tab, space and newline.
- NetEncoder[{"Tokens",{"t1","t2",…}}] uses the string pattern WordBoundary to tokenize the input string and recognizes the tokens "ti" in the resulting list.
- NetEncoder[{"Tokens", "language"}] effectively uses WordList["language"] to produce a list of common words for the given language.
- NetEncoder["Tokens"] uses a list of common English words.
- When NetTrain is allowed to automatically attach a loss layer and a NetDecoder is attached to the output of the net, a NetEncoder of the same type will be created for the "Target" input of the loss layer.
- NetEncoder[NetDecoder[…]] will create an encoder based on the parameters of an existing decoder.
Examples
open allclose allBasic Examples (6)
Scope (12)
Generalizations & Extensions (1)
Properties & Relations (2)
See Also
Related Guides
Introduced in 2016
(11.0)
| Updated in 2017 (11.1)