728x90
0.오류 사항
keras 를 통하여 정수 인코딩을 수행해야하는데 문제가 발생하였다.
현재 아나콘다 환경에서 하고있는데 해당 tensorflow.keras.preprocessing.text 을 가져올수없다고 오류가 나왔다.
from tensorflow.keras.preprocessing.text import Tokenizer
가져오기 "tensorflow.keras.preprocessing.text"을(를)
확인할 수 없습니다.PylancereportMissingImports
Tensorflow와 Keras은 각각 다음과같은 버전으로 설치되어있었다.
(base) C:\Users\asa\Desktop\code\Ai\Deep-leaning-NLP>pip show tensorflow
Name: tensorflow
Version: 2.18.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: C:\Users\asa\anaconda3\Lib\site-packages
Requires: tensorflow-intel
Required-by:
(base) C:\Users\asa\Desktop\code\Ai\Deep-leaning-NLP>pip show keras
Name: keras
Version: 3.7.0
Summary: Multi-backend Keras
Home-page:
Author:
Author-email: Keras team <keras-users@googlegroups.com>
License: Apache License 2.0
Location: C:\Users\asa\anaconda3\Lib\site-packages
Requires: absl-py, h5py, ml-dtypes, namex, numpy, optree, packaging, rich
Required-by: tensorflow_intel
1. 공식 API 문서 살펴보기
https://www.tensorflow.org/api_docs/python/tf/keras
공식문서에서 찾아보았는데 아..... preprocessing이 더이상 사용되지않는것같다.
그러면 어떻게 기존걸 사용할수있는지 찾아봐야겠다.
2.tensorflow-text ?
찾아 보니 tensorflow-text라는걸 찾았다. 근데 파이썬 버전이 3.12.4에선 tensorflow-text 설치가 안되서
3.9버전이 호환성부분에서 좋다고 해서 일단 3.9.21버전의 아나콘다로 환경을 하나 만든다.
pip install tensorflow-text
기존 Tokenizer 는 사라져서 사용할수없었지만 다음과정으로 정수 인코딩할수있었다.
import tensorflow as tf
# 텍스트 데이터
texts = ["hello my name is asa", "I am very strong and confident", "hello hello hello"]
# TextVectorization 레이어 정의
vectorizer = tf.keras.layers.TextVectorization(output_mode='int', output_sequence_length=5)
# 텍스트를 텐서로 변환 후 학습(adapt)
vectorizer.adapt(texts)
# 텍스트를 정수로 변환
vectorized_texts = vectorizer(tf.constant(texts))
print("정수화된 텍스트:")
print(vectorized_texts.numpy())
#결과
정수화된 텍스트:
[[ 2 6 5 7 10]
[ 8 12 3 4 11]
[ 2 2 2 0 0]]
https://github.com/keras-team/keras/issues/19517
728x90
'AI' 카테고리의 다른 글
[AI] 정수 인코딩 (0) | 2024.12.25 |
---|---|
[AI]한국어 토큰화 (1) | 2024.12.25 |
[AI] kss pip install 실패 오류 (0) | 2024.12.23 |