(self, text)
return torch.LongTensor(text)
对target_label做编码和对齐
        对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐
        Args:
            text (str or list of str): texts to convert.

        Returns:
            torch.IntTensor targets:max_length × batch_size
对target_label做编码和对齐
        对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐
        Args:
            text (str or list of str): texts to convert.
对target_label做编码和对齐 对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐 Args : text ( str or list of str ) : texts to convert .
def encode(self, text):
        """对target_label做编码和对齐
        对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐
        Args:
            text (str or list of str): texts to convert.

        Returns:
            torch.IntTensor targets:max_length × batch_size
        """
        if isinstance(text, unicode):
            text = [self.dict[item] for item in text]
        elif isinstance(text, collections.Iterable):
            text = [self.encode(s) for s in text]           # 编码

            max_length = max([len(x) for x in text])        # 对齐
            nb = len(text)
            targets = torch.ones(nb, max_length + 2) * 2              # use ‘blank’ for pading
            for i in range(nb):
                targets[i][0] = 0                           # 开始
                targets[i][1:len(text[i]) + 1] = text[i]
                targets[i][len(text[i]) + 1] = 1
            text = targets.transpose(0, 1).contiguous()
            text = text.long()
        return torch.LongTensor(text)
def encode ( self , text ) : if isinstance ( text , unicode ) : text = [ self . dict [ item ] for item in text ] elif isinstance ( text , collections . Iterable ) : text = [ self . encode ( s ) for s in text ] # 编码 max_length = max ( [ len ( x ) for x in text ] ) # 对齐 nb = len ( text ) targets = torch . ones ( nb , max_length + 2 ) * 2 # use ‘blank’ for pading for i in range ( nb ) : targets [ i ] [ 0 ] = 0 # 开始 targets [ i ] [ 1 : len ( text [ i ] ) + 1 ] = text [ i ] targets [ i ] [ len ( text [ i ] ) + 1 ] = 1 text = targets . transpose ( 0 , 1 ) . contiguous ( ) text = text . long ( ) return torch . LongTensor ( text )