You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
model = anago.Sequence()
model.fit(x_train, y_train)
with my own data with just two different labels, but it gave an exception with a keras error on mismatching shape of X and y. It turned out that my data had blocks of sentences of length > 32, where each sentence had a single word and each label was the same.
The following fix worked for me:
--- a/anago/preprocessing.py
+++ b/anago/preprocessing.py
@@ -107,7 +107,8 @@ class IndexTransformer(BaseEstimator, TransformerMixin):
# >>> to_categorical([[1]], num_classes=4).shape
# (1, 4)
# So, I expand dimensions when len(y.shape) == 2.
- y = y if len(y.shape) == 3 else np.expand_dims(y, axis=0)
+ #y = y if len(y.shape) == 3 else np.expand_dims(y, axis=0)
+ y = y if len(y.shape) == 3 else y.reshape(y.shape+(1,)).transpose([0,2,1])
return features, y
else:
return features
@@ -237,7 +238,8 @@ class ELMoTransformer(IndexTransformer):
# >>> to_categorical([[1]], num_classes=4).shape
# (1, 4)
# So, I expand dimensions when len(y.shape) == 2.
- y = y if len(y.shape) == 3 else np.expand_dims(y, axis=0)
+ #y = y if len(y.shape) == 3 else np.expand_dims(y, axis=0)
+ y = y if len(y.shape) == 3 else y.reshape(y.shape+(1,)).transpose([0,2,1])
return features, y
else:
return features
This is due to inconsistency in keras to_categorical, but np.expand_dims used in the current code does not seem to solve this.
I tried
with my own data with just two different labels, but it gave an exception with a keras error on mismatching shape of X and y. It turned out that my data had blocks of sentences of length > 32, where each sentence had a single word and each label was the same.
The following fix worked for me:
This is due to inconsistency in keras
to_categorical
, butnp.expand_dims
used in the current code does not seem to solve this.The text was updated successfully, but these errors were encountered: