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"]
code: def forward_normalized(
      self, texts: Sequence[str]
  ) -> torch.FloatTensor:  # noqa: D102
      # tokenize
      token_ids = [
          [self.token_to_id.get(c, self.unknown_idx) for c in text]
          for text in texts
      ]
      # pad
      max_length = max(map(len, token_ids))
      indices = torch.full(
          size=(len(texts), max_length), fill_value=self.padding_idx
      )
      for i, ids in enumerate(token_ids):
          indices[i, : len(ids)] = torch.as_tensor(
              ids, dtype=torch.long
          )
      # get character embeddings
      x = self.character_embedding(indices=indices)
      # pool
      x = self.aggregation(x)
      if not torch.is_tensor(x):
          x = x.values
      return x
  
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 2 for calling the CharacterEmbeddingTextEncoder obj's underlying member method code with example usage: obj.forward_normalized(texts) and returns: x