(self, doc)
| 1013 | return doc |
| 1014 | |
| 1015 | def doc_to_text(self, doc): |
| 1016 | if self.prompt is not None: |
| 1017 | doc_to_text = self.prompt |
| 1018 | else: |
| 1019 | doc_to_text = self.config.doc_to_text |
| 1020 | |
| 1021 | if isinstance(doc_to_text, int): |
| 1022 | return doc_to_text |
| 1023 | elif isinstance(doc_to_text, str): |
| 1024 | if doc_to_text in self.features: |
| 1025 | # if self.config.doc_to_choice is not None: |
| 1026 | # return self.doc_to_choice(doc)[doc[doc_to_text]] |
| 1027 | # else: |
| 1028 | return doc[doc_to_text] |
| 1029 | else: |
| 1030 | text_string = utils.apply_template(doc_to_text, doc) |
| 1031 | if text_string.isdigit() and self._config.doc_to_choice is not None: |
| 1032 | return ast.literal_eval(text_string) |
| 1033 | else: |
| 1034 | return text_string |
| 1035 | elif callable(doc_to_text): |
| 1036 | return doc_to_text(doc) |
| 1037 | # Used when applying a Promptsource template |
| 1038 | elif hasattr(doc_to_text, "apply"): |
| 1039 | applied_prompt = doc_to_text.apply(doc) |
| 1040 | if len(applied_prompt) == 2: |
| 1041 | return applied_prompt[0] |
| 1042 | else: |
| 1043 | eval_logger.warning("Applied prompt returns empty string") |
| 1044 | return self.config.fewshot_delimiter |
| 1045 | else: |
| 1046 | print(type(doc_to_text)) |
| 1047 | raise TypeError |
| 1048 | |
| 1049 | def doc_to_target(self, doc: dict) -> Union[int, str, list]: |
| 1050 | if self.prompt is not None: |
no test coverage detected