Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scispacy/candidate_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(
[ann_index, tfidf_vectorizer, ann_concept_aliases_list, kb]
):
raise ValueError(
"You cannot pass both a name argument and other constuctor arguments."
"You cannot pass both a name argument and other constructor arguments."
)

# Set the name to the default, after we have checked
Expand Down
43 changes: 19 additions & 24 deletions scispacy/data_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,12 @@ def _cleanup_dir(dir_path: str):
corpus = os.path.join(resolved_directory_path, expected_names[0])
examples = med_mentions_example_iterator(corpus)

train_ids = {
x.strip()
for x in open(os.path.join(resolved_directory_path, expected_names[4]))
}
dev_ids = {
x.strip()
for x in open(os.path.join(resolved_directory_path, expected_names[2]))
}
test_ids = {
x.strip()
for x in open(os.path.join(resolved_directory_path, expected_names[3]))
}
with open(os.path.join(resolved_directory_path, expected_names[4])) as train_file:
train_ids = {x.strip() for x in train_file}
with open(os.path.join(resolved_directory_path, expected_names[2])) as dev_file:
dev_ids = {x.strip() for x in dev_file}
with open(os.path.join(resolved_directory_path, expected_names[3])) as test_file:
test_ids = {x.strip() for x in test_file}

train_examples = []
dev_examples = []
Expand Down Expand Up @@ -299,19 +293,20 @@ def read_ner_from_tsv(filename: str) -> List[SpacyNerExample]:
"""
spacy_format_data = []
examples: List[Tuple[str, str]] = []
for line in open(cached_path(filename)):
line = line.strip()
if line.startswith("-DOCSTART-"):
continue
# We have reached the end of a sentence.
if not line:
if not examples:
with open(cached_path(filename)) as tsv_file:
for line in tsv_file:
line = line.strip()
if line.startswith("-DOCSTART-"):
continue
spacy_format_data.append(_handle_sentence(examples))
examples = []
else:
word, entity = line.split("\t")
examples.append((word, entity))
# We have reached the end of a sentence.
if not line:
if not examples:
continue
spacy_format_data.append(_handle_sentence(examples))
examples = []
else:
word, entity = line.split("\t")
examples.append((word, entity))
if examples:
spacy_format_data.append(_handle_sentence(examples))

Expand Down
2 changes: 1 addition & 1 deletion scispacy/hearst_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
{"LEMMA": "which"},
{"LEMMA": "look"},
{"LEMMA": "like"},
hyponym,
hypernym,
],
"position": "last",
},
Expand Down
4 changes: 2 additions & 2 deletions scispacy/per_class_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def __call__(
gold_spans = copy.copy(gold_spans)
predicted_spans = copy.copy(predicted_spans)
untyped_gold_spans = {(x[0], x[1]) for x in gold_spans}
untyped_predicted_spans = {(x[0], x[1]) for x in predicted_spans}

for untyped_span, span in zip(untyped_predicted_spans, predicted_spans):
for span in predicted_spans:
untyped_span = (span[0], span[1])
if span in gold_spans:
self._true_positives[span[2]] += 1
gold_spans.remove(span)
Expand Down
3 changes: 2 additions & 1 deletion scispacy/train_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def evaluate_ner(

metrics = scorer.get_metric()
if dump_path is not None:
json.dump(metrics, open(dump_path, "a+"))
with open(dump_path, "a+") as metrics_file:
json.dump(metrics, metrics_file)
for name, metric in metrics.items():
if "overall" in name or "untyped" in name or verbose:
print(f"{name}: \t\t {metric}")
Expand Down