From 7629b78f425459a84a40fe0acf370de5b5b27bd1 Mon Sep 17 00:00:00 2001 From: Ilya Matiach Date: Fri, 3 Dec 2021 22:58:35 -0500 Subject: [PATCH] fix nightly build failures (#184) --- azuredevops/templates/all-tests-job-template.yml | 3 +-- azuredevops/templates/test-run-step-template.yml | 6 +++--- ...classification_classical_text_explainer.ipynb | 2 +- python/interpret_text/experimental/classical.py | 16 +++++++++++++--- tools/generate_conda_files.py | 6 +++--- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/azuredevops/templates/all-tests-job-template.yml b/azuredevops/templates/all-tests-job-template.yml index 18bae007..94586f86 100644 --- a/azuredevops/templates/all-tests-job-template.yml +++ b/azuredevops/templates/all-tests-job-template.yml @@ -33,8 +33,7 @@ jobs: - ${{ each pyVer in parameters.pyVersions }}: - job: displayName: ${{ format('{0} {1} {2}', plat.Key , testRunType, pyVer) }} - ${{ if eq(plat.Key, 'Windows')}}: - timeoutInMinutes: 240 + timeoutInMinutes: 360 pool: vmImage: ${{ plat.value }} diff --git a/azuredevops/templates/test-run-step-template.yml b/azuredevops/templates/test-run-step-template.yml index 054b64ca..6b2ef35c 100644 --- a/azuredevops/templates/test-run-step-template.yml +++ b/azuredevops/templates/test-run-step-template.yml @@ -68,19 +68,19 @@ steps: - ${{ if eq(parameters.testRunType, 'Unit')}}: - bash: | source activate ${{parameters.condaEnv}} - python -m pytest test/unit --junitxml=./TEST--TEST.xml -o junit_suite_name="$(Agent.JobName)-Unit" + python -m pytest -s -v test/unit --junitxml=./TEST--TEST.xml -o junit_suite_name="$(Agent.JobName)-Unit" displayName: Run Unit tests - ${{ if eq(parameters.testRunType, 'Integration')}}: - bash: | source activate ${{parameters.condaEnv}} - python -m pytest test/integration/ --junitxml=./TEST--TEST.xml -o junit_suite_name="$(Agent.JobName)-Integration" + python -m pytest -s -v test/integration/ --junitxml=./TEST--TEST.xml -o junit_suite_name="$(Agent.JobName)-Integration" displayName: Run Integration tests - ${{ if eq(parameters.testRunType, 'CodeCoverage')}}: - bash: | source activate ${{parameters.condaEnv}} - python -m pytest test/unit --junitxml=./TEST--TEST.xml -o junit_suite_name="$(Agent.JobName)-Coverage" --cov=python --cov-report=xml --cov-report=html -o unit_suite_name="UnitCoverage" + python -m pytest -s -v test/unit --junitxml=./TEST--TEST.xml -o junit_suite_name="$(Agent.JobName)-Coverage" --cov=python --cov-report=xml --cov-report=html -o unit_suite_name="UnitCoverage" displayName: Run Code Coverage tests - task: PublishCodeCoverageResults@1 diff --git a/notebooks/text_classification/text_classification_classical_text_explainer.ipynb b/notebooks/text_classification/text_classification_classical_text_explainer.ipynb index 1cfdb0ef..1e281cbf 100644 --- a/notebooks/text_classification/text_classification_classical_text_explainer.ipynb +++ b/notebooks/text_classification/text_classification_classical_text_explainer.ipynb @@ -126,7 +126,7 @@ "outputs": [], "source": [ "# Create explainer object that contains default glassbox classifier and explanation methods\n", - "explainer = ClassicalTextExplainer()\n", + "explainer = ClassicalTextExplainer(n_jobs=-1, tol=0.1)\n", "label_encoder = LabelEncoder()" ] }, diff --git a/python/interpret_text/experimental/classical.py b/python/interpret_text/experimental/classical.py index ea38b3ec..d40eaa1b 100644 --- a/python/interpret_text/experimental/classical.py +++ b/python/interpret_text/experimental/classical.py @@ -39,7 +39,8 @@ class ClassicalTextExplainer: """ def __init__(self, preprocessor=None, model=None, - hyperparam_range=None, is_trained=False): + hyperparam_range=None, is_trained=False, + n_jobs=None, tol=0.0001): """Initialize the ClassicalTextExplainer :param model: Linear models with linear coefs mapped to features or tree based models with inbuilt feature_importances that are sklearn @@ -52,7 +53,13 @@ def __init__(self, preprocessor=None, model=None, :param hyperparam_range: Custom hyper parameter range to search over when training input model. passed to sklearn's GridsearchCV's as param_grid argument. - :type hyperparam_range: dict """ + :type hyperparam_range: dict + :param n_jobs: The number of jobs to run in parallel. + Passed to GridSearchCV. -1 means using all processors. + :type n_jobs: int + :param tol: Tolerance for stopping criteria. Default is 1e-4. + :type tol: float + """ self.parsed_sentence = None self.word_importances = None self.model = model @@ -69,6 +76,8 @@ def __init__(self, preprocessor=None, model=None, "Custom model needs to be supplied with custom hyperparameter range to search over." ) self.preprocessor = BOWEncoder() if preprocessor is None else preprocessor + self.n_jobs = n_jobs + self.tol = tol def _encode(self, X_str): """Encode text strings in X_str as vectors. @@ -114,8 +123,9 @@ def fit(self, X_str, y_train): self.model = LogisticRegression() # Hyperparameters were chosen through hyperparamter optimization on MNLI self.hyperparam_range = [ExplainerParams.HYPERPARAM_RANGE] + self.hyperparam_range[0]['tol'] = [self.tol] classifier_CV = GridSearchCV( - self.model, self.hyperparam_range, cv=3, scoring="accuracy" + self.model, self.hyperparam_range, cv=3, scoring="accuracy", n_jobs=self.n_jobs ) classifier_CV.fit(X_train, y_train) # set model as the best estimator from grid search results diff --git a/tools/generate_conda_files.py b/tools/generate_conda_files.py index 84d2eb90..d60b9cee 100644 --- a/tools/generate_conda_files.py +++ b/tools/generate_conda_files.py @@ -52,11 +52,11 @@ PIP_BASE = { "interpret-community": "interpret-community>=0.16.0", "cached-property": "cached-property==1.5.1", - "papermill": "papermill>=1.0.1", + "papermill": "papermill>=2.3.3", "nteract-scrapbook": "nteract-scrapbook>=0.2.1", "pytorch-pretrained-bert": "pytorch-pretrained-bert>=0.6", - "tqdm": "tqdm==4.31.1", - "scikit-learn": "scikit-learn>=0.19.0,<=0.20.3", + "tqdm": "tqdm>=4.62.3", + "scikit-learn": "scikit-learn>=0.19.0,<=1.0.1", "nltk": "nltk>=3.4", "pre-commit": "pre-commit>=1.20.0", "spacy": "spacy>=2.2.3",