"Characters" (Net Decoder)

NetDecoder["Characters"]

represents a decoder that converts a sequence of probability vectors to a string of ASCII characters.

NetDecoder[{"Characters",table}]

represents a decoder that converts probability vectors into a string composed of characters in the list table.

NetDecoder[{"Characters",table,"param"value,}]

represents a decoder in which additional parameters have been specified.

Details

  • NetDecoder[][input] applies the decoder to an input to produce an output.
  • NetDecoder[][{input1,input2,}] applies the decoder to a list of inputs to produce a list of outputs.
  • The input to the decoder input is either a vector of probabilities or a sequence of probability vectors. Each probability vector sums to 1. For NetDecoder["Characters"], the length of each probability vector is the number of ASCII characters, 97. For NetDecoder[{"Characters",table}], the length of each probability vector is the number of characters in table.
  • NetDecoder[][input] returns a string.
  • The mapping from probability vectors to characters specified by table can have the following forms:
  • "c1c2"map each character ci to successive available codes
    "c1c2"nmap all characters ci to code n
    "c1c2"Automaticmap all characters ci to the next available code
    n;;mspecmap 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:
  • Automaticall printable ASCII characters, plus space, tab and newline
    LetterCharacterthe letters a through z and A through Z
    DigitCharacterthe digits 0 through 9
    WordCharacterthe union of LetterCharacter and DigitCharacter
    PunctuationCharacterall visible ASCII punctuation characters
    WhitespaceCharacterspace, tab and newline
    StartOfStringvirtual character that occurs before the beginning of the string
    EndOfStringvirtual character that occurs after the end of the string
    _any otherwise unassigned character
  • NetDecoder["Characters"] is suitable for typical English prose and consists of all printable ASCII characters, as well as tab, space and newline.
  • NetDecoder["Characters"] is equivalent to NetDecoder[{"Characters",{"\t","\n",FromCharacterCode[Range[32,126]]}}].
  • A decoder can be attached to an output port of a net by specifying "port"->NetDecoder[] when constructing the net.
  • NetDecoder[{"Characters",}][["Alphabet"]] produces a list of the characters recognized by the decoder.
  • NetEncoder[NetDecoder[{"Characters",}]] produces a NetEncoder[{"Characters",}] with the same encoding as the given decoder.
  • Properties
  • NetDecoder[][data,prop] can be used to calculate a specific property for the input data.
  • When a "Characters" decoder is attached to a net, net[data,prop] or net[data,"oport"->prop] can be used to calculate a specific property of the decoded output.
  • The "Characters" decoder only supports the bypass property. Setting prop to None bypasses decoding and returns the input to the decoder.

Examples

open allclose all

Basic Examples  (1)

Create a character decoder:

Decode a sequence of probabilities:

Scope  (2)

Create a character decoder:

Create a NumericArray representing a sequence of probability vectors:

Decode the sequence of probabilities:

The decoder maps across a batch of examples:

Create a character decoder:

Decode a sentence from a one-hot vector representation:

Properties & Relations  (2)

Extract the list of characters recognized by the default "Characters" decoder:

Produce a NetEncoder from a NetDecoder: