Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DLSP23] Fixes for torchtext in 12-regularization #842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
38 changes: 24 additions & 14 deletions 12-regularization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
" ...]```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Install old version of torchtext\n",
"# %pip install cmp_version torchtext==0.6.0"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -37,7 +47,7 @@
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"# Checnking for module version \n",
"# Checking for module version \n",
"from cmp_version import cmp_version \n",
"\n",
"# PyTorch imports\n",
Expand Down Expand Up @@ -173,7 +183,7 @@
"source": [
"# Print most common vocabulary text\n",
"most_common_samples = 10\n",
"print(text.vocab.freqs.most_common(most_common_samples))"
"print(*text.vocab.freqs.most_common(most_common_samples), sep='\\n')"
]
},
{
Expand Down Expand Up @@ -242,7 +252,12 @@
"outputs": [],
"source": [
"# Check if iterator above is an iterable which should show True\n",
"isinstance(train_loader, collections.Iterable)"
"try:\n",
" from collections.abc import Iterable # noqa\n",
"except ImportError:\n",
" from collections import Iterable # noqa\n",
"\n",
"isinstance(train_loader, Iterable)"
]
},
{
Expand Down Expand Up @@ -381,7 +396,7 @@
" out = torch.relu(out)\n",
" \n",
" # Toggle 3: Dropout\n",
" # out = torch.dropout(out, 0.8)\n",
" out = torch.dropout(out, 0.8, train=True)\n",
"\n",
" # Linear function (readout)\n",
" # Take note here use a final sigmoid function so your loss should not go through sigmoid again.\n",
Expand Down Expand Up @@ -608,27 +623,22 @@
" weights_nothing.reshape(-1),\n",
" weights_L1.reshape(-1),\n",
" weights_L2.reshape(-1),\n",
" weights_dropout.reshape(-1),\n",
"), 49, range=(-.5, .5), label=(\n",
" 'No-reg',\n",
" 'L1',\n",
" 'L2',\n",
" 'Dropout'\n",
"))\n",
"plt.legend();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:dl-minicourse] *",
"display_name": "Python 3",
"language": "python",
"name": "conda-env-dl-minicourse-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -640,7 +650,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down