강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của tks72050746
tks72050746

câu hỏi đã được viết

Giới thiệu deep learning xử lý ngôn ngữ tự nhiên qua ví dụ NLP với TensorFlow - Từ RNN đến BERT

Thực hành 1 - Thực hành mô hình ngôn ngữ N-Gram dựa trên Count (Language Modelling)

소스코드 실행 시 에러

Viết

·

558

0

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.

from nltk.util import pad_sequence
from nltk.util import bigrams
from nltk.util import ngrams
from nltk.util import everygrams
from nltk.lm.preprocessing import pad_both_ends
from nltk.lm.preprocessing import flatten

위 구문 실행 시, 아래와 같은 에러가 뜹니다.

------------------------------------------------------------------------ ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

<ipython-input-5-db6c290979e8> in <cell line: 5>()
      3 from nltk.util import ngrams
      4 from nltk.util import everygrams
----> 5 from nltk.lm.preprocessing import pad_both_ends
      6 from nltk.lm.preprocessing import flatten

/usr/local/lib/python3.10/dist-packages/nltk/lm/counter.py in <module>
     13 from __future__ import unicode_literals
     14 
---> 15 from collections import Sequence, defaultdict
     16 
     17 from six import string_types

ImportError: cannot import name 'Sequence' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
딥러닝tensorflowNLP

Câu trả lời 2

0

AISchool님의 프로필 이미지
AISchool
Người chia sẻ kiến thức

안녕하세요~. 반갑습니다.

해당에러를 수정하기 위해서는 처음에 라이브러리를 설치하는 셀의 설치코드를

!pip install -U pip
!pip install -U dill
!pip install -U nltk==3.4

위 코드에서 아래와 같이 수정해서 실행해주시면 됩니다.

!pip install -U nltk

실습 colab에 해당 수정사항을 반영해놓았기 때문에 실습 colab을 다시 사본저장해서 실습 부탁드립니다.

좋은 하루 되세요.

감사합니다.

0

안녕하세요, 인프런 AI 인턴이에요.

에러 메시지를 보면, collections에서 Sequence 모듈을 찾을 수 없다는 것 같습니다. 이 문제를 해결하기 위해서는 collections 모듈 대신 collections.abc 모듈을 사용해야 합니다. 따라서, 아래와 같이 코드를 수정해보세요.

from nltk.util import pad_sequence
from nltk.util import bigrams
from nltk.util import ngrams
from nltk.util import everygrams
from nltk.lm.preprocessing import pad_both_ends
from nltk.lm.preprocessing import flatten
from collections.abc import Sequence

위와 같이 수정 후 실행해보세요. 질문이 해결되길 바랍니다! :)

Hình ảnh hồ sơ của tks72050746
tks72050746

câu hỏi đã được viết

Đặt câu hỏi