Move Keras as an optional dependency (#319)

Fixes #317
This commit is contained in:
Boris Feld 2019-04-26 18:50:02 +02:00 коммит произвёл Marco
Родитель 8755ea94e5
Коммит 90a8d0f007
7 изменённых файлов: 37 добавлений и 19 удалений

Просмотреть файл

@ -4,4 +4,4 @@ include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
known_third_party = dateutil,flask,hglib,imblearn,jsone,keras,libmozdata,numpy,pandas,parsepatch,pytest,requests,setuptools,shap,sklearn,taskcluster,tqdm,xgboost,yaml,zstandard
known_third_party = dateutil,flask,hglib,imblearn,jsone,libmozdata,numpy,pandas,parsepatch,pytest,requests,setuptools,shap,sklearn,taskcluster,tqdm,xgboost,yaml,zstandard

Просмотреть файл

@ -1,6 +1,7 @@
include VERSION
include requirements.txt
include extra-nlp-requirements.txt
include extra-nn-requirements.txt
recursive-include bugbug/labels *
recursive-exclude * __pycache__

Просмотреть файл

@ -3,18 +3,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from keras import Input, layers
from keras.layers import (
GRU,
Bidirectional,
Dense,
Dropout,
Embedding,
Flatten,
GlobalMaxPooling1D,
SpatialDropout1D,
)
from keras.models import Model as KerasModel
from sklearn.ensemble import VotingClassifier
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.pipeline import Pipeline, make_pipeline
@ -29,10 +17,29 @@ from bugbug.utils import (
StructuredColumnTransformer,
)
OPT_MSG_MISSING = (
"Optional dependencies are missing, install them with: pip install bugbug[nn]\n"
)
try:
from keras import Input, layers
from keras.layers import (
GRU,
Bidirectional,
Dense,
Dropout,
Embedding,
Flatten,
GlobalMaxPooling1D,
SpatialDropout1D,
)
from keras.models import Model as KerasModel
except ImportError:
raise ImportError(OPT_MSG_MISSING)
class ComponentNNClassifier(KerasClassifier):
def __init__(self, **kwargs):
# (epochs, batch_size) combinations
fit_params = [(2, 256), (2, 512), (1, 1024)]
super().__init__(fit_params=fit_params)

Просмотреть файл

@ -3,13 +3,23 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from keras.preprocessing.sequence import pad_sequences
from keras.preprocessing.text import Tokenizer
from keras.utils import to_categorical
from sklearn.base import BaseEstimator, ClassifierMixin, TransformerMixin
from bugbug.utils import numpy_to_dict
OPT_MSG_MISSING = (
"Optional dependencies are missing, install them with: pip install bugbug[nn]\n"
)
try:
from keras.preprocessing.sequence import pad_sequences
from keras.preprocessing.text import Tokenizer
from keras.utils import to_categorical
HAS_OPTIONAL_DEPENDENCIES = True
except ImportError:
raise ImportError(OPT_MSG_MISSING)
class KerasTextToSequences(BaseEstimator, TransformerMixin):
def __init__(self, maxlen, vocab_size):

Просмотреть файл

@ -0,0 +1 @@
keras==2.2.4

Просмотреть файл

@ -10,7 +10,6 @@ python-hglib==2.6.1
shap==0.28.5
pandas==0.24.2
parsepatch==0.1.3
keras==2.2.4
tqdm==4.31.1
python-dateutil==2.8.0
zstandard==0.11.0

Просмотреть файл

@ -38,7 +38,7 @@ with open(os.path.join(here, "VERSION")) as f:
version = f.read().strip()
# Read the extra requirements
extras = ["nlp"]
extras = ["nlp", "nn"]
extras_require = {}