Skip to content

Commit

Permalink
Fix/warning if revlog_history.tsv is empty (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Jul 1, 2023
1 parent a7405e7 commit 1a3e00a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions fsrs4anki_optimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# FSRS4Anki v3.25.8 Optimizer\n",
"# FSRS4Anki v3.25.9 Optimizer\n",
"\n",
"[![open in colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-spaced-repetition/fsrs4anki/blob/v3.25.8/fsrs4anki_optimizer.ipynb)\n",
"[![open in colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-spaced-repetition/fsrs4anki/blob/v3.25.9/fsrs4anki_optimizer.ipynb)\n",
"\n",
"↑ Click the above button to open the optimizer on Google Colab.\n",
"\n",
Expand Down Expand Up @@ -103,7 +103,7 @@
}
],
"source": [
"%pip install -q fsrs4anki_optimizer==3.25.8\n",
"%pip install -q fsrs4anki_optimizer==3.25.9\n",
"# for local development\n",
"# import os\n",
"# import sys\n",
Expand Down
4 changes: 3 additions & 1 deletion package/fsrs4anki_optimizer/fsrs4anki_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def lineToTensor(line: str) -> Tensor:

class RevlogDataset(Dataset):
def __init__(self, dataframe: pd.DataFrame):
if len(dataframe) == 0:
if dataframe.empty:
raise ValueError('Training data is inadequate.')
padded = pad_sequence(dataframe['tensor'].to_list(), batch_first=True, padding_value=0)
self.x_train = padded.int()
Expand Down Expand Up @@ -483,6 +483,8 @@ def train(self, lr: float = 4e-2, n_epoch: int = 3, n_splits: int = 3, batch_siz
"""Step 4"""
self.dataset = pd.read_csv("./revlog_history.tsv", sep='\t', index_col=None, dtype={'r_history': str ,'t_history': str} )
self.dataset = self.dataset[(self.dataset['i'] > 1) & (self.dataset['delta_t'] > 0) & (self.dataset['t_history'].str.count(',0') == 0)]
if self.dataset.empty:
raise ValueError('Training data is inadequate.')
self.dataset['tensor'] = self.dataset.progress_apply(lambda x: lineToTensor(list(zip([x['t_history']], [x['r_history']]))[0]), axis=1)
self.dataset['group'] = self.dataset['r_history'] + self.dataset['t_history']
print("Tensorized!")
Expand Down
2 changes: 1 addition & 1 deletion package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "fsrs4anki_optimizer"
version = "3.25.8"
version = "3.25.9"
readme = "README.md"
dependencies = [
"matplotlib>=3.7.0",
Expand Down

0 comments on commit 1a3e00a

Please sign in to comment.