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

Migrate to PyTorch #191

Merged
merged 85 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
bda13ff
Remove tensorflow components
timokau Mar 12, 2021
e4e907f
Mention the migration status in the README
timokau Apr 3, 2021
05999f8
Remove tensorflow and keras dependencies
timokau Mar 12, 2021
4b1b38a
Avoid ambiguous variable names
timokau Mar 15, 2021
172722e
Mark poetry2nix setup as broken
timokau Apr 3, 2021
b596113
Update nixpkgs
timokau Mar 17, 2021
4bb3df3
Make the nix definitions reusable
timokau Mar 16, 2021
ae7e44c
Update to python 3.8
timokau Mar 15, 2021
8dcd6b3
Add torch dependency
timokau Mar 15, 2021
614cd54
Add skorch dependency
timokau Mar 15, 2021
a009ef9
Update the dependencies in the README
timokau Apr 3, 2021
ddeb39d
Sort estimator class listings alphabetically
timokau Apr 3, 2021
ffaa488
Add pytorch losses and metrics
timokau Mar 15, 2021
99a2aa9
Add superclasses for skorch based estimators
timokau Apr 8, 2021
d643736
Add pytorch FATE estimators
timokau Apr 8, 2021
b48bba1
Prepare for pytorch tests
timokau Mar 23, 2021
4a46a3d
Always use 32 bit floats in tests
timokau Mar 23, 2021
93f5096
Remove some of the fit special casing in tests
timokau Apr 1, 2021
14a6aee
Remove star imports in tests
timokau Apr 3, 2021
0f2b0bc
Add the pytorch based FATE estimators to the tests
timokau Mar 22, 2021
63439d1
Deduplicate the README
timokau Apr 3, 2021
553eaaf
Add a changelog entry for the pytorch migration
timokau Apr 3, 2021
6d14786
Mark FATE as available again in the README
timokau Apr 3, 2021
0eab5b1
Define common skorch arguments in the tests
timokau Apr 7, 2021
ac836cb
Merge pull request #164 from timokau/pytorch-poc
timokau Apr 8, 2021
f202cb2
Add the FETA scoring module
timokau Apr 6, 2021
d3db0a7
Add a FETA discrete choice estimator
timokau Apr 6, 2021
e16e60d
Add FETA to the discrete choice test
timokau Apr 6, 2021
8ec076c
Add a FETA object ranking estimator
timokau Apr 6, 2021
647e9b8
Add FETA to the object ranking test
timokau Apr 6, 2021
98c239d
Add a FETA general choice estimator
timokau Apr 6, 2021
39797c8
Add FETA to the general choice test
timokau Apr 6, 2021
e8a5c80
Merge pull request #183 from timokau/pytorch-feta
timokau Apr 8, 2021
96b2b85
Add CmpNN module
timokau Apr 7, 2021
ce01260
Add the CmpNetScoring module
timokau Apr 7, 2021
b94028a
Add a CmpNet general choice estimator
timokau Apr 7, 2021
15b67a5
Add CmpNet to the general choice test
timokau Apr 7, 2021
581052a
Add a CmpNet discrete choice estimator
timokau Apr 7, 2021
4f448cd
Add CmpNet to the discrete choice test
timokau Apr 7, 2021
6bb82b9
Add a CmpNet object ranking estimator
timokau Apr 7, 2021
9063cc0
Add CmpNet to the object ranking test
timokau Apr 7, 2021
a841c18
fixup! Add a CmpNet general choice estimator
timokau Apr 8, 2021
4010d10
Add missing activation documentation for FETA
timokau Apr 8, 2021
9aa778e
Merge pull request #184 from timokau/pytorch-cmpnet
timokau Apr 8, 2021
dbe6229
Merge pull request #185 from timokau/document-feta-activation
timokau Apr 8, 2021
92ce510
Add the RankNet scoring module
timokau Apr 8, 2021
05b2643
Add a RankNet discrete choice estimator
timokau Apr 8, 2021
936cd4b
Add RankNet to the discrete choice test
timokau Apr 8, 2021
c0ddb87
Add a RankNet object ranking estimator
timokau Apr 8, 2021
320aae3
Add RankNet to the object ranking test
timokau Apr 8, 2021
b4ea040
Add a RankNet general choice estimator
timokau Apr 8, 2021
af37c08
Add RankNet to the general choice test
timokau Apr 8, 2021
645d484
Mark RankNet estimators as available in the README
timokau Apr 8, 2021
034d7e7
Add RankNet and CmpNet changes to the changelog
timokau Apr 8, 2021
68763a1
Add note about changes to behavior and defaults
timokau Apr 8, 2021
0e29bfb
Merge pull request #186 from timokau/pytorch-ranknet
timokau Apr 8, 2021
e4a8d1d
Add missing reference to CmpNetScoring
timokau Apr 8, 2021
410a1d4
Mark FETA estimators as available in the README
timokau Apr 8, 2021
9070ad5
Fix the FETA object ranker documentation
timokau Apr 8, 2021
9af5848
Unify docs of scoring module based estimators
timokau Apr 8, 2021
22bf673
Use SELU as the default activation for CmpNet
timokau Apr 8, 2021
096a745
Explicitly specify the network size for RankNet
timokau Apr 8, 2021
d1cd208
Fix choicefunction module name in the api docs
timokau Apr 8, 2021
ee60fde
Add all estimators to the api docs
timokau Apr 8, 2021
16a4327
Update the migration status in the README
timokau Apr 8, 2021
086b7c0
Merge pull request #187 from timokau/migration-updates
timokau Apr 8, 2021
e6f6ba4
Add GitHub actions tests.yml file
kiudee Apr 12, 2021
96aa079
Add a GitHub action for deployment
kiudee Apr 12, 2021
563a635
Use importlib.metadata to automatically fetch the package version
kiudee Apr 12, 2021
604de70
Remove bump2version as dependency
kiudee Apr 12, 2021
289f64a
Remove bump2version configuration from setup.cfg
kiudee Apr 12, 2021
2152cd5
Add nox as dependency and remove tox
kiudee Apr 12, 2021
d754753
Add nox-poetry as dev dependency
kiudee Apr 12, 2021
e304526
Create noxfile.py with (roughly) the same functionality as the tox co…
kiudee Apr 13, 2021
3afd305
Remove tox.ini file
kiudee Apr 13, 2021
c67f95b
Update tests.yml to use nox.
kiudee Apr 13, 2021
6f1067d
Add coverage stage to tests.yml
kiudee Apr 13, 2021
6cad718
Update black version in .pre-commit-config.yaml
kiudee Apr 13, 2021
6bca1c7
Apply black formatter to codebase
kiudee Apr 13, 2021
80cd697
Ignore errors while reading files when running coverage
kiudee Apr 13, 2021
682ac25
Update CONTRIBUTING.rst
kiudee Apr 13, 2021
cb49c28
Replace tox by nox in release.yml
kiudee Apr 13, 2021
a74dbcf
Merge pull request #189 from kiudee/gh-actions
kiudee Apr 13, 2021
27bd138
Update README.rst
kiudee Apr 13, 2021
7c1f922
Update Python version in .readthedocs.yml
kiudee Apr 13, 2021
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
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# .github/workflows/release.yml
name: Release
on:
release:
types: [published]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: '3.8'
architecture: x64
- run: pip install nox==2020.12.31
- run: pip install nox-poetry==0.8.4
- run: pip install poetry==1.1.4
- run: nox
- run: poetry build
- run: poetry publish --username=__token__ --password=${{ secrets.PYPI_TOKEN }}
90 changes: 90 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Tests
on:
- push
- pull_request
jobs:
tests:
runs-on: "${{ matrix.os }}"
strategy:
fail-fast: false
matrix:
include:
- { python-version: 3.8, os: ubuntu-latest, session: "pre-commit" }
- { python-version: 3.8, os: ubuntu-latest, session: "tests" }
- { python-version: 3.8, os: ubuntu-latest, session: "docs-build" }

