Skip to content

Commit

Permalink
Revert "tensorboard dir tweaks"
Browse files Browse the repository at this point in the history
This reverts commit 5393336.
  • Loading branch information
awarebayes committed Aug 7, 2020
1 parent 51976d2 commit b76b42f
Show file tree
Hide file tree
Showing 17 changed files with 443 additions and 220 deletions.
143 changes: 111 additions & 32 deletions examples/1. Vanilla RL/2. DDPG.ipynb

Large diffs are not rendered by default.

162 changes: 104 additions & 58 deletions examples/1. Vanilla RL/3. TD3.ipynb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions examples/1. Vanilla RL/4. SAC.ipynb
Expand Up @@ -31,7 +31,6 @@
"import numpy as np\n",
"import pandas as pd\n",
"from tqdm.auto import tqdm\n",
"from datetime import datetime\n",
"\n",
"import torch\n",
"import torch.nn as nn\n",
Expand Down Expand Up @@ -420,7 +419,7 @@
" 'test': {'value': [], 'softq': [], 'policy': [], 'step': []}\n",
" }\n",
"\n",
"writer = SummaryWriter(log_dir='../../runs/SAC' + datetime.now().strftime(\"%H_%M\") + \"/\")\n",
"writer = SummaryWriter(log_dir='../../runs')\n",
"debugger = recnn.Debugger(layout, run_tests, writer)\n",
"plotter = recnn.Plotter(debugger, [['policy'], ['value', 'softq']],)\n",
"torch.autograd.set_detect_anomaly(True)"
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -33,7 +33,6 @@
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"from datetime import datetime\n",
"\n",
"# == recnn ==\n",
"import sys\n",
Expand Down Expand Up @@ -195,7 +194,7 @@
"reinforce = recnn.nn.Reinforce(policy_net, value_net)\n",
"reinforce = reinforce.to(cuda)\n",
"\n",
"reinforce.writer = SummaryWriter(log_dir='../../runs/ReinforceOffPolicy'+datetime.now().strftime(\"%H_%M\") + \"/\")\n",
"reinforce.writer = SummaryWriter(log_dir='../../runs')\n",
"plotter = recnn.utils.Plotter(reinforce.loss_layout, [['value', 'policy']],)"
]
},
Expand Down
Expand Up @@ -34,8 +34,6 @@
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"from datetime import datetime\n",
"\n",
"\n",
"# == recnn ==\n",
"import sys\n",
Expand Down Expand Up @@ -197,7 +195,7 @@
"reinforce = recnn.nn.Reinforce(policy_net, value_net)\n",
"reinforce = reinforce.to(cuda)\n",
"\n",
"reinforce.writer = SummaryWriter(log_dir='../../runs/ReinforceTopKOffPolicy' + datetime.now().strftime(\"%H_%M\") + \"/\")\n",
"reinforce.writer = SummaryWriter(log_dir='../../runs')\n",
"plotter = recnn.utils.Plotter(reinforce.loss_layout, [['value', 'policy']],)"
]
},
Expand Down
148 changes: 100 additions & 48 deletions examples/[Library Basics]/algorithms how to/ddpg.ipynb

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
17 changes: 10 additions & 7 deletions readme.md
Expand Up @@ -42,14 +42,15 @@ This is my school project. It focuses on Reinforcement Learning for personalized

- The learning is built around sequential or frame environment that supports ML20M and like. Seq and Frame determine the length type of sequential data, seq is fully sequential dynamic size, while the frame is just a static frame.

- State Representation module with various methods. For sequential state representation, you can use LSTM/RNN/GRU (WIP)
- State Representation module with various methods. For sequential state representation, you can use basic LSTM/RNN/GRU,
Temporal Convolutional Networks, Echo State Networks and Chaos Free RNNs that are way faster than GRU.

- Parallel data loading with Modin (Dask and Ray) with one line of code = 3x time improvement

- Pytorch 1.5 support with Tensorboard visualization.
- Pytorch 1.3 support with Tensorboard visualization.

- New datasets will be added in the future.

- SOTA optimizers (RAdam, LookAhead, Ranger) come pre-packaged.

## 📚 Medium Articles

