Differences with torchtext.data.functional.custom_replace
torchtext.data.functional.custom_replace
torchtext.data.functional.custom_replace(replace_pattern)
For more information, see torchtext.data.functional.custom_replace.
mindspore.dataset.text.RegexReplace
class mindspore.dataset.text.RegexReplace(pattern, replace, replace_all=True)
For more information, see mindspore.dataset.text.RegexReplace.
Differences
PyTorch: Replace a part of string with given text according to regular expressions.
MindSpore: Replace a part of string with given text according to regular expressions.
Categories |
Subcategories |
PyTorch |
MindSpore |
Difference |
---|---|---|---|---|
Parameter |
Parameter1 |
replace_pattern |
- |
Regex expression and string to replace stored in tuple |
Parameter2 |
- |
pattern |
Regex expression patterns |
|
Parameter3 |
- |
replace |
String to replace matched element. |
|
Parameter4 |
- |
replace_all |
If only replace first matched element |
Code Example
list_a = ["Sentencepiece encode aS pieces"]
# PyTorch
from torchtext.data.functional import custom_replace
custom_replace_transform = custom_replace([(r'S', 's')])
print(list(custom_replace_transform(list_a)))
# Out: ['sentencepiece encode as pieces']
# MindSpore
import mindspore.dataset.text as text
transform = text.RegexReplace(pattern=r'S', replace='s')
print(transform(list_a))
# Out: ['sentencepiece encode as pieces']