mindspore.dataset.text.UnicodeScriptTokenizer

class mindspore.dataset.text.UnicodeScriptTokenizer(keep_whitespace=False, with_offsets=False)[源代码]

使用UnicodeScript分词器对UTF-8编码的字符串进行分词。

说明

Windows平台尚不支持 UnicodeScriptTokenizer

参数:
  • keep_whitespace (bool, 可选) - 是否输出空白标记(token)。默认值:False。

  • with_offsets (bool, 可选) - 是否输出标记(token)的偏移量。默认值:False。

异常:
  • TypeError - 参数 keep_whitespace 的类型不为bool。

  • TypeError - 参数 with_offsets 的类型不为bool。

支持平台:

CPU

样例:

>>> import mindspore.dataset.text as text
>>> # If with_offsets=False, default output one column {["text", dtype=str]}
>>> tokenizer_op = text.UnicodeScriptTokenizer(keep_whitespace=True, with_offsets=False)
>>> text_file_dataset = text_file_dataset.map(operations=tokenizer_op)
>>> # If with_offsets=True, then output three columns {["token", dtype=str],
>>> #                                                  ["offsets_start", dtype=uint32],
>>> #                                                  ["offsets_limit", dtype=uint32]}
>>> tokenizer_op = text.UnicodeScriptTokenizer(keep_whitespace=True, with_offsets=True)
>>> text_file_dataset = text_file_dataset.map(operations=tokenizer_op, input_columns=["text"],
...                                           output_columns=["token", "offsets_start", "offsets_limit"])