(
    n: int,
    max_chars: int,
    lower: bool,
)
return Model(
        "texts_to_char_ngrams",
        forward,
        attrs={"n": n, "max_chars": max_chars, "lower": lower},
    )
Custom data type transfer thinc layer that transforms a sequence of text strings
    into a sequence of sequence of character ngram strings. Like this::

        ["a short text.", "another text."] => [["a ", " s", "sh", "ho", ...], ...]

    Args:
        n: Number of adjacent characters to combine into an ngram.
        max_chars: Max number of characters from the start of the text to transform
            into character ngrams.
        lower: If True, lowercase text before extracting character ngrams; otherwise,
            leave text casing as-is.
Custom data type transfer thinc layer that transforms a sequence of text strings
    into a sequence of sequence of character ngram strings. Like this::
Custom data type transfer thinc layer that transforms a sequence of text strings into a sequence of sequence of character ngram strings . Like this ::
def text_to_char_ngrams(
    n: int,
    max_chars: int,
    lower: bool,
) -> Model[List[str], List[List[str]]]:
    """
    Custom data type transfer thinc layer that transforms a sequence of text strings
    into a sequence of sequence of character ngram strings. Like this::

        ["a short text.", "another text."] => [["a ", " s", "sh", "ho", ...], ...]

    Args:
        n: Number of adjacent characters to combine into an ngram.
        max_chars: Max number of characters from the start of the text to transform
            into character ngrams.
        lower: If True, lowercase text before extracting character ngrams; otherwise,
            leave text casing as-is.
    """

    def forward(
        model: Model, texts: List[str], is_train: bool
    ) -> Tuple[List[List[str]], Callable]:
        if lower is True:
            texts = (text[:max_chars].lower() for text in texts)
        else:
            texts = (text[:max_chars] for text in texts)
        if n == 1:
            char_ngs = [list(text) for text in texts]
        else:
            char_ngs = [
                [text[i : i + n] for i in range(len(text) - n + 1)]
                for text in texts
            ]

        def backprop(dY):
            return []

        return (char_ngs, backprop)

    return Model(
        "texts_to_char_ngrams",
        forward,
        attrs={"n": n, "max_chars": max_chars, "lower": lower},
    )
def text_to_char_ngrams ( n : int , max_chars : int , lower : bool , ) -> Model [ List [ str ] , List [ List [ str ] ] ] : def forward ( model : Model , texts : List [ str ] , is_train : bool ) -> Tuple [ List [ List [ str ] ] , Callable ] : if lower is True : texts = ( text [ : max_chars ] . lower ( ) for text in texts ) else : texts = ( text [ : max_chars ] for text in texts ) if n == 1 : char_ngs = [ list ( text ) for text in texts ] else : char_ngs = [ [ text [ i : i + n ] for i in range ( len ( text ) - n + 1 ) ] for text in texts ] def backprop ( dY ) : return [ ] return ( char_ngs , backprop ) return Model ( "texts_to_char_ngrams" , forward , attrs = { "n" : n , "max_chars" : max_chars , "lower" : lower } , )