StringProcessor
StringProcessor ¶
An interface class used to process the model's output before evaluation.
Typically used in Metric
.
Source code in flexeval/core/string_processor/base.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
__call__
abstractmethod
¶
__call__(text: str) -> str
Process the input text.
Parameters:
-
text
(str
) –The text to process.
Source code in flexeval/core/string_processor/base.py
9 10 11 12 13 14 15 16 17 |
|
AIONormalizer ¶
StringProcessor used for AI王 (AI king) question answering task. This is adapted from the official script.
Examples:
>>> from flexeval import AIONormalizer
>>> processor = AIONormalizer()
>>> text = "「蛹化(ようか)」"
>>> normalized_text = processor(text)
>>> print(normalized_text)
蛹化
Source code in flexeval/core/string_processor/aio.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
__call__ ¶
__call__(text: str) -> str
Source code in flexeval/core/string_processor/aio.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
LastLineExtractor ¶
Extract the last line from a string.
Examples:
>>> from flexeval import LastLineExtractor
>>> processor = LastLineExtractor()
>>> text = "Answer\nFUJI-YAMA"
>>> print(processor(text))
FUJI-YAMA
Source code in flexeval/core/string_processor/last_line.py
4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
__call__ ¶
__call__(text: str) -> str
Source code in flexeval/core/string_processor/last_line.py
15 16 |
|
StringLower ¶
This processor returns a lowercased string.
Examples:
>>> from flexeval import StringLower
>>> processor = StringLower()
>>> text = "ABCDefg"
>>> normalized_text = processor(text)
>>> print(normalized_text)
abcdefg
Source code in flexeval/core/string_processor/lower.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
__call__ ¶
__call__(text: str) -> str
Source code in flexeval/core/string_processor/lower.py
16 17 |
|
NFKCNormalizer ¶
This processor returns a NFKC normalized string.
Examples:
>>> from flexeval import NFKCNormalizer
>>> processor = NFKCNormalizer()
>>> text = "0123ABC"
>>> normalized_text = processor(text)
>>> print(normalized_text)
0123ABC
Source code in flexeval/core/string_processor/nfkc.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
__call__ ¶
__call__(text: str) -> str
Source code in flexeval/core/string_processor/nfkc.py
18 19 |
|
RegexExtractor ¶
StringProcessor that extracts the last match of a regex pattern. Useful to extract an answer after a step-by-step derivation.
Parameters:
-
pattern
(str
) –The regex pattern to extract.
Examples:
>>> from flexeval import RegexExtractor
>>> processor = RegexExtractor(r"Answer: (.*)")
>>> text = "Step 1: 3 + 2 = 5\nStep 2: 5 × 4 = 20\nAnswer: 20"
>>> print(processor(text))
20
Source code in flexeval/core/string_processor/regex.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
__init__ ¶
__init__(pattern: str) -> None
Source code in flexeval/core/string_processor/regex.py
22 23 |
|
__call__ ¶
__call__(text: str) -> str
Source code in flexeval/core/string_processor/regex.py
25 26 27 28 29 |
|
StringStrip ¶
Strip leading and trailing whitespaces from a string.
Examples:
>>> from flexeval import StringStrip
>>> processor = StringStrip()
>>> text = " ABC"
>>> normalized_text = processor(text)
>>> print(normalized_text)
ABC
Source code in flexeval/core/string_processor/string_strip.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
__call__ ¶
__call__(text: str) -> str
Source code in flexeval/core/string_processor/string_strip.py
16 17 |
|
TemplateRenderer ¶
Render a jinja2 template with a given string
Examples:
>>> from flexeval import TemplateRenderer
>>> processor = TemplateRenderer("This is a {{text}}")
>>> text = "ABC"
>>> normalized_text = processor(text)
>>> print(normalized_text)
This is a ABC
Source code in flexeval/core/string_processor/template.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
__init__ ¶
__init__(template: str) -> None
Source code in flexeval/core/string_processor/template.py
18 19 |
|
__call__ ¶
__call__(text: str) -> str
Source code in flexeval/core/string_processor/template.py
21 22 |
|