repp / big-phoney

Get phonetic spellings and syllable counts for any english word. Works with made-up and non-dictionary words
GNU General Public License v3.0
91 stars 13 forks source link

Dimension incompatibility Issue during Initialization #9

Open PradipKumarDas opened 3 years ago

PradipKumarDas commented 3 years ago

Hello!

Thanks for the initiative to bring this open source project.

I was on the way to give it a try, and found the error while executing the following line after importing the module successfully.

phoney = BigPhoney()

The error generated is mentioned below. Numpy 1.19.5 is installed. Any help towards resolution would be appreciated.

`--------------------------------------------------------------------------- ValueError Traceback (most recent call last)

in ----> 1 phoney = BigPhoney(preprocessors=[]) ~/anaconda3/lib/python3.7/site-packages/big_phoney/big_phoney.py in __init__(self, preprocessors) 13 self.preprocessors = [preprocessor_class() for preprocessor_class in preprocessors] 14 self.phonetic_dict = PhoneticDictionary() ---> 15 self.pred_model = PredictionModel() 16 17 def apply_preprocessors(self, input_string): ~/anaconda3/lib/python3.7/site-packages/big_phoney/prediction_model.py in __init__(self, search_width) 14 self.search_width = search_width 15 self.utils = PredictionModelUtils() ---> 16 self.training_model, self.encoder, self.decoder = self._build_model() 17 self.load_weights(PREDICTION_MODEL_WEIGHTS_PATH) 18 ~/anaconda3/lib/python3.7/site-packages/big_phoney/prediction_model.py in _build_model(self) 73 phone_embeddings = embedding_reshaper(phone_embeddings) 74 ---> 75 context = get_context(encoder_outputs, h) 76 phone_and_context = context_phone_concat([context, phone_embeddings]) 77 phone_and_context = context_phone_dense(phone_and_context) ~/anaconda3/lib/python3.7/site-packages/big_phoney/prediction_model.py in get_context(encoder_outputs, h_prev) 36 e = attn_dense2(e) 37 attention_weights = attn_softmax(e) ---> 38 context = attn_dot([attention_weights, encoder_outputs]) 39 return context 40 ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs) 950 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list): 951 return self._functional_construction_call(inputs, args, kwargs, --> 952 input_list) 953 954 # Maintains info about the `Layer.call` stack. ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list) 1089 # Check input assumptions set after layer building, e.g. input shape. 1090 outputs = self._keras_tensor_symbolic_call( -> 1091 inputs, input_masks, args, kwargs) 1092 1093 if outputs is None: ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs) 820 return nest.map_structure(keras_tensor.KerasTensor, output_signature) 821 else: --> 822 return self._infer_output_signature(inputs, args, kwargs, input_masks) 823 824 def _infer_output_signature(self, inputs, args, kwargs, input_masks): ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks) 860 # overridden). 861 # TODO(kaftan): do we maybe_build here, or have we already done it? --> 862 self._maybe_build(inputs) 863 outputs = call_fn(inputs, *args, **kwargs) 864 ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs) 2708 # operations. 2709 with tf_utils.maybe_init_scope(self): -> 2710 self.build(input_shapes) # pylint:disable=not-callable 2711 # We must set also ensure that the layer is marked as built, and the build 2712 # shape is stored since user defined build functions may not be calling ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py in wrapper(instance, input_shape) 270 if input_shape is not None: 271 input_shape = convert_shapes(input_shape, to_tuples=True) --> 272 output_shape = fn(instance, input_shape) 273 # Return shapes from `fn` as TensorShapes. 274 if output_shape is not None: ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/layers/merge.py in build(self, input_shape) 678 '%s != %s. ' % (shape1[axes[0]], shape2[axes[1]]) + 679 'Layer shapes: %s, %s. ' % (shape1, shape2) + --> 680 'Chosen axes: %s, %s' % (axes[0], axes[1])) 681 682 def _merge_function(self, inputs): ValueError: Dimension incompatibility 20 != None. Layer shapes: (None, 20, 1), (None, None, 512). Chosen axes: 1, 1 `
jdegregorio commented 2 years ago

Same error occurred for me, python 3.8 running on Ubuntu via WSL on Windows:

>>> phoney = BigPhoney()
2022-04-27 21:50:47.740152: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jdegregorio/repos/name-phonetics/.env/lib/python3.8/site-packages/big_phoney/big_phoney.py", line 15, in __init__
    self.pred_model = PredictionModel()
  File "/home/jdegregorio/repos/name-phonetics/.env/lib/python3.8/site-packages/big_phoney/prediction_model.py", line 16, in __init__
    self.training_model, self.encoder, self.decoder = self._build_model()
  File "/home/jdegregorio/repos/name-phonetics/.env/lib/python3.8/site-packages/big_phoney/prediction_model.py", line 75, in _build_model
    context = get_context(encoder_outputs, h)
  File "/home/jdegregorio/repos/name-phonetics/.env/lib/python3.8/site-packages/big_phoney/prediction_model.py", line 38, in get_context
    context = attn_dot([attention_weights, encoder_outputs])
  File "/home/jdegregorio/repos/name-phonetics/.env/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/jdegregorio/repos/name-phonetics/.env/lib/python3.8/site-packages/keras/layers/merge.py", line 693, in build
    raise ValueError(
ValueError: Incompatible input shapes: axis values 20 (at axis 1) != None (at axis 1). Full input shapes: (None, 20, 1), (None, None, 512)

Package Versions:

absl-py==1.0.0
astunparse==1.6.3
big-phoney==1.0.1
cachetools==5.0.0
certifi==2021.10.8
charset-normalizer==2.0.12
flatbuffers==2.0
gast==0.5.3
google-auth==2.6.6
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.44.0
h5py==3.6.0
idna==3.3
importlib-metadata==4.11.3
inflect==5.5.2
keras==2.8.0
Keras-Preprocessing==1.1.2
libclang==14.0.1
Markdown==3.3.6
numpy==1.22.3
oauthlib==3.2.0
opt-einsum==3.3.0
pandas==1.4.2
protobuf==3.20.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyhere==1.0.0
python-dateutil==2.8.2
pytz==2022.1
requests==2.27.1
requests-oauthlib==1.3.1
rsa==4.8
six==1.16.0
tensorboard==2.8.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow-cpu==2.8.0
tensorflow-io-gcs-filesystem==0.25.0
termcolor==1.1.0
tf-estimator-nightly==2.8.0.dev2021122109
typing-extensions==4.2.0
urllib3==1.26.9
Werkzeug==2.1.1
wrapt==1.14.0
zipp==3.8.0
samoliverschumacher commented 1 year ago

Fixed here: https://github.com/repp/big-phoney/pull/8/commits