name: "${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }}"
env:
NOXSESSION: "${{ matrix.session }}"
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: pip install nox==2020.12.31
- run: pip install nox-poetry==0.8.4
- run: pip install poetry==1.1.4
- name: Compute pre-commit cache key
if: matrix.session == 'pre-commit'
id: pre-commit-cache
shell: python
run: |
import hashlib
import sys
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
print("::set-output name=result::{}".format(result))
- name: Restore pre-commit cache
uses: actions/[email protected]
if: matrix.session == 'pre-commit'
with:
path: ~/.cache/pre-commit
key: "${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}"
restore-keys: |
"${{ steps.pre-commit-cache.outputs.result }}-"
- name: Run Nox
run: |
nox --force-color --python=${{ matrix.python-version }}

- name: Upload coverage data
if: always() && matrix.session == 'tests'
uses: "actions/[email protected]"
with:
name: coverage-data
path: ".coverage.*"


coverage:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repository
uses: actions/[email protected]

- name: Set up Python 3.8
uses: actions/[email protected]
with:
python-version: 3.8

- run: pip install nox==2020.12.31
- run: pip install nox-poetry==0.8.4
- run: pip install poetry==1.1.4

- name: Download coverage data
uses: actions/[email protected]
with:
name: coverage-data

- name: Combine coverage data and display human readable report
run: |
nox --force-color --session=coverage

- name: Create coverage report
run: |
nox --force-color --session=coverage -- xml

- name: Upload coverage report
uses: codecov/[email protected]
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/PyCQA/doc8
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sphinx:
configuration: docs/conf.py

