Skip to content
Permalink
Browse files

Rename inferno to skorch.

  • Loading branch information...
benjamin-work authored and ottonemo committed Oct 9, 2017
1 parent 1b9d6a2 commit 81a8786cd48334eb633e2bf428f1c9b0d2de9833
@@ -1,4 +1,4 @@
[run]
omit =
inferno/tests/*
inferno/tests/*
skorch/tests/*
skorch/tests/*
@@ -1,11 +1,11 @@
# Inferno
# Skorch

A scikit-learn compatible neural network library that wraps pytorch.

## Example

To see a more elaborate example, check out
[this notebook](https://nbviewer.jupyter.org/github/dnouri/inferno/blob/master/notebooks/Basic_Usage.ipynb)
[this notebook](https://nbviewer.jupyter.org/github/dnouri/skorch/blob/master/notebooks/Basic_Usage.ipynb)

```python
import numpy as np
@@ -14,7 +14,7 @@ import torch
from torch import nn
import torch.nn.functional as F
from inferno.net import NeuralNetClassifier
from skorch.net import NeuralNetClassifier
X, y = make_classification(1000, 20, n_informative=10, random_state=0)
@@ -98,7 +98,7 @@ Note: pip installation will follow soon.

```shell
conda env create
source activate inferno
source activate skorch
# install pytorch version for your system (see below)
python setup.py install
```
@@ -107,13 +107,13 @@ python setup.py install

```shell
conda env create
source activate inferno
source activate skorch
# install pytorch version for your system (see below)
conda install --file requirements-dev.txt
python setup.py develop
py.test # unit tests
pylint inferno # static code checks
pylint skorch # static code checks
```

### pip
@@ -1,6 +1,6 @@
import argparse

import inferno
import skorch
import torch
from torch.autograd import Variable

@@ -48,16 +48,16 @@
learner.load_params(args.checkpoint)

hidden = None
input = inferno.utils.to_var(torch.rand(1,1).mul(ntokens).long(),
use_cuda=args.cuda)
input = skorch.utils.to_var(torch.rand(1, 1).mul(ntokens).long(),
use_cuda=args.cuda)

with open(args.outf, 'w') as outf:
for i in range(args.words):
word_idx, hidden = learner.sample(input=input,
temperature=args.temperature,
hidden=hidden)
input = inferno.utils.to_var(torch.LongTensor([[word_idx]]),
use_cuda=args.cuda)
input = skorch.utils.to_var(torch.LongTensor([[word_idx]]),
use_cuda=args.cuda)

word = corpus.dictionary.idx2word[word_idx]
outf.write(word + ('\n' if i % 20 == 19 else ' '))
@@ -1,11 +1,11 @@
import inferno
import skorch
import numpy as np
import torch
from torch.autograd import Variable
from sklearn.metrics import f1_score


class Learner(inferno.NeuralNet):
class Learner(skorch.NeuralNet):

def __init__(self,
criterion=torch.nn.CrossEntropyLoss,
@@ -42,8 +42,8 @@ def sample_n(self, num_words, input, temperature=1., hidden=None):
preds = [None] * num_words
for i in range(num_words):
preds[i], hidden = self.sample(input, hidden=hidden)
input = inferno.utils.to_var(torch.LongTensor([[preds[i]]]),
use_cuda=self.use_cuda)
input = skorch.utils.to_var(torch.LongTensor([[preds[i]]]),
use_cuda=self.use_cuda)
return preds, hidden

def train_step(self, X, y, _):
@@ -74,7 +74,7 @@ def validation_step(self, X, y):
def evaluation_step(self, X, **kwargs):
self.module_.eval()

X = inferno.utils.to_var(X, use_cuda=self.use_cuda)
X = skorch.utils.to_var(X, use_cuda=self.use_cuda)

# TODO: resetting the hidden layer here prevents the user from
# manually resetting the hidden layer from outside (when generating
@@ -100,9 +100,9 @@ def score(self, X, y=None):
# memory issues. We do not calculate F1 on the batches as this
# would introduce an error to the score.
for X, y in self.get_iterator(X, y, train=False):
prediction = inferno.utils.to_numpy(self.evaluation_step(X)).argmax(1)
prediction = skorch.utils.to_numpy(self.evaluation_step(X)).argmax(1)
y_probas.append(prediction)
y_target.append(inferno.utils.to_numpy(y))
y_target.append(skorch.utils.to_numpy(y))

y_probas = np.concatenate(y_probas)
y_target = np.concatenate(y_target)
@@ -1,6 +1,6 @@
import argparse

import inferno
import skorch
import torch
from sklearn.model_selection import GridSearchCV

@@ -30,21 +30,21 @@
corpus = data.Corpus(args.data)
ntokens = len(corpus.dictionary)

class LRAnnealing(inferno.callbacks.Callback):
class LRAnnealing(skorch.callbacks.Callback):
def on_epoch_end(self, net, **kwargs):
if not net.history[-1]['valid_loss_best']:
net.lr /= 4.0

class Checkpointing(inferno.callbacks.Callback):
class Checkpointing(skorch.callbacks.Callback):
def on_epoch_end(self, net, **kwargs):
if net.history[-1]['valid_loss_best']:
net.save_params(args.save)

class ExamplePrinter(inferno.callbacks.Callback):
class ExamplePrinter(skorch.callbacks.Callback):
def on_epoch_end(self, net, **kwargs):
seed_sentence = "the meaning of"
indices = [corpus.dictionary.word2idx[n] for n in seed_sentence.split()]
indices = inferno.utils.to_var(torch.LongTensor([indices]).t(), use_cuda=args.cuda)
indices = skorch.utils.to_var(torch.LongTensor([indices]).t(), use_cuda=args.cuda)
sentence, _ = net.sample_n(num_words=10, input=indices)
print(seed_sentence,
" ".join([corpus.dictionary.idx2word[n] for n in sentence]))

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 81a8786

Please sign in to comment.
You can’t perform that action at this time.