mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2026-09-27 10:05:43 +08:00
[misc] upgrade format to py39 (#7256)
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from collections.abc import Sequence
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Sequence, Tuple
|
||||
|
||||
from ..data import Role
|
||||
from ..extras.constants import CHOICES
|
||||
@@ -25,20 +25,19 @@ class EvalTemplate:
|
||||
choice: str
|
||||
answer: str
|
||||
|
||||
def _parse_example(self, example: Dict[str, str]) -> Tuple[str, str]:
|
||||
r"""
|
||||
def _parse_example(self, example: dict[str, str]) -> tuple[str, str]:
|
||||
r"""Parse eval example.
|
||||
|
||||
input: a dict with keys {"question", "A", "B", "C", "D", "answer"}
|
||||
output: a tuple of (prompt, response)
|
||||
output: a tuple of (prompt, response).
|
||||
"""
|
||||
candidates = [self.choice.format(choice=ch, content=example[ch]) for ch in CHOICES if ch in example]
|
||||
return "".join([example["question"]] + candidates + [self.answer]), example["answer"]
|
||||
|
||||
def format_example(
|
||||
self, target_data: Dict[str, str], support_set: Sequence[Dict[str, str]], subject_name: str
|
||||
) -> List[Dict[str, str]]:
|
||||
r"""
|
||||
Converts dataset examples to messages.
|
||||
"""
|
||||
self, target_data: dict[str, str], support_set: Sequence[dict[str, str]], subject_name: str
|
||||
) -> list[dict[str, str]]:
|
||||
r"""Convert dataset examples to messages."""
|
||||
messages = []
|
||||
for k in range(len(support_set)):
|
||||
prompt, response = self._parse_example(support_set[k])
|
||||
@@ -52,7 +51,7 @@ class EvalTemplate:
|
||||
return messages
|
||||
|
||||
|
||||
eval_templates: Dict[str, "EvalTemplate"] = {}
|
||||
eval_templates: dict[str, "EvalTemplate"] = {}
|
||||
|
||||
|
||||
def _register_eval_template(name: str, system: str, choice: str, answer: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user