blueoil
blueoil copied to clipboard
Avoid the implementation depended on the order of dict
In lmnet/executor/train.py
and lmnet/executor/evaluate.py
, we have implementations implicit depended on the order of dict
object as follows.
https://github.com/blue-oil/blueoil/blob/8055a4a29618d79cf70d068d5aac5af7a4f3351e/lmnet/executor/train.py#L127
https://github.com/blue-oil/blueoil/blob/8055a4a29618d79cf70d068d5aac5af7a4f3351e/lmnet/executor/train.py#L238-L239
metrics_placeholders
and metrics_values
are the lists generated by metrics_ops_dict
, but it is not sure that the order(key) is the same, this implementation depends on the order of dict
implicitly.
In Python
< 3.7, the order of dict
is arbitrary on python language specification.
Fortunately, in CPython 3.6, the order of dict
is not arbitrary but this is the implementation specification not the language specification of 3.6.
The order-preserving aspect of this new implementation is considered an implementation detail and should not be relied upon ...
Python 3.6 new-dict-implementation
So it is better to avoid such implementations.
Refs from stackoverflow: Why is the order in dictionaries and sets arbitrary? The order of keys in dictionaries
the file seems to be moved to blueoil/cmd/train.py