Skip to content

Commit

Permalink
Rename inferno to skorch.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-work authored and ottonemo committed Oct 10, 2017
1 parent 1b9d6a2 commit 81a8786
Show file tree
Hide file tree
Showing 23 changed files with 284 additions and 272 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
[run] [run]
omit = omit =
inferno/tests/* skorch/tests/*
inferno/tests/* skorch/tests/*
12 changes: 6 additions & 6 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,11 @@
# Inferno # Skorch


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


## Example ## Example


To see a more elaborate example, check out 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 ```python
import numpy as np import numpy as np
Expand All @@ -14,7 +14,7 @@ import torch
from torch import nn from torch import nn
import torch.nn.functional as F 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) X, y = make_classification(1000, 20, n_informative=10, random_state=0)
Expand Down Expand Up @@ -98,7 +98,7 @@ Note: pip installation will follow soon.


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


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


py.test # unit tests py.test # unit tests
pylint inferno # static code checks pylint skorch # static code checks
``` ```


### pip ### pip
Expand Down
10 changes: 5 additions & 5 deletions examples/word_language_model/generate.py
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse import argparse


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


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


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


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


word = corpus.dictionary.idx2word[word_idx] word = corpus.dictionary.idx2word[word_idx]
outf.write(word + ('\n' if i % 20 == 19 else ' ')) outf.write(word + ('\n' if i % 20 == 19 else ' '))
Expand Down
14 changes: 7 additions & 7 deletions examples/word_language_model/learner.py
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,11 @@
import inferno import skorch
import numpy as np import numpy as np
import torch import torch
from torch.autograd import Variable from torch.autograd import Variable
from sklearn.metrics import f1_score from sklearn.metrics import f1_score




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


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


def train_step(self, X, y, _): def train_step(self, X, y, _):
Expand Down Expand Up @@ -74,7 +74,7 @@ def validation_step(self, X, y):
def evaluation_step(self, X, **kwargs): def evaluation_step(self, X, **kwargs):
self.module_.eval() 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 # TODO: resetting the hidden layer here prevents the user from
# manually resetting the hidden layer from outside (when generating # manually resetting the hidden layer from outside (when generating
Expand All @@ -100,9 +100,9 @@ def score(self, X, y=None):
# memory issues. We do not calculate F1 on the batches as this # memory issues. We do not calculate F1 on the batches as this
# would introduce an error to the score. # would introduce an error to the score.
for X, y in self.get_iterator(X, y, train=False): 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_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_probas = np.concatenate(y_probas)
y_target = np.concatenate(y_target) y_target = np.concatenate(y_target)
Expand Down
10 changes: 5 additions & 5 deletions examples/word_language_model/train.py
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse import argparse


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


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


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


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


class ExamplePrinter(inferno.callbacks.Callback): class ExamplePrinter(skorch.callbacks.Callback):
def on_epoch_end(self, net, **kwargs): def on_epoch_end(self, net, **kwargs):
seed_sentence = "the meaning of" seed_sentence = "the meaning of"
indices = [corpus.dictionary.word2idx[n] for n in seed_sentence.split()] 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) sentence, _ = net.sample_n(num_words=10, input=indices)
print(seed_sentence, print(seed_sentence,
" ".join([corpus.dictionary.idx2word[n] for n in sentence])) " ".join([corpus.dictionary.idx2word[n] for n in sentence]))
Expand Down
20 changes: 0 additions & 20 deletions inferno/exceptions.py

This file was deleted.

Loading

0 comments on commit 81a8786

Please sign in to comment.