python:
version: 3.7
version: 3.8
install:
- method: pip
path: .
Expand Down
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- 3.7.9 # Pinned since tensorflow 1.x is not available for python > 3.7
- 3.8

cache:
directories:
Expand All @@ -23,18 +23,16 @@ stages:
jobs:
fast_finish: true
include:
- python: 3.7.9
- python: 3.8
env: TOXENV=test1
- python: 3.7.9
- python: 3.8
env: TOXENV=test2
- python: 3.7.9
- python: 3.8
env: TOXENV=test3
- python: 3.7.9
env: TOXENV=test4
- python: 3.7.9
- python: 3.8
env: TOXENV=lint
- stage: docs
python: 3.7.9
python: 3.8
env: TOXENV=docs

before_deploy:
Expand All @@ -47,6 +45,6 @@ deploy:
script: poetry publish -v --build
on:
tags: true
python: 3.7.9
python: 3.8
repo: kiudee/cs-ranking
branch: master
12 changes: 3 additions & 9 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,9 @@ Deploying
~~~~~~~~~

Make sure all your changes are committed (including an entry in HISTORY.rst).
Then run

.. code-block:: bash

$ bump2version patch # possible: major / minor / patch
$ git push
$ git push --tags

The new version will automatically be released on PyPi.
Then click on `"Draft a new release"`__ at the GitHub repository.
GitHub Actions will ensure that the package is uploaded to PyPI.

__ https://github.com/kiudee/cs-ranking/releases/new

.. _poetry: https://python-poetry.org/
17 changes: 16 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
History
=======

Unreleased
2.0.0 (Unreleased)
------------------

* The library has been migrated to pytorch. This is a breaking change. You will
likely need to adapt to this new version if you have been using estimators
from version 1.x.

* The RankNet and CmpNet estimators are now trained with a loss that applies to
the whole result (the general/discrete choice or ranking). They were
previously trained on object pairs with different loss functions.

* Behavior and default parameters of the estimators may differ from the
previous versions. For example the default activation for CmpNet and RankNet
is now SELU instead of ReLU.

1.3.0 (Unreleased)
------------------

* We no longer override any of the defaults of our default optimizer (SGD). In
Expand Down
25 changes: 17 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
|Build Status| |Coverage| |Binder|
|Coverage| |Binder|

****
NOTE
****

This library has recently been migrated from tensorflow to PyTorch. The 2.0
version marks a breaking change. Some of the previous functionality is now
unavailable and some classes behave differently. You can use the latest 1.x
release if you are looking for the tensorflow based estimators.

*******
CS-Rank
*******

CS-Rank is a Python package for context-sensitive ranking and choice
algorithms.

Expand All @@ -27,9 +37,6 @@ setting:
* RankNetDiscreteChoiceFunction
* PairwiseSVMDiscreteChoiceFunction

Check out our `interactive notebooks`_ to quickly find out what our package can
do.


Getting started
===============
Expand Down Expand Up @@ -73,7 +80,7 @@ Another option is to clone the repository and install CS-Rank using::

Dependencies
------------
CS-Rank depends on Tensorflow, Keras, NumPy, SciPy, matplotlib, scikit-learn,
CS-Rank depends on PyTorch, skorch, NumPy, SciPy, matplotlib, scikit-learn,
joblib and tqdm. For data processing and generation you will
also need PyGMO, H5Py and pandas.

Expand Down Expand Up @@ -111,10 +118,12 @@ License
:target: https://mybinder.org/v2/gh/kiudee/cs-ranking/master?filepath=docs%2Fnotebooks

.. |Coverage| image:: https://codecov.io/gh/kiudee/cs-ranking/branch/master/graph/badge.svg
:target: https://codecov.io/gh/kiudee/cs-ranking
:target: https://codecov.io/gh/kiudee/cs-ranking

.. |Build Status| image:: https://travis-ci.org/kiudee/cs-ranking.svg?branch=master
:target: https://travis-ci.org/kiudee/cs-ranking
..
|Build Status| image:: https://img.shields.io/github/workflow/status/kiudee/cs-ranking/tests
:target: https://github.com/kiudee/cs-ranking/actions
:alt: GitHub Workflow Status


.. _interactive notebooks: https://mybinder.org/v2/gh/kiudee/cs-ranking/master?filepath=docs%2Fnotebooks
Expand Down
10 changes: 6 additions & 4 deletions csrank/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
__version__ = "1.2.1"

# We should re-evaluate if we really want to re-export everything here and then
# use __all__ properly.
from importlib.metadata import version

from .choicefunction import * # noqa
from .core import * # noqa
from .dataset_reader import * # noqa
from .discretechoice import * # noqa
from .objectranking import * # noqa

# We should re-evaluate if we really want to re-export everything here and then
# use __all__ properly.

__version__ = version(__name__)
Loading