question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'tuple' object doesn't have attribute `as_list`

See original GitHub issue

Environment info

- `transformers` version: 4.12.3
- Platform: Linux-5.10.0-9-amd64-x86_64-with-glibc2.2.5
- Python version: 3.8.12
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): 2.6.2 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no

Who can help

Information

I’m sorry for not being able to give more information about this, since I don’t directly works with the model. I believe the model is bert-base-multilingual-cased. I’m trying to create a chat bot with Rasa.

To reproduce

Steps to reproduce the behavior: Run the chat bot, either use rasa shell or rasa run --enable-api and curl to chat with the bot.

Error log:

2021-11-09 08:08:34 ERROR    rasa.core.channels.rest  - An exception occured while handling user message 'hello'.
Traceback (most recent call last):
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/channels/rest.py", line 120, in receive
    await on_new_message(
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/channels/channel.py", line 89, in handler
    await app.agent.handle_message(message)
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/agent.py", line 577, in handle_message
    return await processor.handle_message(message)
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/processor.py", line 96, in handle_message
    tracker = await self.log_message(message, should_save_tracker=False)
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/processor.py", line 327, in log_message
    await self._handle_message_with_tracker(message, tracker)
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/processor.py", line 594, in _handle_message_with_tracker
    parse_data = await self.parse_message(message, tracker)
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/processor.py", line 572, in parse_message
    parse_data = await self.interpreter.parse(
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/core/interpreter.py", line 145, in parse
    result = self.interpreter.parse(text)
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/nlu/model.py", line 470, in parse
    component.process(message, **self.context)
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/nlu/utils/hugging_face/hf_transformers.py", line 749, in process
    self._get_docs_for_batch(
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/nlu/utils/hugging_face/hf_transformers.py", line 678, in _get_docs_for_batch
    ) = self._get_model_features_for_batch(
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/nlu/utils/hugging_face/hf_transformers.py", line 609, in _get_model_features_for_batch
    sequence_hidden_states = self._compute_batch_sequence_features(
  File "/home/grooo/.local/lib/python3.8/site-packages/rasa/nlu/utils/hugging_face/hf_transformers.py", line 460, in _compute_batch_sequence_features
    model_outputs = self.model(
  File "/home/grooo/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 1037, in __call__
    outputs = call_fn(inputs, *args, **kwargs)
  File "/home/grooo/.local/lib/python3.8/site-packages/transformers/models/bert/modeling_tf_bert.py", line 1129, in call
    outputs = self.bert(
  File "/home/grooo/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 1037, in __call__
    outputs = call_fn(inputs, *args, **kwargs)
  File "/home/grooo/.local/lib/python3.8/site-packages/transformers/models/bert/modeling_tf_bert.py", line 803, in call
    attention_mask_shape = shape_list(inputs["attention_mask"])
  File "/home/grooo/.local/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 1831, in shape_list
    static = tensor.shape.as_list()
AttributeError: 'tuple' object has no attribute 'as_list'

Line 1831 of transformers/modeling_tf_utils.py:

static = tensor.shape.as_list()

After printing out stuff in transformers/modeling_tf_utils.py, I found out that sometime tensor is a numpy array, therefore tensor.shape is a tuple and indeed doesn’t have as_list.

Proposed fix:

    static = tensor.shape
    if type(static) == tuple:
        static = list(static)
    else:
        static = static.as_list()

Expected behavior

No error.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ndgnuhcommented, Nov 16, 2021

Sorry but I have a potato computer and I’m too lazy for the full PR procedure 😄

1reaction
LysandreJikcommented, Nov 15, 2021

Nice catch, do you want to open a PR with the fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'tuple' object has no attribute 'append'
In the line: Jobs = (). you create a tuple . A tuple is immutable and has no methods to add, remove or...
Read more >
AttributeError tuple object has no attribute append - Solved
python tutorial: #codefix #python #python tutorialAttributeError ' tuple ' object has no attribute 'append' - SolvedIn this video i have ...
Read more >
Python AttributeError: 'tuple' object has no attribute
The error AttributeError: 'tuple' object has no attribute is caused when treating the values within a tuple as named attributes. The error also...
Read more >
5. Data Structures — Python 3.11.1 documentation
More on Lists: The list data type has some more methods. ... line 1, in <module> TypeError: 'tuple' object does not support item...
Read more >
Update tuples in Python (Add, change, remove items in tuples)
t[0] = 100 # TypeError: 'tuple' object does not support item ... t.append(100) # AttributeError: 'tuple' object has no attribute 'append'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found