Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed Jul 30, 2024
1 parent a8142b5 commit 179df4a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.5.5'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
19 changes: 19 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.11
target-version = "py311"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
1 change: 0 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

3 changes: 1 addition & 2 deletions compile_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import ast
import hyperscan
import json
import pickle
Expand All @@ -22,7 +21,7 @@
flags=(hyperscan.HS_FLAG_SINGLEMATCH | hyperscan.HS_FLAG_UTF8,),
)
regexes.add(line)
except hyperscan.error as e:
except hyperscan.error:
pass

# Build input for the final Hyperscan database
Expand Down
9 changes: 4 additions & 5 deletions explain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import io
import json
import random

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -42,9 +41,9 @@ def update_sample(samples, N, sample):
)

# See https://github.com/slundberg/shap/issues/1406
shap.explainers._deep.deep_tf.op_handlers[
"AddV2"
] = shap.explainers._deep.deep_tf.passthrough
shap.explainers._deep.deep_tf.op_handlers["AddV2"] = (
shap.explainers._deep.deep_tf.passthrough
)

# Load the trained model
model = tf.keras.models.model_from_json(open("nn_model_sherlock.json").read())
Expand All @@ -66,7 +65,7 @@ def update_sample(samples, N, sample):
# Use SHAP to create a summary plot
e = shap.DeepExplainer(model, matrix)
shap_values = e.shap_values(sample)
feature_names = [l.strip() for l in open("pattern_ids.txt")]
feature_names = [line.strip() for line in open("pattern_ids.txt")]
shap.summary_plot(
shap_values, sample, class_names=class_names, feature_names=feature_names
)
Expand Down
6 changes: 0 additions & 6 deletions preprocess.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import argparse
import ast
import itertools
import math
import json
import numpy as np
import os
import pickle
Expand All @@ -12,10 +10,6 @@
from pyarrow.parquet import ParquetFile
from tqdm import tqdm
import hyperscan
import joblib
import numpy as np
import scipy
import scipy.sparse


BATCH_SIZE = 1000
Expand Down
6 changes: 3 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@

y_pred = model.predict(matrix)
y_pred = np.argmax(y_pred, axis=1)
labels_pred[
batch * BATCH_SIZE : batch * BATCH_SIZE + len(matrix)
] = le.inverse_transform(y_pred)
labels_pred[batch * BATCH_SIZE : batch * BATCH_SIZE + len(matrix)] = (
le.inverse_transform(y_pred)
)
batch += 1
pbar.update(len(matrix))

Expand Down

0 comments on commit 179df4a

Please sign in to comment.