728x90

KoBERT 모델을 이용하다가 초기에 필요 패키지를 설치하고, 각종 모듈들을 임포트 해주다가 아래와 같은 에러가 발생했다.

 

import torch
from torch import nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader
import gluonnlp as nlp
import numpy as np
from tqdm import tqdm, tqdm_notebook

 

/usr/local/lib/python3.10/dist-packages/mxnet/numpy/utils.py:37: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar. bool = onp.bool

---------------------------------------------------------------------------

AttributeError Traceback (most recent call last)

in ()

4 import torch.optim as optim

5 from torch.utils.data import Dataset, DataLoader

----> 6 import gluonnlp as nlp

7 import numpy as np

8 import pandas as pd

 

10 frames /usr/local/lib/python3.10/dist-packages/numpy/__init__.py in __getattr__(attr)

317

318 if attr in __former_attrs__: --> 319 raise AttributeError(__former_attrs__[attr])

320

321 if attr == 'testing':

 

AttributeError: module 'numpy' has no attribute 'bool'. `np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

 

NumPy 1.20.0 Release Notes — NumPy v2.1.dev0 Manual

NumPy 1.20.0 Release Notes This NumPy release is the largest so made to date, some 684 PRs contributed by 184 people have been merged. See the list of highlights below for more details. The Python versions supported for this release are 3.7-3.9, support fo

numpy.org

 

이는 Numpy 버전이 맞지 않아 생긴 오류이다.

Numpy 최근 버전에는 np.bool 속성이 제거되었는데, 내가 사용한 Numpy 버전은 업그레이드 된 버전이라 임포트 할 수 없었던 것이다.

 

따라서 Numpy를 다운그레이드 해주면 문제가 해결된다.

# import gluonnlp as nlp 오류 -> numpy downgrade 필요
pip install numpy==1.23.1

 

728x90

+ Recent posts