Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow에서 사용가능한 모델도 배포하실 예정이 있으신가요? #6

Closed
Luzzer opened this issue Jul 4, 2020 · 4 comments

Comments

@Luzzer
Copy link

Luzzer commented Jul 4, 2020

안녕하세요. @monologg 님, 자연어처리를 공부중인 학생입니다.
항상 좋은 글들과 모델들을 공유해주셔서 감사드립니다.

이번에 공유해주신 KoELECTRA 모델을 사용해서 fine-tuning을 진행해보고 싶은데요.
기존 사용하던 코드가 Tensorflow로 구현되어있어 Tensorflow 버전용 모델도 공유하실 예정이 있으신지 궁금합니다.
아니면 pytorch 모델을 tensorflow 모델로 바꾸어 사용할 수 있는 방법이 따로 있는지 궁금합니다.

@Luzzer Luzzer closed this as completed Jul 4, 2020
@Luzzer Luzzer reopened this Jul 4, 2020
@monologg
Copy link
Owner

monologg commented Jul 5, 2020

안녕하세요:)

@Luzzer 님이 사용하신 Tensorflow 버전이 v1인지 v2인지를 모르겠네요ㅠ

1. Tensorflow v2

transformers 라이브러리는 pytorch와 tensorflow 2를 모두 지원합니다.

from transformers import TFElectraModel, ElectraTokenizer

model = TFElectraModel.from_pretrained("monologg/koelectra-base-discriminator", from_pt=True)
tokenizer = ElectraTokenizer.from_pretrained("monologg/koelectra-base-discriminator")

text = "오늘 날씨는 맑아요"

encoded_input = tokenizer.encode_plus(
    text=text,
    add_special_tokens=True,
    return_tensors="tf"
)

output = model(
    inputs=encoded_input["input_ids"],
    token_type_ids=encoded_input["token_type_ids"],
    attention_mask=encoded_input["attention_mask"]
)

위에서 주의할 점은 model을 로딩할 때 from_pt=True라는 인자를 주어야 한다는 것입니다.
해당 부분에 대한 것은 README에 추가하도록 하겠습니다.

2. Tensorflow v1

(아마 @Luzzer 님이 v1 기준으로 코드를 짜셨을 것으로 생각됩니다.)

v1 체크포인트는 빠른 시일 내에 구글 드라이브에 업로드해서 README에 업데이트 하도록 하겠습니다.

@Luzzer
Copy link
Author

Luzzer commented Jul 5, 2020

답변 감사드립니다. :)
코드는 v1 으로 구현이 되어 있습니다.
모니터링 하고 있다가 업로드 해주실 때 사용하도록 하겠습니다.
최신 모델을 사용할 수 있게끔 공유해주시고, 공부에도 많은 도움을 주셔서 너무 감사드립니다. 👍

@Luzzer Luzzer closed this as completed Jul 5, 2020
@monologg
Copy link
Owner

monologg commented Jul 7, 2020

@Luzzer

안녕하세요!

TF v1 ckpt 모두 google drive에 업로드 했습니다. (관련 README Link)

공식 레포의 코드에 위의 ckpt를 이용하여 돌렸을 때 문제는 없었습니다. (hparams에서 vocab_size만 32200으로 변경하여 finetuning 코드를 돌리면 될 것 같습니다)

혹시나 이슈가 생기면 알려주세요:)

@monologg
Copy link
Owner

monologg commented Jul 7, 2020

@Luzzer

구글 드라이브 권한이 전체 공개가 아니었네요...방금 수정했습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants