Coder Social home page Coder Social logo

Tensorflow 오류 about kb-albert HOT 10 CLOSED

ksunw0209 avatar ksunw0209 commented on September 6, 2024
Tensorflow 오류

from kb-albert.

Comments (10)

sackoh avatar sackoh commented on September 6, 2024

안녕하세요
의견 남겨주셔서 감사드립니다.

우선 보내주신 코드의 에러를 보면 from_pretrained 시에 적절한 인자를 주지 못해서 생긴 이슈인 것 같습니다.

이슈 발생 원인

TensorFlow로 모델을 불러올 때 지정해준 경로에 tf_model.h5가 없어서 오류 발생.

해결 방법

pytorch_model.bin으로부터 모델 로딩
from_pretrained 시에 from_pt=True 지정하여 로딩

  • 예제
    tf_model = TFAlbertModel.from_pretrained(kb_albert_model_path, from_pt=True)

from kb-albert.

ksunw0209 avatar ksunw0209 commented on September 6, 2024

from_pt = True로 설정했는데도 발생한 오류입니다ㅠㅠ

from kb-albert.

sackoh avatar sackoh commented on September 6, 2024

혹시 코드 전문을 보여주실 수 있으신가요?

from kb-albert.

ksunw0209 avatar ksunw0209 commented on September 6, 2024

README 4번 코드 그대로 사용했고 kb_albert_model_path = "model"만 추가했습니다.

from kb-albert.

ksunw0209 avatar ksunw0209 commented on September 6, 2024
from transformers import TFAlbertModel
from tokenization_kbalbert import KbAlbertCharTokenizer

kb_albert_model_path = "model"
# Load Tokenizer
tokenizer = KbAlbertCharTokenizer.from_pretrained(kb_albert_model_path)

# Load Model from pytorch checkpoint
tf_model = TFAlbertModel.from_pretrained(kb_albert_model_path, from_pt=True)

# Load Model from tensorflow checkpoint
tf_model = TFAlbertModel.from_pretrained(kb_albert_model_path)

# inference text input to sentence vector of last layer
text = '방카슈랑스는 금융의 겸업화 추세에 부응하여 금융산업의 선진화를 도모하고 금융소비자의 편익을 위하여 도입되었습니다.'
tf_inputs = tokenizer(text, return_tensors='tf')
tf_outputs = tf_model(tf_inputs)[0]
print(tf_outputs)
# tf.Tensor(
# [[[-0.24243946 -0.11504214  0.17393401 ... -0.11044239 -0.25206116
#    -0.23426072]
#  [-0.2397561   0.6024074   0.2139548  ... -0.10028014 -0.08111599
#   -0.33866274]
#  [-0.06281117  0.17218252 -0.29536933 ...  0.02597588 -0.12882982
#   -0.03670263]
#  ...
#  [ 0.04058527 -0.04625399  0.017508   ... -0.00161684 -0.06357272
#    0.04015562]
#  [ 0.11111088 -0.2124992   0.01409155 ...  0.13796085 -0.12516738
#   -0.08492979]
#  [ 0.04058535 -0.04625027  0.01748611 ... -0.0016344  -0.06360036
#    0.04017936]]], shape=(1, 54, 768), dtype=float32)

from kb-albert.

ksunw0209 avatar ksunw0209 commented on September 6, 2024

image
참고로 파일 디렉토리는 위와 같고 돌리려는 코드는 ex.py입니다.

from kb-albert.

sackoh avatar sackoh commented on September 6, 2024
from transformers import TFAlbertModel
from tokenization_kbalbert import KbAlbertCharTokenizer

kb_albert_model_path = "model"
# Load Tokenizer
tokenizer = KbAlbertCharTokenizer.from_pretrained(kb_albert_model_path)

# Load Model from pytorch checkpoint
tf_model = TFAlbertModel.from_pretrained(kb_albert_model_path, from_pt=True)

# Load Model from tensorflow checkpoint
tf_model = TFAlbertModel.from_pretrained(kb_albert_model_path)

# inference text input to sentence vector of last layer
text = '방카슈랑스는 금융의 겸업화 추세에 부응하여 금융산업의 선진화를 도모하고 금융소비자의 편익을 위하여 도입되었습니다.'
tf_inputs = tokenizer(text, return_tensors='tf')
tf_outputs = tf_model(tf_inputs)[0]
print(tf_outputs)
# tf.Tensor(
# [[[-0.24243946 -0.11504214  0.17393401 ... -0.11044239 -0.25206116
#    -0.23426072]
#  [-0.2397561   0.6024074   0.2139548  ... -0.10028014 -0.08111599
#   -0.33866274]
#  [-0.06281117  0.17218252 -0.29536933 ...  0.02597588 -0.12882982
#   -0.03670263]
#  ...
#  [ 0.04058527 -0.04625399  0.017508   ... -0.00161684 -0.06357272
#    0.04015562]
#  [ 0.11111088 -0.2124992   0.01409155 ...  0.13796085 -0.12516738
#   -0.08492979]
#  [ 0.04058535 -0.04625027  0.01748611 ... -0.0016344  -0.06360036
#    0.04017936]]], shape=(1, 54, 768), dtype=float32)

코드를 보시면
tf_model = TFAlbertModel.from_pretrained(kb_albert_model_path)

부분이 다시 실행되는데 여기에는 from_pt가 없어서 에러가 발생했습니다.
코드 11, 12번째 줄을 삭제하시면 될 것 같습니다.

from kb-albert.

ksunw0209 avatar ksunw0209 commented on September 6, 2024

앗 그렇네요... 감사합니다!!

from kb-albert.

sackoh avatar sackoh commented on September 6, 2024

현재 올라와 있는 README는 예시로 tensorflow checkpoint에서도 불러올 수 있다는 예시로 작성했는데

이번에 AI 챌린지로 제공해드린 버전에서는 tf_model.h5가 없어서 혼란을 드렸네요. 죄송합니다.

README는 수정하도록 하겠습니다.

from kb-albert.

ksunw0209 avatar ksunw0209 commented on September 6, 2024

저야말로 사소한걸로 계속 질문해서 죄송합니다...
친절한 답변 감사합니다!

from kb-albert.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.