Skip to content

Commit d073fef

Browse files
committed
feat: apply ruff and fix main problems
Signed-off-by: Luca Foppiano <luca@foppiano.org>
1 parent 4c2bdc9 commit d073fef

43 files changed

Lines changed: 228 additions & 445 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

delft/applications/citationClassifier.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import json
2-
from delft.utilities.Utilities import split_data_and_labels
3-
from delft.textClassification.reader import load_citation_sentiment_corpus
4-
from delft.textClassification import Classifier
51
import argparse
2+
import json
63
import time
4+
5+
from delft.textClassification import Classifier
76
from delft.textClassification.models import architectures
7+
from delft.textClassification.reader import load_citation_sentiment_corpus
8+
from delft.utilities.Utilities import split_data_and_labels
89

910
list_classes = ["negative", "neutral", "positive"]
1011

@@ -194,7 +195,7 @@ def classify(texts, output_format, architecture="gru", embeddings_name=None, tra
194195
if architecture not in architectures:
195196
print("unknown model architecture, must be one of " + str(architectures))
196197

197-
if transformer == None and embeddings_name == None:
198+
if transformer is None and embeddings_name is None:
198199
# default word embeddings
199200
embeddings_name = "glove-840B"
200201

delft/applications/dataseerClassifier.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import json
2-
from delft.utilities.Utilities import split_data_and_labels, t_or_f
3-
from delft.textClassification.reader import load_dataseer_corpus_csv
4-
from delft.textClassification.reader import vectorize as vectorizer
5-
from delft.textClassification import Classifier
61
import argparse
2+
import json
73
import time
8-
from delft.textClassification.models import architectures
4+
95
import numpy as np
106

7+
from delft.textClassification import Classifier
8+
from delft.textClassification.models import architectures
9+
from delft.textClassification.reader import load_dataseer_corpus_csv
10+
from delft.textClassification.reader import vectorize as vectorizer
11+
from delft.utilities.Utilities import split_data_and_labels, t_or_f
12+
1113
"""
12-
Classifier for deciding if a sentence introduce a dataset or not, and prediction of the
13-
dataset type.
14+
Classifier for deciding if a sentence introduce a dataset or not, and prediction of the
15+
dataset type.
1416
"""
1517

1618

@@ -198,8 +200,8 @@ def train(
198200
199201
model_name = 'dataseer-' + the_class + "_" + architecture
200202
201-
model = Classifier(model_name, architecture=architecture, list_classes=datatypes_list_subclasses[the_class], max_epoch=max_epoch,
202-
fold_number=fold_count, patience=patience, use_roc_auc=True, embeddings_name=embeddings_name,
203+
model = Classifier(model_name, architecture=architecture, list_classes=datatypes_list_subclasses[the_class], max_epoch=max_epoch,
204+
fold_number=fold_count, patience=patience, use_roc_auc=True, embeddings_name=embeddings_name,
203205
batch_size=batch_size, class_weights=class_weights, early_stop=early_stop, transformer_name=transformer)
204206
205207
if fold_count == 1:
@@ -560,7 +562,6 @@ def train_eval_cascaded(embeddings_name, fold_count, architecture="gru", transfo
560562
model_binary.eval(x_test, y_test)
561563

562564
x_test_binary = x_test
563-
y_test_binary = y_test
564565

565566
# second, the first level datatype taxonomy for sentences classified as dataset
566567
(
@@ -610,7 +611,6 @@ def train_eval_cascaded(embeddings_name, fold_count, architecture="gru", transfo
610611

611612
# eval by cascading
612613
result_binary = model_binary.predict(x_test_binary, output_format="default")
613-
result_first = model_first.predict(x_test, output_format="default")
614614

615615
# select sequences classified as dataset
616616
result_intermediate = np.asarray([np.argmax(line) for line in result_binary])
@@ -810,7 +810,7 @@ def build_prior_class_distribution():
810810
if architecture not in architectures:
811811
print("unknown model architecture, must be one of " + str(architectures))
812812

813-
if transformer == None and embeddings_name == None:
813+
if transformer is None and embeddings_name is None:
814814
# default word embeddings
815815
embeddings_name = "glove-840B"
816816

delft/applications/datasetTagger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import os
21
import argparse
32
import json
3+
import os
44
import time
5-
import numpy as np
65

6+
import numpy as np
77
from sklearn.model_selection import train_test_split
88

99
from delft.sequenceLabelling import Sequence

delft/applications/grobidTagger.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ def train(
308308
)
309309

310310
if incremental:
311-
if input_model_path != None:
311+
if input_model_path is not None:
312312
model.load(input_model_path)
313-
elif output_path != None:
313+
elif output_path is not None:
314314
model.load(output_path)
315315
else:
316316
model.load()
@@ -423,9 +423,9 @@ def train_eval(
423423
)
424424

425425
if incremental:
426-
if input_model_path != None:
426+
if input_model_path is not None:
427427
model.load(input_model_path)
428-
elif output_path != None:
428+
elif output_path is not None:
429429
model.load(output_path)
430430
else:
431431
model.load()
@@ -798,7 +798,7 @@ class Tasks:
798798
someTexts.append("2023 July the 22nd")
799799
elif model == "citation":
800800
someTexts.append(
801-
"N. Al-Dhahir and J. Cioffi, \“On the uniform ADC bit precision and clip level computation for a Gaussian signal,\” IEEE Trans. Signal Processing, pp. 434–438, Feb. 1996."
801+
r"N. Al-Dhahir and J. Cioffi, \“On the uniform ADC bit precision and clip level computation for a Gaussian signal,\” IEEE Trans. Signal Processing, pp. 434–438, Feb. 1996."
802802
)
803803
someTexts.append(
804804
"T. Steinherz, E. Rivlin, N. Intrator, Off-line cursive script word recognition—a survey, Int. J. Doc. Anal. Recognition 2(3) (1999) 1–33."

delft/applications/insultTagger.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import os
2-
import json
3-
from delft.sequenceLabelling import Sequence
4-
from delft.sequenceLabelling.reader import load_data_and_labels_xml_file
51
import argparse
2+
import json
3+
import os
64
import time
75

6+
from delft.sequenceLabelling import Sequence
7+
from delft.sequenceLabelling.reader import load_data_and_labels_xml_file
88
from delft.utilities.Utilities import t_or_f
99

1010

@@ -224,7 +224,7 @@ def annotate(
224224
wandb = args.wandb
225225
num_workers = args.num_workers
226226

227-
if transformer == None and embeddings_name == None:
227+
if transformer is None and embeddings_name is None:
228228
# default word embeddings
229229
embeddings_name = "glove-840B"
230230

delft/applications/licenseClassifier.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
import argparse
12
import json
2-
from delft.utilities.Utilities import split_data_and_labels, t_or_f
3-
from delft.utilities.numpy import shuffle_triple_with_view
4-
from delft.textClassification.reader import vectorize as vectorizer
3+
import time
4+
5+
import numpy as np
6+
7+
from delft.textClassification import Classifier
8+
from delft.textClassification.models import architectures
59
from delft.textClassification.reader import (
610
load_texts_and_classes_pandas_no_id,
711
)
8-
from delft.textClassification import Classifier
9-
import argparse
10-
import time
11-
from delft.textClassification.models import architectures
12-
import numpy as np
12+
from delft.textClassification.reader import vectorize as vectorizer
13+
from delft.utilities.numpy import shuffle_triple_with_view
14+
from delft.utilities.Utilities import split_data_and_labels, t_or_f
1315

1416
"""
1517
Two multiclass classifiers to be used in combination with Grobid to classify a license/copyrights section
16-
extracted from a scientific article into two dimensions:
18+
extracted from a scientific article into two dimensions:
1719
- copyright owner: publisher, authors or undecidable (changed from NA to avoid issues with pandas)
18-
- license associated to the article file: explicit copyrights (no restriction), creative commons licenses
20+
- license associated to the article file: explicit copyrights (no restriction), creative commons licenses
1921
(CC-0, CC-BY, CC-BY-NC, etc.), other, or undecidable (changed from NA to avoid issues with pandas)
20-
22+
2123
Note: when the license is undecidable, this means normal copyrights when a copyright owner exists.
2224
"""
2325

@@ -690,7 +692,7 @@ def report_training_copyrights(y):
690692
if architecture not in architectures:
691693
print("unknown model architecture, must be one of " + str(architectures))
692694

693-
if transformer == None and embeddings_name == None:
695+
if transformer is None and embeddings_name is None:
694696
# default word embeddings
695697
embeddings_name = "glove-840B"
696698

delft/applications/nerTagger.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import argparse
12
import os
3+
import time
4+
25
import numpy as np
6+
from sklearn.model_selection import train_test_split
7+
38
from delft.sequenceLabelling import Sequence
4-
from delft.utilities.Utilities import stats, t_or_f
5-
from delft.utilities.numpy import shuffle_arrays
69
from delft.sequenceLabelling.reader import (
710
load_data_and_labels_conll,
811
load_data_and_labels_lemonde,
912
load_data_and_labels_ontonotes,
1013
)
11-
from sklearn.model_selection import train_test_split
12-
import argparse
13-
import time
14+
from delft.utilities.numpy import shuffle_arrays
15+
from delft.utilities.Utilities import stats, t_or_f
1416

1517

1618
def configure(
@@ -642,8 +644,6 @@ def annotate(
642644
if not os.path.isfile(file_in):
643645
raise ValueError("the provided input file is not valid")
644646

645-
annotations = []
646-
647647
if (dataset_type == "conll2003") and (lang == "en"):
648648
# load model
649649
model_name = "ner-en-conll2003-" + architecture

delft/applications/onnx_export.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
python -m delft.applications.onnx_export --model MODEL_NAME --output OUTPUT_DIR
1414
"""
1515

16-
import os
17-
import json
1816
import argparse
17+
import json
18+
import os
1919

20-
import torch
2120
import numpy as np
21+
import torch
2222

2323
from delft.sequenceLabelling.wrapper import Sequence
2424

delft/applications/softwareClassifier.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import json
2-
from delft.utilities.Utilities import split_data_and_labels
3-
from delft.textClassification.reader import load_software_use_corpus_json
4-
from delft.textClassification import Classifier
51
import argparse
2+
import json
63
import time
4+
5+
from delft.textClassification import Classifier
76
from delft.textClassification.models import architectures
7+
from delft.textClassification.reader import load_software_use_corpus_json
8+
from delft.utilities.Utilities import split_data_and_labels
89

910
"""
1011
This binary classifier is used in combination with a software mention recognition model, for characterizing
11-
the nature of the citation of software in scientific and technical literature.
12+
the nature of the citation of software in scientific and technical literature.
1213
This classifier predicts if the software introduced by a software mention in a sentence is used
13-
or not by the described work.
14+
or not by the described work.
1415
1516
For the software mention recognizer, see https://github.com/ourresearch/software-mentions
1617
and grobidTagger.py in the present project DeLFT.
1718
18-
Best architecture/model is fine-tuned SciBERT.
19+
Best architecture/model is fine-tuned SciBERT.
1920
"""
2021

2122
list_classes = ["not_used", "used"]
@@ -225,7 +226,7 @@ def classify(texts, output_format, embeddings_name=None, architecture="gru", tra
225226
if architecture not in architectures:
226227
print("unknown model architecture, must be one of " + str(architectures))
227228

228-
if transformer == None and embeddings_name == None:
229+
if transformer is None and embeddings_name is None:
229230
# default word embeddings
230231
embeddings_name = "glove-840B"
231232

delft/applications/softwareContextClassifier.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
import argparse
12
import json
2-
from delft.utilities.Utilities import split_data_and_labels
3-
from delft.utilities.numpy import concatenate_or_none, shuffle_triple_with_view
3+
import time
4+
5+
import numpy as np
6+
7+
from delft.textClassification import Classifier
8+
from delft.textClassification.models import architectures
49
from delft.textClassification.reader import (
510
load_software_context_corpus_json,
611
load_software_dataset_context_corpus_json,
712
)
8-
from delft.textClassification import Classifier
9-
import argparse
10-
import time
11-
from delft.textClassification.models import architectures
12-
import numpy as np
13+
from delft.utilities.numpy import concatenate_or_none, shuffle_triple_with_view
14+
from delft.utilities.Utilities import split_data_and_labels
1315

1416
"""
1517
A multiclass classifier to be used in combination with a software mention recognition model, for characterizing
16-
the nature of the mention of software in scientific and technical literature.
18+
the nature of the mention of software in scientific and technical literature.
1719
This classifier predicts if the software introduced by a software mention in a sentence is likely:
1820
- used or not by the described work (class used)
1921
- a creation of the described work (class creation)
@@ -22,7 +24,7 @@
2224
For the software mention recognizer, see https://github.com/ourresearch/software-mentions
2325
and grobidTagger.py in the present project DeLFT.
2426
25-
Best architecture/model is fine-tuned SciBERT.
27+
Best architecture/model is fine-tuned SciBERT.
2628
"""
2729

2830
list_classes = ["used", "creation", "shared"]
@@ -375,7 +377,7 @@ def report_training_contexts(y):
375377
if architecture not in architectures:
376378
print("unknown model architecture, must be one of " + str(architectures))
377379

378-
if transformer == None and embeddings_name == None:
380+
if transformer is None and embeddings_name is None:
379381
# default word embeddings
380382
embeddings_name = "glove-840B"
381383

0 commit comments

Comments
 (0)