mirror of
https://github.com/dongdongunique/EvoSynth.git
synced 2026-02-12 17:22:44 +00:00
30 lines
908 B
Python
30 lines
908 B
Python
from abc import ABC, abstractmethod
|
||
from typing import Iterator, Any
|
||
|
||
class BaseDataset(ABC):
|
||
"""
|
||
所有数据集的抽象基类。
|
||
确保了无论数据来自文件、数据库还是内存,
|
||
框架都能以统一的方式进行迭代。
|
||
"""
|
||
def __init__(self, **kwargs):
|
||
"""允许在配置文件中传入任意数据集特定的参数。"""
|
||
pass
|
||
|
||
@abstractmethod
|
||
def __iter__(self) -> Iterator[Any]:
|
||
"""
|
||
返回一个迭代器,每次产生一个攻击目标 (例如,一个有害的prompt)。
|
||
这是让数据集能够被 for 循环遍历的关键。
|
||
"""
|
||
pass
|
||
|
||
@abstractmethod
|
||
def __len__(self) -> int:
|
||
"""返回数据集中的样本总数。"""
|
||
pass
|
||
|
||
@abstractmethod
|
||
def __getitem__(self, index: int) -> Any:
|
||
"""支持索引访问数据集中的特定样本。"""
|
||
pass |