text icon indicating copy to clipboard operation
text copied to clipboard

Transformers Notebook does not work on Google Colab

Open drewm8080 opened this issue 1 year ago • 5 comments

Gets stuck on this block of code

`embed_pt = PositionalEmbedding(vocab_size=tokenizers.pt.get_vocab_size(), d_model=512) embed_en = PositionalEmbedding(vocab_size=tokenizers.en.get_vocab_size(), d_model=512)

pt_emb = embed_pt(pt) en_emb = embed_en(en`

drewm8080 avatar Mar 30 '24 05:03 drewm8080

For this code:

https://www.tensorflow.org/text/tutorials/transformer

drewm8080 avatar Mar 30 '24 16:03 drewm8080

Hi, adding .numpy() after the get_vocab_size() functions will solve your issue!

embed_pt = PositionalEmbedding(vocab_size=tokenizers.pt.get_vocab_size().numpy(), d_model=512) embed_en = PositionalEmbedding(vocab_size=tokenizers.en.get_vocab_size().numpy(), d_model=512)

MatteoManzari avatar Apr 03 '24 13:04 MatteoManzari

I got error in the importing parts:


AttributeError Traceback (most recent call last) in <cell line: 26>() 24 25 import tensorflow as tf ---> 26 import tensorflow_hub as hub 27 import tensorflow_text as text 28 import tensorflow_datasets as tfds

13 frames /usr/local/lib/python3.10/dist-packages/tf_keras/src/saving/legacy/saved_model/load_context.py in 66 67 ---> 68 tf.internal.register_load_context_function(in_load_context) 69

AttributeError: module 'tensorflow._api.v2.compat.v2.internal' has no attribute 'register_load_context_function'

jemmyfebryan avatar Apr 05 '24 10:04 jemmyfebryan

I got the same problem on May 1, 2024. I am struggling to understand why these tutorials are not tested before releasing code updates. IMHO these frequent issues create a sense of frustration and loss of faith in the tool.

JuanVargas avatar May 01 '24 12:05 JuanVargas

Adding .numpy() worked for me, posting in the hopes that the notebook can be corrected and the next person can save themselves the hour I wasted trying to fix myself.

garricklw avatar May 28 '24 21:05 garricklw