Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions chebai/preprocessing/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(
inner_k_folds: int = -1, # use inner cross-validation if > 1
fold_index: Optional[int] = None,
base_dir: Optional[str] = None,
n_token_limit: Optional[int] = None,
**kwargs,
):
super().__init__()
Expand Down Expand Up @@ -110,6 +111,7 @@ def __init__(
), "fold_index can't be larger than the total number of folds"
self.fold_index = fold_index
self._base_dir = base_dir
self.n_token_limit = n_token_limit
os.makedirs(self.raw_dir, exist_ok=True)
os.makedirs(self.processed_dir, exist_ok=True)
if self.use_inner_cross_validation:
Expand Down Expand Up @@ -311,8 +313,14 @@ def _load_data_from_file(self, path: str) -> List[Dict[str, Any]]:
for d in tqdm.tqdm(self._load_dict(path), total=lines)
if d["features"] is not None
]
# filter for missing features in resulting data
data = [val for val in data if val["features"] is not None]
# filter for missing features in resulting data, keep features length below token limit
data = [
val
for val in data
if val["features"] is not None
and self.n_token_limit is None
or len(val["features"]) <= self.n_token_limit
]

return data

Expand Down Expand Up @@ -1181,4 +1189,6 @@ def processed_file_names_dict(self) -> dict:
dict: A dictionary mapping dataset keys to their respective file names.
For example, {"data": "data.pt"}.
"""
if self.n_token_limit is not None:
return {"data": f"data_maxlen{self.n_token_limit}.pt"}
return {"data": "data.pt"}