tensorflow / neural-structured-learning

Training neural models with structured signals.
https://www.tensorflow.org/neural_structured_learning
Apache License 2.0
980 stars 189 forks source link

AttributeError: module 'collections' has no attribute 'Mapping' - Python v3.10.4, nsl v1.3.1 #120

Closed klanderson closed 2 years ago

klanderson commented 2 years ago

I think this needs to be changed for Python 3.10 compatibility. There error I'm getting is from neural_structured_learning\keras\adversarial_regularization.py:236

File c:\Users\xxx\Anaconda3\envs\niq_model\lib\site-packages\neural_structured_learning\keras\adversarial_regularization.py:236, in _prepare_loss_fns(loss, output_names)
    [234](file:///c%3A/Users/xxx/Anaconda3/envs/niq_model/lib/site-packages/neural_structured_learning/keras/adversarial_regularization.py?line=233) """Converts `loss` to a list of per-output loss functions or objects."""
    [235](file:///c%3A/Users/xxx/Anaconda3/envs/niq_model/lib/site-packages/neural_structured_learning/keras/adversarial_regularization.py?line=234) # losses for multiple outputs indexed by name
--> [236](file:///c%3A/Users/xxx/Anaconda3/envs/niq_model/lib/site-packages/neural_structured_learning/keras/adversarial_regularization.py?line=235) if isinstance(loss, collections.Mapping):
    [237](file:///c%3A/Users/xxx/Anaconda3/envs/niq_model/lib/site-packages/neural_structured_learning/keras/adversarial_regularization.py?line=236)   for name in output_names:
    [238](file:///c%3A/Users/xxx/Anaconda3/envs/niq_model/lib/site-packages/neural_structured_learning/keras/adversarial_regularization.py?line=237)     if name not in loss:

Here is the Python 3.9 deprecation warning text:

Using or importing the ABCs
  from 'collections' instead of from 'collections.abc' is deprecated
  since Python 3.3, and in 3.10 it will stop working
csferng commented 2 years ago

Thanks for pointing out the issue! We will fix this in the next version. (PR is welcome!)