The repo consists of two parts: the library (./recnn), and the playground (./examples) where I explain how to work with certain things.
Expand Down Expand Up @@ -88,8 +89,10 @@ The repo consists of two parts: the library (./recnn), and the playground (./exa

### ‍Repos I used code from:

- Sfujim's [BCQ](https://github.com/sfujim/BCQ) (not released yet)
- Higgsfield's [RL Adventure 2](https://github.com/higgsfield/RL-Adventure-2) (great insiration)
- Sfujim's [BCQ](https://github.com/sfujim/BCQ)
- LiyuanLucasLiu [Radam](https://github.com/LiyuanLucasLiu/RAdam)
- Higgsfield's [RL Adventure 2](https://github.com/higgsfield/RL-Adventure-2)
- Mpyrozhok's [adamwr](https://github.com/mpyrozhok/adamwr)

### 🤔 What is this?

Expand Down Expand Up @@ -136,7 +139,7 @@ recommendations, pairwise distances, and pinpoint accuracy.

Run it:
```
git clone --depth 1 git@github.com:awarebayes/RecNN.git
git clone git@github.com:awarebayes/RecNN.git
cd RecNN && streamlit run examples/streamlit_demo.py
```

Expand Down
1 change: 0 additions & 1 deletion recnn/__init__.py
@@ -1,2 +1 @@
from recnn import data, utils, nn, rep
from recnn.data import pd as pd
1 change: 0 additions & 1 deletion recnn/data/__init__.py
Expand Up @@ -2,4 +2,3 @@
from .utils import *
from .env import *
from .dataset_functions import *
from .pandas_backend import pd
25 changes: 8 additions & 17 deletions recnn/data/dataset_functions.py
@@ -1,5 +1,4 @@
from recnn.data.utils import make_items_tensor
from .pandas_backend import pd

"""
What?
Expand Down Expand Up @@ -42,12 +41,6 @@ def prepare_dataset(**kwargs):
build_data_pipeline function, and it is passed down the function chain. If needed, it will be used. Otherwise, ignored
"""

def try_progress_apply(data_frame, function):
try:
return data_frame.progress_apply(function)
except AttributeError:
return data_frame.apply(function)


def prepare_dataset(df, key_to_id, frame_size, env, sort_users=False, **kwargs):

Expand All @@ -56,28 +49,26 @@ def prepare_dataset(df, key_to_id, frame_size, env, sort_users=False, **kwargs):
[1, 34, 123, 2000], recnn makes it look like [0,1,2,3] for you.
"""

df['rating'] = try_progress_apply(df['rating'], lambda i: 2 * (i - 2.5))
df['movieId'] = try_progress_apply(df['movieId'], lambda i: key_to_id.get(i))
df['rating'] = df['rating'].progress_apply(lambda i: 2 * (i - 2.5))
df['movieId'] = df['movieId'].progress_apply(lambda i: key_to_id.get(i))

users = df[['userId', 'movieId']].groupby(['userId']).size()
users = users[users > frame_size]
if sort_users:
users = users.sort_values(ascending=False)
users = users.index
if pd.get_type() == "modin": # modin groupby.apply isn't much faster
df = df._to_pandas() # and collect better be single threaded
ratings = df.sort_values(by='timestamp').set_index('userId').drop('timestamp', axis=1).groupby('userId')

# Groupby user
user_dict = {}

def app(x):
userid = int(x.index[0])
user_dict[userid] = {}
user_dict[userid]['items'] = x['movieId'].values
user_dict[userid]['ratings'] = x['rating'].values
userid = x.index[0]
user_dict[int(userid)] = {}
user_dict[int(userid)]['items'] = x['movieId'].values
user_dict[int(userid)]['ratings'] = x['rating'].values

try_progress_apply(ratings, app)
ratings.progress_apply(app)

env.user_dict = user_dict
env.users = users
Expand Down
5 changes: 2 additions & 3 deletions recnn/data/env.py
@@ -1,6 +1,6 @@
from . import utils, dataset_functions as dset_F
import pickle
from .pandas_backend import pd
import pandas as pd
from torch.utils.data import Dataset, DataLoader
import torch
import numpy as np
Expand Down Expand Up @@ -101,8 +101,7 @@ def __init__(self, embeddings, ratings, test_size=0.05, min_seq_size=10,
self.embeddings = movies_embeddings_tensor
self.key_to_id = key_to_id
self.id_to_key = id_to_key
self.ratings = pd.get().read_csv(ratings)

self.ratings = pd.read_csv(ratings)

self.user_dict = None
self.users = None # filtered keys of user_dict
Expand Down
4 changes: 2 additions & 2 deletions recnn/data/utils.py
@@ -1,7 +1,7 @@

import numpy as np
import torch
from .pandas_backend import pd
import pandas as pd

# helper function similar to pandas.Series.rolling
def rolling_window(a, window):
Expand Down Expand Up @@ -112,7 +112,7 @@ def padder(x):


def sort_users_itemwise(user_dict, users):
return pd.get().Series(dict([(i, user_dict[i]['items'].shape[0]) for i in users])).sort_values(ascending=False).index
return pd.Series(dict([(i, user_dict[i]['items'].shape[0]) for i in users])).sort_values(ascending=False).index


def prepare_batch_dynamic_size(batch, item_embeddings_tensor, embed_batch=None):
Expand Down

0 comments on commit b76b42f

Please sign in to comment.