keras-team / keras-io

Keras documentation, hosted live at keras.io
Apache License 2.0
2.78k stars 2.04k forks source link

Main KerasNLP tutorial error: got an unexpected keyword argument 'mask_positions' #1446

Open gustheman opened 1 year ago

gustheman commented 1 year ago

I'm was playing with KerasNLP and found an issue on the main tutorial

https://keras.io/guides/keras_nlp/getting_started/

In the expert part, on the pretraining model cell, I'm getting an error in the line:

outputs = mlm_head(sequence, mask_positions=inputs["mask_positions"])

Error:


/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py:639: UserWarning: Input dict contained keys ['mask_positions'] which did not match any model input. They will be ignored by the model. inputs = self._flatten_to_reference_inputs(inputs)

TypeError Traceback (most recent call last)

in () 26 # We use the input token embedding to project from our encoded vectors to 27 # vocabulary logits, which has been shown to improve training efficiency. ---> 28 outputs = mlm_head(sequence, mask_positions=inputs["mask_positions"]) 29 30 # Define and compile our pretraining model. 1 frames /usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py in converted_call(f, args, kwargs, caller_fn_scope, options) 437 try: 438 if kwargs is not None: --> 439 result = converted_f(*effective_args, **kwargs) 440 else: 441 result = converted_f(*effective_args) TypeError: in user code: TypeError: outer_factory..inner_factory..tf__call() got an unexpected keyword argument 'mask_positions' ---------------------------------------------- I'm running the example on public Colab without any code changes the keras_nlp version is 0.6.0
sampathweb commented 1 year ago

Thanks for reporting the issue. I confirm that Release 0.6.0 had the argument named as masked_positions https://github.com/keras-team/keras-nlp/blob/r0.6/keras_nlp/layers/modeling/masked_lm_head.py#L180. This is changed in main branch to mask_positions, so checking with @mattdangerw to see if we need to update the tutorial or should we do a new release of Keras-NLP to fix it.

sampathweb commented 1 year ago

After discussing with Matt, I realized that we need to update the arg in tutorial to masked_positions. Will update with a PR.

mattdangerw commented 1 year ago

Actually just noticed this was actually us working around a bug in keras-core. Just applied a fix. https://github.com/keras-team/keras-core/pull/632

So I think we can restore the original name here. https://github.com/keras-team/keras-nlp/pull/1185

Let's fix this in 0.6.1, and release that soon!