class_docstr: A simple character-based text encoder.
  
  This encoder uses base representations for each character from a given alphabet, as well as two special tokens
  for unknown character and padding. To encoder a sentence, it converts it to a sequence of characters, obtains
  the invidual characters representations and aggregates these representations to a single one.
  
  With :class:`pykeen.nn.representation.Embedding` character representation and :func:`torch.mean` aggregation,
  this encoder is similar to a bag-of-characters model with trainable character embeddings. Therefore, it is
  invariant to the ordering of characters:
  
  >>> from pykeen.nn.text import CharacterEmbeddingTextEncoder
  >>> encoder = CharacterEmbeddingTextEncoder()
  >>> import torch
  >>> torch.allclose(encoder("seal"), encoder("sale"))
  True
class_docstr_tok: ["A","simple","character-based","text","encoder",".","This","encoder","uses","base","representations","for","each","character","from","a","given","alphabet",",","as","well","as","two","special","tokens","for","unknown","character","and","padding",".","To","encoder","a","sentence",",","it","converts","it","to","a","sequence","of","characters",",","obtains","the","invidual","characters","representations","and","aggregates","these","representations","to","a","single","one",".","With",":","class",":","`","pykeen.nn.representation.Embedding","`","character","representation","and",":","func",":","`","torch.mean","`","aggregation",",","this","encoder","is","similar","to","a","bag-of-characters","model","with","trainable","character","embeddings",".","Therefore",",","it","is","invariant","to","the","ordering","of","characters",":",">",">",">","from","pykeen.nn.text","import","CharacterEmbeddingTextEncoder",">",">",">","encoder","=","CharacterEmbeddingTextEncoder","(",")",">",">",">","import","torch",">",">",">","torch.allclose","(","encoder","(","``","seal","''",")",",","encoder","(","``","sale","''",")",")","True"]
docstr: Initialize the encoder.
  
  :param dim: the embedding dimension
  :param character_representation: the character representation or a hint thereof
  :param vocabulary: the vocabulary, i.e., the allowed characters
  :param aggregation: the aggregation to use to pool the character embeddings
docstr_tok: ["Initialize","the","encoder",".",":","param","dim",":","the","embedding","dimension",":","param","character_representation",":","the","character","representation","or","a","hint","thereof",":","param","vocabulary",":","the","vocabulary",",","i.e.",",","the","allowed","characters",":","param","aggregation",":","the","aggregation","to","use","to","pool","the","character","embeddings"]
code: def __init__(
      self,
      dim: int = 32,
      character_representation: HintOrType["Representation"] = None,
      vocabulary: str = string.printable,
      aggregation: Hint[Callable[..., torch.FloatTensor]] = None,
  ) -> None:
      """Initialize the encoder.
  
      :param dim: the embedding dimension
      :param character_representation: the character representation or a hint thereof
      :param vocabulary: the vocabulary, i.e., the allowed characters
      :param aggregation: the aggregation to use to pool the character embeddings
      """
      super().__init__()
      from . import representation_resolver
  
      self.aggregation = aggregation_resolver.make(aggregation, dim=-2)
      self.vocabulary = vocabulary
      self.token_to_id = {c: i for i, c in enumerate(vocabulary)}
      num_real_tokens = len(self.vocabulary)
      self.unknown_idx = num_real_tokens
      self.padding_idx = num_real_tokens + 1
      self.character_embedding = representation_resolver.make(
          character_representation,
          max_id=num_real_tokens + 2,
          shape=dim,
      )
  
imports: import logging
  import string
  from abc import abstractmethod
  from typing import TYPE_CHECKING, Callable, Optional, Sequence, Union
  import torch
  from class_resolver import ClassResolver, Hint, HintOrType
  from class_resolver.contrib.torch import aggregation_resolver
  from more_itertools import chunked
  from torch import nn
  from torch_max_mem import maximize_memory_utilization
  from tqdm.auto import tqdm
  from ..utils import get_preferred_device, resolve_device, upgrade_to_sequence
label_desc: Use image node_id 1 to create a new CharacterEmbeddingTextEncoder object from inherited base classes: TextEncoder with example: obj = CharacterEmbeddingTextEncoder(dim, character_representation, vocabulary, aggregation)