Skip to content

Commit

Permalink
Feature/torch 0.3 (#127)
Browse files Browse the repository at this point in the history
* Better error message when data conversion fails.

Specifically, when conversion to torch tensor or to numpy array fails,
users would often only get "AttributeError: bla has no attribute
.cuda". Now a more specific TypeError is shown.

* Update install instructions for pytorch 0.3.

* Softmax now requires a dimension parameter.

* Fix an sklearn deprecation warning.

* Install pytorch from new pytorch forge channel.

* Update install instructions for pytorch 0.3.

* Softmax now requires a dimension parameter.

* Fix an sklearn deprecation warning.

* Install pytorch from new pytorch forge channel.

* Add missing parameter to a Scoring unit test.

* __repr__ changed in torch 0.3, adjust test to changes.

* Remove temporary workaround to pytorch indexing idiosyncrasy.

* Fix some pylint complaints.
  • Loading branch information
benjamin-work authored and ottonemo committed Dec 8, 2017
1 parent 4bf56dd commit d2fcce0
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ install:
- source activate skorch-env
- conda install --file=requirements-dev.txt
- python setup.py install
- conda install -c soumith pytorch
- conda install -c pytorch pytorch
script:
- pytest
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ version you need is dependent on your system. For installation
instructions for ``pytorch``, visit the `pytorch website
<http://pytorch.org/>`__.

In general, this should work:
In general, this should work (assuming CUDA 9):

.. code:: bash
# using conda:
conda install pytorch cuda80 -c soumith
conda install pytorch cuda90 -c pytorch
# using pip
pip install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp36-cp36m-manylinux1_x86_64.whl
pip install http://download.pytorch.org/whl/cu90/torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl
98 changes: 49 additions & 49 deletions notebooks/Advanced_Usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
" X = self.nonlin(self.dense0(X))\n",
" X = self.dropout(X)\n",
" X = F.relu(self.dense1(X))\n",
" X = F.softmax(self.output(X))\n",
" X = F.softmax(self.output(X), dim=-1)\n",
" return X"
]
},
Expand Down Expand Up @@ -283,7 +283,7 @@
"net = NeuralNetClassifier(\n",
" ClassifierModule,\n",
" max_epochs=10,\n",
" lr=0.1,\n",
" lr=0.02,\n",
" warm_start=True,\n",
" callbacks=[AccuracyTweet(min_accuracy=0.7)],\n",
")"
Expand All @@ -300,16 +300,16 @@
"text": [
" epoch train_loss valid_acc valid_loss dur\n",
"------- ------------ ----------- ------------ ------\n",
" 1 \u001b[36m0.7111\u001b[0m \u001b[32m0.5100\u001b[0m \u001b[35m0.6894\u001b[0m 0.0994\n",
" 2 \u001b[36m0.6928\u001b[0m \u001b[32m0.5500\u001b[0m \u001b[35m0.6803\u001b[0m 0.0676\n",
" 3 \u001b[36m0.6833\u001b[0m \u001b[32m0.5650\u001b[0m \u001b[35m0.6741\u001b[0m 0.0396\n",
" 4 \u001b[36m0.6763\u001b[0m \u001b[32m0.5850\u001b[0m \u001b[35m0.6674\u001b[0m 0.0661\n",
" 5 \u001b[36m0.6727\u001b[0m \u001b[32m0.6450\u001b[0m \u001b[35m0.6616\u001b[0m 0.0557\n",
" 6 \u001b[36m0.6606\u001b[0m \u001b[32m0.6600\u001b[0m \u001b[35m0.6536\u001b[0m 0.0645\n",
" 7 \u001b[36m0.6560\u001b[0m 0.6600 \u001b[35m0.6443\u001b[0m 0.0559\n",
" 8 \u001b[36m0.6427\u001b[0m \u001b[32m0.6650\u001b[0m \u001b[35m0.6354\u001b[0m 0.0569\n",
" 9 \u001b[36m0.6300\u001b[0m \u001b[32m0.6800\u001b[0m \u001b[35m0.6264\u001b[0m 0.0606\n",
" 10 \u001b[36m0.6289\u001b[0m 0.6800 \u001b[35m0.6189\u001b[0m 0.0594\n",
" 1 \u001b[36m0.6908\u001b[0m \u001b[32m0.5950\u001b[0m \u001b[35m0.6842\u001b[0m 0.1078\n",
" 2 \u001b[36m0.6876\u001b[0m 0.5950 \u001b[35m0.6815\u001b[0m 0.0561\n",
" 3 \u001b[36m0.6853\u001b[0m \u001b[32m0.6100\u001b[0m \u001b[35m0.6789\u001b[0m 0.0580\n",
" 4 0.6882 0.5950 \u001b[35m0.6769\u001b[0m 0.0551\n",
" 5 \u001b[36m0.6780\u001b[0m 0.6000 \u001b[35m0.6743\u001b[0m 0.0570\n",
" 6 \u001b[36m0.6730\u001b[0m 0.6100 \u001b[35m0.6717\u001b[0m 0.0538\n",
" 7 \u001b[36m0.6664\u001b[0m \u001b[32m0.6150\u001b[0m \u001b[35m0.6698\u001b[0m 0.0496\n",
" 8 0.6670 0.6100 \u001b[35m0.6670\u001b[0m 0.0522\n",
" 9 0.6667 \u001b[32m0.6300\u001b[0m \u001b[35m0.6646\u001b[0m 0.0560\n",
" 10 \u001b[36m0.6624\u001b[0m \u001b[32m0.6350\u001b[0m \u001b[35m0.6624\u001b[0m 0.0575\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
"*tweet* Accuracy never reached 0.7 :( #skorch #pytorch\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
Expand All @@ -318,7 +318,7 @@
{
"data": {
"text/plain": [
"<skorch.net.NeuralNetClassifier at 0x7f7aeeae95f8>"
"<skorch.net.NeuralNetClassifier at 0x7faf55866048>"
]
},
"execution_count": 10,
Expand Down Expand Up @@ -346,25 +346,25 @@
"name": "stdout",
"output_type": "stream",
"text": [
" 11 \u001b[36m0.6241\u001b[0m \u001b[32m0.7150\u001b[0m \u001b[35m0.6114\u001b[0m 0.0475\n",
" 12 \u001b[36m0.6132\u001b[0m 0.7150 \u001b[35m0.6017\u001b[0m 0.0443\n",
" 13 \u001b[36m0.5950\u001b[0m \u001b[32m0.7350\u001b[0m \u001b[35m0.5902\u001b[0m 0.0523\n",
" 14 \u001b[36m0.5914\u001b[0m 0.7200 \u001b[35m0.5831\u001b[0m 0.0551\n",
" 15 \u001b[36m0.5784\u001b[0m 0.7300 \u001b[35m0.5733\u001b[0m 0.0598\n",
" 16 0.5816 \u001b[32m0.7400\u001b[0m \u001b[35m0.5665\u001b[0m 0.0524\n",
" 17 \u001b[36m0.5766\u001b[0m \u001b[32m0.7450\u001b[0m \u001b[35m0.5616\u001b[0m 0.0539\n",
" 18 \u001b[36m0.5636\u001b[0m 0.7450 \u001b[35m0.5559\u001b[0m 0.0548\n",
" 19 \u001b[36m0.5517\u001b[0m 0.7350 \u001b[35m0.5527\u001b[0m 0.0571\n",
" 20 0.5570 0.7350 \u001b[35m0.5492\u001b[0m 0.0544\n",
" 11 0.6647 \u001b[32m0.6500\u001b[0m \u001b[35m0.6598\u001b[0m 0.0816\n",
" 12 \u001b[36m0.6573\u001b[0m \u001b[32m0.6650\u001b[0m \u001b[35m0.6575\u001b[0m 0.0675\n",
" 13 \u001b[36m0.6458\u001b[0m \u001b[32m0.6700\u001b[0m \u001b[35m0.6549\u001b[0m 0.0454\n",
" 14 0.6528 \u001b[32m0.6750\u001b[0m \u001b[35m0.6525\u001b[0m 0.0905\n",
" 15 0.6476 0.6700 \u001b[35m0.6502\u001b[0m 0.0854\n",
" 16 0.6483 0.6750 \u001b[35m0.6476\u001b[0m 0.0878\n",
" 17 0.6514 \u001b[32m0.6800\u001b[0m \u001b[35m0.6452\u001b[0m 0.0741\n",
" 18 \u001b[36m0.6365\u001b[0m \u001b[32m0.6850\u001b[0m \u001b[35m0.6422\u001b[0m 0.0545\n",
" 19 \u001b[36m0.6335\u001b[0m \u001b[32m0.7000\u001b[0m \u001b[35m0.6390\u001b[0m 0.0531\n",
" 20 0.6381 \u001b[32m0.7100\u001b[0m \u001b[35m0.6363\u001b[0m 0.0477\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
"*tweet* Accuracy reached 0.7 at epoch 11!!! #skorch #pytorch\n",
"*tweet* Accuracy reached 0.7 at epoch 19!!! #skorch #pytorch\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
]
},
{
"data": {
"text/plain": [
"<skorch.net.NeuralNetClassifier at 0x7f7aeeae95f8>"
"<skorch.net.NeuralNetClassifier at 0x7faf55866048>"
]
},
"execution_count": 11,
Expand Down Expand Up @@ -460,25 +460,25 @@
"text": [
" epoch train_loss valid_acc valid_loss dur\n",
"------- ------------ ----------- ------------ ------\n",
" 1 \u001b[36m0.7261\u001b[0m \u001b[32m0.5050\u001b[0m \u001b[35m0.6986\u001b[0m 0.0527\n",
" 2 \u001b[36m0.6977\u001b[0m \u001b[32m0.5350\u001b[0m \u001b[35m0.6889\u001b[0m 0.0584\n",
" 3 \u001b[36m0.6897\u001b[0m \u001b[32m0.5550\u001b[0m \u001b[35m0.6844\u001b[0m 0.0593\n",
" 4 \u001b[36m0.6846\u001b[0m \u001b[32m0.5800\u001b[0m \u001b[35m0.6813\u001b[0m 0.0579\n",
" 5 \u001b[36m0.6788\u001b[0m 0.5800 \u001b[35m0.6768\u001b[0m 0.0483\n",
" 6 \u001b[36m0.6725\u001b[0m 0.5800 \u001b[35m0.6731\u001b[0m 0.0479\n",
" 7 \u001b[36m0.6711\u001b[0m \u001b[32m0.5950\u001b[0m \u001b[35m0.6689\u001b[0m 0.0522\n",
" 8 \u001b[36m0.6581\u001b[0m \u001b[32m0.6150\u001b[0m \u001b[35m0.6650\u001b[0m 0.0542\n",
" 9 0.6648 0.6050 \u001b[35m0.6605\u001b[0m 0.0585\n",
" 10 \u001b[36m0.6550\u001b[0m 0.6150 \u001b[35m0.6549\u001b[0m 0.0544\n",
" 1 \u001b[36m0.7139\u001b[0m \u001b[32m0.5500\u001b[0m \u001b[35m0.6933\u001b[0m 0.1162\n",
" 2 \u001b[36m0.6916\u001b[0m \u001b[32m0.5950\u001b[0m \u001b[35m0.6873\u001b[0m 0.0457\n",
" 3 \u001b[36m0.6829\u001b[0m 0.5800 \u001b[35m0.6814\u001b[0m 0.0516\n",
" 4 \u001b[36m0.6671\u001b[0m \u001b[32m0.6050\u001b[0m \u001b[35m0.6718\u001b[0m 0.0440\n",
" 5 \u001b[36m0.6670\u001b[0m \u001b[32m0.6200\u001b[0m \u001b[35m0.6639\u001b[0m 0.1035\n",
" 6 \u001b[36m0.6622\u001b[0m \u001b[32m0.6350\u001b[0m \u001b[35m0.6546\u001b[0m 0.0561\n",
" 7 \u001b[36m0.6371\u001b[0m \u001b[32m0.6550\u001b[0m \u001b[35m0.6429\u001b[0m 0.0387\n",
" 8 \u001b[36m0.6293\u001b[0m \u001b[32m0.6700\u001b[0m \u001b[35m0.6312\u001b[0m 0.0680\n",
" 9 \u001b[36m0.6170\u001b[0m 0.6650 \u001b[35m0.6200\u001b[0m 0.0500\n",
" 10 0.6204 \u001b[32m0.6750\u001b[0m \u001b[35m0.6119\u001b[0m 0.0477\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
"*tweet* Accuracy reached 0.6 at epoch 8!!! #skorch #pytorch\n",
"*tweet* Accuracy reached 0.6 at epoch 4!!! #skorch #pytorch\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
]
},
{
"data": {
"text/plain": [
"<skorch.net.NeuralNetClassifier at 0x7f7aeeae94e0>"
"<skorch.net.NeuralNetClassifier at 0x7faf5585b9b0>"
]
},
"execution_count": 13,
Expand All @@ -505,7 +505,7 @@
{
"data": {
"text/plain": [
"<skorch.net.NeuralNetClassifier at 0x7f7aeeae94e0>"
"<skorch.net.NeuralNetClassifier at 0x7faf5585b9b0>"
]
},
"execution_count": 14,
Expand All @@ -528,16 +528,16 @@
"text": [
" epoch train_loss valid_acc valid_loss dur\n",
"------- ------------ ----------- ------------ ------\n",
" 11 \u001b[36m0.6435\u001b[0m \u001b[32m0.6250\u001b[0m \u001b[35m0.6492\u001b[0m 0.0568\n",
" 12 0.6435 \u001b[32m0.6350\u001b[0m \u001b[35m0.6437\u001b[0m 0.0546\n",
" 13 \u001b[36m0.6267\u001b[0m \u001b[32m0.6450\u001b[0m \u001b[35m0.6375\u001b[0m 0.0555\n",
" 14 \u001b[36m0.6214\u001b[0m \u001b[32m0.6800\u001b[0m \u001b[35m0.6306\u001b[0m 0.0390\n",
" 15 \u001b[36m0.6185\u001b[0m 0.6750 \u001b[35m0.6239\u001b[0m 0.0440\n",
" 16 \u001b[36m0.6060\u001b[0m 0.6750 \u001b[35m0.6154\u001b[0m 0.0454\n",
" 17 \u001b[36m0.5964\u001b[0m \u001b[32m0.6850\u001b[0m \u001b[35m0.6061\u001b[0m 0.0503\n",
" 18 \u001b[36m0.5868\u001b[0m \u001b[32m0.7000\u001b[0m \u001b[35m0.5964\u001b[0m 0.0579\n",
" 19 \u001b[36m0.5693\u001b[0m \u001b[32m0.7150\u001b[0m \u001b[35m0.5859\u001b[0m 0.0556\n",
" 20 \u001b[36m0.5689\u001b[0m \u001b[32m0.7200\u001b[0m \u001b[35m0.5793\u001b[0m 0.0558\n",
" 11 \u001b[36m0.5845\u001b[0m \u001b[32m0.7000\u001b[0m \u001b[35m0.6016\u001b[0m 0.0998\n",
" 12 \u001b[36m0.5831\u001b[0m \u001b[32m0.7050\u001b[0m \u001b[35m0.5915\u001b[0m 0.0762\n",
" 13 0.5854 \u001b[32m0.7200\u001b[0m \u001b[35m0.5788\u001b[0m 0.0597\n",
" 14 \u001b[36m0.5582\u001b[0m 0.7150 \u001b[35m0.5729\u001b[0m 0.0520\n",
" 15 0.5601 0.7150 \u001b[35m0.5692\u001b[0m 0.0486\n",
" 16 \u001b[36m0.5468\u001b[0m \u001b[32m0.7250\u001b[0m \u001b[35m0.5662\u001b[0m 0.0479\n",
" 17 \u001b[36m0.5333\u001b[0m \u001b[32m0.7300\u001b[0m \u001b[35m0.5583\u001b[0m 0.0576\n",
" 18 0.5592 0.7200 \u001b[35m0.5555\u001b[0m 0.0493\n",
" 19 \u001b[36m0.5295\u001b[0m 0.7300 \u001b[35m0.5488\u001b[0m 0.0495\n",
" 20 \u001b[36m0.5232\u001b[0m 0.7300 \u001b[35m0.5428\u001b[0m 0.0532\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
"*tweet* Accuracy never reached 0.75 :( #skorch #pytorch\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
Expand All @@ -546,7 +546,7 @@
{
"data": {
"text/plain": [
"<skorch.net.NeuralNetClassifier at 0x7f7aeeae94e0>"
"<skorch.net.NeuralNetClassifier at 0x7faf5585b9b0>"
]
},
"execution_count": 15,
Expand Down

0 comments on commit d2fcce0

Please sign in to comment.