nlp-with-transformers / notebooks

Jupyter notebooks for the Natural Language Processing with Transformers book
https://transformersbook.com/
Apache License 2.0
3.7k stars 1.13k forks source link

Error with numpy dependencies #138

Open LilAntonioC opened 1 month ago

LilAntonioC commented 1 month ago

Information

The problem arises in chapter:

Describe the bug

After trying to run it fails `def extract_hidden_states(batch):

Place model inputs on the GPU

inputs = {k:v.to(device) for k,v in batch.items() 
          if k in tokenizer.model_input_names}
# Extract last hidden states
with torch.no_grad():
    last_hidden_state = model(**inputs).last_hidden_state
# Return vector for [CLS] token
return {"hidden_state": last_hidden_state[:,0].cpu().numpy()}

emotions_hidden = emotions_encoded.map(extract_hidden_states, batched=True) ` I tried on my machine and also on colab, and both seem to have the same error, I tried to modified the setup, but for some reason I cannot change the numpy library to an older version, I don't know someone has the same error

To Reproduce

Steps to reproduce the behavior:

  1. Run the cell emotions_hidden = emotions_encoded.map(extract_hidden_states, batched=True)

the error module 'numpy' has no attribute 'object'. np.object was a deprecated alias for the builtin object. To avoid this error in existing code, use object by itself. Doing this will not modify any behavior and is safe. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:

Expected behavior

Run the cell as expected an preprocess all the dataset