lab1/text_recognizer/data/util.py
def convert_strings_to_labels(strings: Sequence[str], mapping: Dict[str, int], length: int) -> torch.Tensor:
    """
    Convert sequence of N strings to a (N, length) ndarray, with each string wrapped with <S> and <E> tokens,
    and padded with the <P> token.
    """
    labels = torch.ones((len(strings), length), dtype=torch.long) * mapping["<P>"]
    for i, string in enumerate(strings):
        tokens = list(string)
        tokens = ["<S>", *tokens, "<E>"]
        for ii, token in enumerate(tokens):
            labels[i, ii] = mapping[token]
    return labels

    Convert sequence of N strings to a (N, length) ndarray, with each string wrapped with <S> and <E> tokens,
    and padded with the <P> token.
    
Convert sequence of N strings to a (N, length) ndarray, with each string wrapped with  and  tokens,
and padded with the  token.
Convert sequence of N strings to a ( N length ) ndarray with each string wrapped with and tokens and padded with the token .
def convert_strings_to_labels(strings: Sequence[str], mapping: Dict[str, int], length: int) -> torch.Tensor:
    labels = torch.ones((len(strings), length), dtype=torch.long) * mapping["<P>"]
    for i, string in enumerate(strings):
        tokens = list(string)
        tokens = ["<S>", *tokens, "<E>"]
        for ii, token in enumerate(tokens):
            labels[i, ii] = mapping[token]
    return labels
def convert_strings_to_labels ( strings : Sequence [ str ] , mapping : Dict [ str , int ] , length : int ) -> torch . Tensor : labels = torch . ones ( ( len ( strings ) , length ) , dtype = torch . long ) * mapping [ "<P>" ] for i , string in enumerate ( strings ) : tokens = list ( string ) tokens = [ "<S>" , * tokens , "<E>" ] for ii , token in enumerate ( tokens ) : labels [ i , ii ] = mapping [ token ] return labels
Convert sequence of N strings to a (N, length) ndarray, with each string wrapped with <S> and <E> tokens,
and padded with the <P> token.
Convert sequence of N strings to a ( N length ) ndarray with each string wrapped with <S > and <E > tokens and padded with the <P > token .
"""
    Convert sequence of N strings to a (N, length) ndarray, with each string wrapped with <S> and <E> tokens,
    and padded with the <P> token.
    """
strings
Sequence[str]
mapping
Dict[str, int]
length
int