Represents full text input. Adds field descriptions. For example, entailment inputs look like: ``` premise: ... hypothesis: ... ```
(self, key_color="bold", key_color_method=None)
| 577 | ] |
| 578 | |
| 579 | def printable_text(self, key_color="bold", key_color_method=None) -> str: |
| 580 | """Represents full text input. Adds field descriptions. |
| 581 | |
| 582 | For example, entailment inputs look like: |
| 583 | ``` |
| 584 | premise: ... |
| 585 | hypothesis: ... |
| 586 | ``` |
| 587 | """ |
| 588 | # For single-sequence inputs, don't show a prefix. |
| 589 | if len(self._text_input) == 1: |
| 590 | return next(iter(self._text_input.values())) |
| 591 | # For multiple-sequence inputs, show a prefix and a colon. Optionally, |
| 592 | # color the key. |
| 593 | else: |
| 594 | if key_color_method: |
| 595 | |
| 596 | def ck(k): |
| 597 | return textattack.shared.utils.color_text( |
| 598 | k, key_color, key_color_method |
| 599 | ) |
| 600 | |
| 601 | else: |
| 602 | |
| 603 | def ck(k): |
| 604 | return k |
| 605 | |
| 606 | return "\n".join( |
| 607 | f"{ck(key.capitalize())}: {value}" |
| 608 | for key, value in self._text_input.items() |
| 609 | ) |
| 610 | |
| 611 | def __repr__(self) -> str: |
| 612 | return f'<AttackedText "{self.text}">' |
no outgoing calls