C3W1 Assignment 1: Deep N-grams

When creating a post, please add:

  • Week # must be added in the tags option of the post.
  • Link to the classroom item you are referring to:
  • Description (include relevant info but please do not post solution code or your entire notebook)
    Deep N-grams | Coursera

Getting value error while executing

# UNGRADED CLASS: GenerativeModel
class GenerativeModel(tf.keras.Model):


Suspecting issue with passing null value , could you please help to resolve.

print(gen.generate_n_chars(32, " "), '\n\n' + '_'*80)

# UNIT TEST
# Fix the seed to get replicable results for testing
tf.random.set_seed(272)
gen = GenerativeModel(model, vocab, temperature=0.5)

print(gen.generate_n_chars(32, " "), '\n\n' + '_'*80)
print(gen.generate_n_chars(32, "Dear"), '\n\n' + '_'*80)
print(gen.generate_n_chars(32, "KING"), '\n\n' + '_'*80)


Error:
###################

ValueError                                Traceback (most recent call last)
Cell In[108], line 6
      3 tf.random.set_seed(272)
      4 gen = GenerativeModel(model, vocab, temperature=0.5)
----> 6 print(gen.generate_n_chars(32, " "), '\n\n' + '_'*80)
      7 print(gen.generate_n_chars(32, "Dear"), '\n\n' + '_'*80)
      8 print(gen.generate_n_chars(32, "KING"), '\n\n' + '_'*80)

Cell In[107], line 64, in GenerativeModel.generate_n_chars(self, num_chars, prefix)
     62 result = [next_char]
     63 for n in range(num_chars):
---> 64     next_char, states = self.generate_one_step(next_char, states=states)
     65     result.append(next_char)
     67 return tf.strings.join(result)[0].numpy().decode('utf-8')

File /usr/local/lib/python3.8/dist-packages/tensorflow/python/util/traceback_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    151 except Exception as e:
    152   filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153   raise e.with_traceback(filtered_tb) from None
    154 finally:
    155   del filtered_tb

File /tmp/__autograph_generated_file87tl4msj.py:11, in outer_factory.<locals>.inner_factory.<locals>.tf__generate_one_step(self, inputs, states)
      9 do_return = False
     10 retval_ = ag__.UndefinedReturnValue()
---> 11 input_ids = ag__.converted_call(ag__.ld(line_to_tensor), (ag__.ld(self).inputs, ag__.ld(self).vocab), None, fscope)
     12 (predicted_logits, states) = ag__.converted_call(ag__.ld(self).model, (ag__.converted_call(ag__.ld(tf).expand_dims, (ag__.ld(input_ids), 0), None, fscope),), dict(states=ag__.ld(states), return_state=True), fscope)
     13 predicted_logits = ag__.ld(predicted_logits)[0, (- 1), :]

File /tmp/__autograph_generated_filen5auk7bg.py:11, in outer_factory.<locals>.inner_factory.<locals>.tf__line_to_tensor(line, vocab)
      9 do_return = False
     10 retval_ = ag__.UndefinedReturnValue()
---> 11 chars = ag__.converted_call(ag__.ld(tf).strings.unicode_split, (ag__.ld(line),), dict(input_encoding='UTF-8'), fscope)
     12 ids = ag__.converted_call(ag__.converted_call(ag__.ld(tf).keras.layers.StringLookup, (), dict(vocabulary=ag__.converted_call(ag__.ld(list), (ag__.ld(vocab),), None, fscope), mask_token=None), fscope), (ag__.ld(chars),), None, fscope)
     13 try:

ValueError: in user code:

    File "/tmp/ipykernel_14/4281713250.py", line 34, in generate_one_step  *
        input_ids = line_to_tensor(self.inputs, self.vocab)
    File "/tmp/ipykernel_14/2955566712.py", line 16, in line_to_tensor  *
        chars = tf.strings.unicode_split(line, input_encoding='UTF-8')

    ValueError: None values not supported.
1 Like

Hi!
It seems like you are using the object’s inputs (self) (which do not exist in the constructor function) but you have to use the one passed in the function generate_one_step.

1 Like