paddlenlp/transformers/chinesebert/tokenizer.py
def pinyin_locs_map(self, text):
        """
        Get the map of pinyin locations and pinyin tensor.

        Args:
            text (str):
                The sequence to be processed.
 
        Returns:
            dict: the map of pinyin locations and pinyin tensor.
        """
        pinyin = try_import("pypinyin.pinyin")
        Style = try_import("pypinyin.Style")
        pinyin_list = pinyin(
            text,
            style=Style.TONE3,
            heteronym=True,
            errors=lambda x: [["not chinese"] for _ in x], )
        pinyin_locs = {}
        # get pinyin of each location
        for index, item in enumerate(pinyin_list):
            pinyin_string = item[0]
            # not a Chinese character, pass
            if pinyin_string == "not chinese":
                continue
            if pinyin_string in self.pinyin2tensor:
                pinyin_locs[index] = self.pinyin2tensor[pinyin_string]
            else:
                ids = [0] * 8
                for i, p in enumerate(pinyin_string):
                    if p not in self.pinyin_dict["char2idx"]:
                        ids = [0] * 8
                        break
                    ids[i] = self.pinyin_dict["char2idx"][p]
                pinyin_locs[index] = ids
        return pinyin_locs

        Get the map of pinyin locations and pinyin tensor.

        Args:
            text (str):
                The sequence to be processed.
 
        Returns:
            dict: the map of pinyin locations and pinyin tensor.
        
Get the map of pinyin locations and pinyin tensor.
Get the map of pinyin locations and pinyin tensor .
def pinyin_locs_map(self, text):
        pinyin = try_import("pypinyin.pinyin")
        Style = try_import("pypinyin.Style")
        pinyin_list = pinyin(
            text,
            style=Style.TONE3,
            heteronym=True,
            errors=lambda x: [["not chinese"] for _ in x], )
        pinyin_locs = {}
        for index, item in enumerate(pinyin_list):
            pinyin_string = item[0]
            if pinyin_string == "not chinese":
                continue
            if pinyin_string in self.pinyin2tensor:
                pinyin_locs[index] = self.pinyin2tensor[pinyin_string]
            else:
                ids = [0] * 8
                for i, p in enumerate(pinyin_string):
                    if p not in self.pinyin_dict["char2idx"]:
                        ids = [0] * 8
                        break
                    ids[i] = self.pinyin_dict["char2idx"][p]
                pinyin_locs[index] = ids
        return pinyin_locs
def pinyin_locs_map ( self , text ) : pinyin = try_import ( "pypinyin.pinyin" ) Style = try_import ( "pypinyin.Style" ) pinyin_list = pinyin ( text , style = Style . TONE3 , heteronym = True , errors = lambda x : [ [ "not chinese" ] for _ in x ] , ) pinyin_locs = { } for index , item in enumerate ( pinyin_list ) : pinyin_string = item [ 0 ] if pinyin_string == "not chinese" : continue if pinyin_string in self . pinyin2tensor : pinyin_locs [ index ] = self . pinyin2tensor [ pinyin_string ] else : ids = [ 0 ] * 8 for i , p in enumerate ( pinyin_string ) : if p not in self . pinyin_dict [ "char2idx" ] : ids = [ 0 ] * 8 break ids [ i ] = self . pinyin_dict [ "char2idx" ] [ p ] pinyin_locs [ index ] = ids return pinyin_locs
Get the map of pinyin locations and pinyin tensor.
Get the map of pinyin locations and pinyin tensor .
"""
        Get the map of pinyin locations and pinyin tensor.

        Args:
            text (str):
                The sequence to be processed.
 
        Returns:
            dict: the map of pinyin locations and pinyin tensor.
        """ # get pinyin of each location
 # not a Chinese character, pass

the map of pinyin locations and pinyin tensor.
the map of pinyin locations and pinyin tensor .
dict
self
text
The sequence to be processed.
The sequence to be processed .