Skip to content

Commit

Permalink
Merge pull request #40 from ResponsiblyAI/dev
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
shlomihod authored Sep 14, 2020
2 parents eda6e65 + 1a4da28 commit fc11a66
Show file tree
Hide file tree
Showing 16 changed files with 661 additions and 561 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
environment:
python: 3.5.0
python: 3.6
tests:
override:
- pylint-run --rcfile=.pylint.ini
Expand Down
21 changes: 10 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
dist: xenial # required for Python >= 3.7
language: python
python:
- "3.5"
- "3.5-dev" # 3.5 development branch
- "3.6"
- "3.6-dev" # 3.6 development branch
- "3.7"
- "3.7-dev" # 3.7 development branch
- "3.7"
- "3.8"
- "3.8-dev" # 3.8 development branch
- "nightly" # nightly build
# - "nightly" # nightly build

cache:
pip: true
Expand All @@ -18,22 +15,24 @@ cache:
env:
global:
- RANDOM_SEED=0
- BOTO_CONFIG=/dev/null # https://github.com/travis-ci/travis-ci/issues/7940
# https://github.com/travis-ci/travis-ci/issues/7940
- BOTO_CONFIG=/dev/null

before_install:
- "sudo apt-get install python3-tk"
- pip install pipenv
# Work around https://github.com/jaraco/zipp/issues/40
- python -m pip install -U --upgrade pip setuptools virtualenv
- python -m pip install -U pipenv
- make doctor

install:
- make install

script:
- make check
- make test
- make ci

after_success:
- pip install coveralls scrutinizer-ocular
- python -m pip install -U coveralls scrutinizer-ocular
- coveralls
- ocular

Expand Down
4 changes: 2 additions & 2 deletions .verchew.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ version = GNU Make
[Python]

cli = python
version = Python 3.5.
version = Python 3.6.

[pipenv]

cli = pipenv
versions = 10. | 11. | 2018.11 | 2018.10
versions = 2019. | 2020.

[Graphviz]

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Revision History
================

0.1.2 (2020/09/15)
------------------

- Fix Travis CI issues with pipenv

- Fix bugs with word embedding bias

0.1.1 (2019/08/04)
------------------

Expand Down
12 changes: 8 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[requires]
python_version = "3.5"

[packages]
responsibly = {editable = true,path = "."}

Expand All @@ -18,7 +15,11 @@ pep8 = "*"
pydocstyle = "*"
restructuredtext_lint = "*"
# Testing
pytest = "~= 3.3"
# pytest >= 5.4.0 doesn't work with pytest-sugar <= 0.9.2
# once https://github.com/Teemu/pytest-sugar/pull/188 is
# merged, the upper bound can be removed.
# Ref: https://github.com/pytest-dev/pytest/issues/6931
pytest = ">=5.3.5,<5.4.0"
pytest-describe = "*"
pytest-expecter = "*"
pytest-random = "*"
Expand All @@ -43,3 +44,6 @@ jupyter = "*"
notebook = ">=5.7.8"
requests = ">=2.20.0"
sniffer = "*"
# Work around
zipp = ">=2.2.0"

1,111 changes: 599 additions & 512 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ or write us in `Gitter <https://gitter.im/ResponsiblyAI/responsibly>`_.
Requirements
------------

- Python 3.5+
- Python 3.6+

Installation
------------
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta:__legacy__"
2 changes: 1 addition & 1 deletion responsibly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__project__ = 'responsibly'
__description__ = 'Toolkit for Auditing and Mitigating Bias and Fairness of Machine Learning Systems 🔎🤖🧰'
__url__ = 'https://docs.responsibly.ai'
__version__ = '0.1.1'
__version__ = '0.1.2'
__author__ = 'Shlomi Hod'
__author_email__ = 'shlomi.hod@gmail.com'
__license__ = 'MIT'
Expand Down
3 changes: 2 additions & 1 deletion responsibly/fairness/metrics/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _get_labels(ys, labels):
labels = unique_labels(ys)
else:
labels = np.asarray(labels)
if np.all([l not in ys for l in labels]):
if np.all([label not in ys for label in labels]):
raise ValueError('At least one label specified must be in y.')

