blueoil icon indicating copy to clipboard operation
blueoil copied to clipboard

Avoid the implementation depended on the order of dict

Open hadusam opened this issue 5 years ago • 1 comments

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

hadusam avatar Dec 24 '19 02:12 hadusam

the file seems to be moved to blueoil/cmd/train.py

lm-noshiro avatar May 26 '20 09:05 lm-noshiro