Spaces:
Runtime error
Runtime error
saicharan2804
commited on
Commit
·
45e7e53
1
Parent(s):
ddeebbc
Changed my_metric.py to resemble accuracy.py
Browse files- my_metric.py +85 -0
my_metric.py
CHANGED
@@ -9,3 +9,88 @@ def _compute(self, list_of_generated_smiles):
|
|
9 |
results = metrics.get_all_metrics(preprocessed_smiles, test_set)
|
10 |
|
11 |
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
results = metrics.get_all_metrics(preprocessed_smiles, test_set)
|
10 |
|
11 |
return results
|
12 |
+
|
13 |
+
|
14 |
+
_DESCRIPTION = """
|
15 |
+
Moses and PyTDC metrics
|
16 |
+
"""
|
17 |
+
|
18 |
+
|
19 |
+
_KWARGS_DESCRIPTION = """
|
20 |
+
Args:
|
21 |
+
predictions (`list` of `int`): Predicted labels.
|
22 |
+
references (`list` of `int`): Ground truth labels.
|
23 |
+
normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.
|
24 |
+
sample_weight (`list` of `float`): Sample weights Defaults to None.
|
25 |
+
|
26 |
+
Returns:
|
27 |
+
All moses metrics
|
28 |
+
"""
|
29 |
+
|
30 |
+
|
31 |
+
_CITATION = """
|
32 |
+
@article{DBLP:journals/corr/abs-1811-12823,
|
33 |
+
author = {Daniil Polykovskiy and
|
34 |
+
Alexander Zhebrak and
|
35 |
+
Benjam{\'{\i}}n S{\'{a}}nchez{-}Lengeling and
|
36 |
+
Sergey Golovanov and
|
37 |
+
Oktai Tatanov and
|
38 |
+
Stanislav Belyaev and
|
39 |
+
Rauf Kurbanov and
|
40 |
+
Aleksey Artamonov and
|
41 |
+
Vladimir Aladinskiy and
|
42 |
+
Mark Veselov and
|
43 |
+
Artur Kadurin and
|
44 |
+
Sergey I. Nikolenko and
|
45 |
+
Al{\'{a}}n Aspuru{-}Guzik and
|
46 |
+
Alex Zhavoronkov},
|
47 |
+
title = {Molecular Sets {(MOSES):} {A} Benchmarking Platform for Molecular
|
48 |
+
Generation Models},
|
49 |
+
journal = {CoRR},
|
50 |
+
volume = {abs/1811.12823},
|
51 |
+
year = {2018},
|
52 |
+
url = {http://arxiv.org/abs/1811.12823},
|
53 |
+
eprinttype = {arXiv},
|
54 |
+
eprint = {1811.12823},
|
55 |
+
timestamp = {Fri, 26 Nov 2021 15:34:30 +0100},
|
56 |
+
biburl = {https://dblp.org/rec/journals/corr/abs-1811-12823.bib},
|
57 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
58 |
+
}
|
59 |
+
"""
|
60 |
+
|
61 |
+
|
62 |
+
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
63 |
+
class my_metric(evaluate.Metric):
|
64 |
+
def _info(self):
|
65 |
+
return evaluate.MetricInfo(
|
66 |
+
description=_DESCRIPTION,
|
67 |
+
citation=_CITATION,
|
68 |
+
inputs_description=_KWARGS_DESCRIPTION,
|
69 |
+
features=datasets.Features(
|
70 |
+
{
|
71 |
+
"list_of_generated_smiles": datasets.Sequence(datasets.Value("int32")),
|
72 |
+
}
|
73 |
+
if self.config_name == "multilabel"
|
74 |
+
else {
|
75 |
+
"list_of_generated_smiles": datasets.Value("int32"),
|
76 |
+
}
|
77 |
+
),
|
78 |
+
reference_urls=["https://github.com/molecularsets/moses"],
|
79 |
+
)
|
80 |
+
|
81 |
+
def _compute(self, list_of_generated_smiles):
|
82 |
+
test_set = moses.get_dataset('test')
|
83 |
+
preprocessed_smiles = [smile for smile in list_of_generated_smiles if moses.utils.canonicalize_smiles(smile)]
|
84 |
+
|
85 |
+
results = metrics.get_all_metrics(preprocessed_smiles, test_set)
|
86 |
+
|
87 |
+
return {
|
88 |
+
"results": results
|
89 |
+
}
|
90 |
+
|
91 |
+
# def _compute(self, predictions, references, normalize=True, sample_weight=None):
|
92 |
+
# return {
|
93 |
+
# "accuracy": float(
|
94 |
+
# accuracy_score(references, predictions, normalize=normalize, sample_weight=sample_weight)
|
95 |
+
# )
|
96 |
+
# }
|