return labels
Expand Down Expand Up @@ -190,6 +190,7 @@ def roc_curve_by_attr(y_true, y_score, x_sens,

grouped = _groupby_y_x_sens(y_true, y_score, x_sens)

# pylint: disable=too-many-function-args
roc_curves = {x_sens_value: roc_curve(group['y_true'],
group['y_score'],
pos_label, sample_weight,
Expand Down
2 changes: 1 addition & 1 deletion responsibly/fairness/metrics/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pandas as pd
from sklearn.metrics.classification import _check_targets
from sklearn.metrics._classification import _check_targets


def _assert_binary(y1, y2=None):
Expand Down
19 changes: 11 additions & 8 deletions responsibly/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ def pytest_configure(config):
"""Disable verbose output when running tests."""

terminal = config.pluginmanager.getplugin('terminal')
base = terminal.TerminalReporter

class QuietReporter(base):
"""Reporter that only shows dots when running tests."""
class QuietReporter(terminal.TerminalReporter):
@property
def verbosity(self):
return 0

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.verbosity = 0
self.showlongtestinfo = False
self.showfspath = False
@property
def showlongtestinfo(self):
return False

@property
def showfspath(self):
return False

terminal.TerminalReporter = QuietReporter
5 changes: 3 additions & 2 deletions responsibly/tests/test_we.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_assert_gensim_keyed_vectors():


def test_project_params():
# pylint: disable=arguments-out-of-order
v = np.array([1, 2, 3])
u = np.array([-4, 5, -6])

Expand Down Expand Up @@ -454,5 +455,5 @@ def test_compute_association(gender_biased_w2v_small):
"""
(r, pvalue), _ = gender_biased_w2v_small.compute_factual_association()

assert isclose(r, 0.7070401592764508)
assert isclose(pvalue, 1.4324502214459908e-06)
assert isclose(r, 0.7070401592764508, abs_tol=ATOL)
assert isclose(pvalue, 1.4324502214459908e-06, abs_tol=ATOL)
15 changes: 9 additions & 6 deletions responsibly/we/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
from sklearn.decomposition import PCA
from sklearn.metrics.pairwise import euclidean_distances
from sklearn.svm import LinearSVC
from tabulate import tabulate
from tqdm import tqdm

from responsibly.consts import RANDOM_STATE
Expand All @@ -96,7 +97,6 @@
project_vector, reject_vector, round_to_extreme,
take_two_sides_extreme_sorted, update_word_vector,
)
from tabulate import tabulate


DIRECTION_METHODS = ['single', 'sum', 'pca']
Expand All @@ -122,6 +122,8 @@ class BiasWordEmbedding:

def __init__(self, model, only_lower=False, verbose=False,
identify_direction=False, to_normalize=True):
# pylint: disable=undefined-variable

assert_gensim_keyed_vectors(model)

# TODO: this is bad Python, ask someone about it
Expand Down Expand Up @@ -346,10 +348,11 @@ def plot_projection_scores(self, words, n_extreme=10,
projections_df['color'] = ((projections_df['projection'] + 0.5)
.apply(cmap))

most_extream_projection = (projections_df['projection']
.abs()
.max()
.round(1))
most_extream_projection = np.round(
projections_df['projection']
.abs()
.max(),
decimals=1)

sns.barplot(x='projection', y='word', data=projections_df,
palette=projections_df['color'])
Expand Down Expand Up @@ -522,7 +525,7 @@ def generate_analogies(self, n_analogies=100, seed='ends',
:return: Data Frame of analogies (x, y), their distances,
and their cosine similarity scores
"""
# pylint: disable=C0301,R0914
# pylint: disable=C0301,R0914,E1136

if not unrestricted:
warnings.warn('Not Using unrestricted most_similar '
Expand Down
2 changes: 1 addition & 1 deletion scent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Configuration file for sniffer."""
# pylint: disable=superfluous-parens,bad-continuation,unpacking-non-sequence
# pylint: disable=superfluous-parens,unpacking-non-sequence

import subprocess
import time
Expand Down
12 changes: 2 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@


PACKAGE_NAME = 'responsibly'
MINIMUM_PYTHON_VERSION = '3.5'


def check_python_version():
"""Exit when the Python version is too low."""
if sys.version < MINIMUM_PYTHON_VERSION:
sys.exit("Python {0}+ is required.".format(MINIMUM_PYTHON_VERSION))


def read_package_variable(key, filename='__init__.py'):
Expand All @@ -36,8 +29,6 @@ def build_description():
return readme + '\n' + changelog


check_python_version()

setuptools.setup(
name=read_package_variable('__project__'),
version=read_package_variable('__version__'),
Expand Down Expand Up @@ -69,11 +60,12 @@ def build_description():
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],

python_requires='>=3.6',

install_requires=[
"numpy >= 1.15",
"scipy >= 1.1",
Expand Down

0 comments on commit fc11a66

Please sign in to comment.