Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tfr MRR metric for sparse tensors crashes #331

Open
fraolBatole opened this issue Aug 31, 2022 · 0 comments
Open

tfr MRR metric for sparse tensors crashes #331

fraolBatole opened this issue Aug 31, 2022 · 0 comments

Comments

@fraolBatole
Copy link

fraolBatole commented Aug 31, 2022

Hello,

I was trying to use tfr.keras.metrics.MRRMetric() at compile time. But it crashes with a shape-related bug. Below is the code I used:

mrr_metric = tfr.keras.metrics.MRRMetric(topn=10)
def create_classifier_bert_model():    
    inputs = layers.Input((config.MAX_LEN,), dtype=tf.int64)
    sequence_output = pretrained_bert_model(inputs)
    outputs = layers.Dense(vectorize_layer.vocabulary_size(), activation="softmax")(sequence_output)
    # outputs2 = layers.Dense(vectorize_layer.vocabulary_size(), activation="softmax")(sequence_output)
    classifer_model = keras.Model(inputs, outputs=[outputs], name="prediction")
    optimizer = keras.optimizers.Adam(learning_rate=config.LR)
    classifer_model.compile(
        optimizer=optimizer, loss="sparse_categorical_crossentropy", weighted_metrics=[tf.keras.metrics.SparseCategoricalAccuracy(), mrr_metric]
    )
    return classifer_model

classifer_model = create_classifier_bert_model()
print(config.LR)
classifer_model.fit(
    mlm_ds_ft_cs,
    epochs=5,
)

The error is ValueError: Shapes (None, 64, 49934) and (None, 64) are incompatible

I have also tried to reshape (y_true, y_pred) but that causes memory issues. Is there any way to fix this issue, or is there an alternative way to compute MRR in Keras/tensorflow? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant