MCPcopy Create free account
hub / github.com/google-research/language / normalize_text

Function normalize_text

language/decontext/eval_util.py:44–62  ·  view source on GitHub ↗

Lower text and remove punctuation, articles and extra whitespace.

(input_text)

Source from the content-addressed store, hash-verified

42
43
44def normalize_text(input_text):
45 """Lower text and remove punctuation, articles and extra whitespace."""
46
47 def remove_articles(s):
48 return re.sub(r'\b(a|an|the)\b', ' ', s)
49
50 def replace_punctuation(s):
51 to_replace = set(string.punctuation)
52 # TODO(danielandor): Fix annotation tokenization artifacts here as well.
53 return ''.join('' if ch in to_replace else ch for ch in s)
54
55 def white_space_fix(s):
56 return ' '.join(s.split())
57
58 text = input_text.lower()
59 text = replace_punctuation(text)
60 text = remove_articles(text)
61 text = white_space_fix(text)
62 return text
63
64
65_DEFAULT_TEXT_NORMALIZER_FN = normalize_text

Callers

nothing calls this directly

Calls 3

replace_punctuationFunction · 0.85
remove_articlesFunction · 0.70
white_space_fixFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…