- NLP Engineer, contributing on Korean NLP with Open Source!
monologg / distilkobert Goto Github PK
View Code? Open in Web Editor NEWDistillation of KoBERT from SKTBrain (Lightweight KoBERT)
License: Apache License 2.0
Distillation of KoBERT from SKTBrain (Lightweight KoBERT)
License: Apache License 2.0
μλ νμΈμ.
μμ±ν΄μ£Όμ DistilKoBERTμ ν΅ν΄μ λ€μ΄λ² κ°μ±λΆμ μ½λλ₯Ό ꡬνμΈ λμ νλ€. μλμ κ°μ μ€λ₯μ μ§λ©΄νμ΅λλ€. μ½λλ μ¬μ€μ KoBERTμ μλ μ½λλ₯Ό μ¬μ©νμ΅λλ€.
RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_index_select
for e in range(num_epochs):
train_acc = 0.0
test_acc = 0.0
model.train()
for batch_id, (token_ids, valid_length, segment_ids, label) in enumerate(tqdm_notebook(train_dataloader)):
optimizer.zero_grad()
token_ids = token_ids.long().to(device)
segment_ids = segment_ids.long().to(device)
valid_length= valid_length
label = label.long().to(device)
out = model(token_ids, valid_length, segment_ids)
loss = loss_fn(out, label)
loss.backward()
torch.nn.utils.clip_grad_norm_(model.parameters(), max_grad_norm)
optimizer.step()
scheduler.step() # Update learning rate schedule
train_acc += calc_accuracy(out, label)
if batch_id % log_interval == 0:
print("epoch {} batch id {} loss {} train acc {}".format(e+1, batch_id+1, loss.data.cpu().numpy(), train_acc / (batch_id+1)))
print("epoch {} train acc {}".format(e+1, train_acc / (batch_id+1)))
model.eval()
for batch_id, (token_ids, valid_length, segment_ids, label) in enumerate(tqdm_notebook(test_dataloader)):
token_ids = token_ids.long().to(device)
segment_ids = segment_ids.long().to(device)
valid_length= valid_length
label = label.long().to(device)
out = model(token_ids, valid_length, segment_ids)
test_acc += calc_accuracy(out, label)
print("epoch {} test acc {}".format(e+1, test_acc / (batch_id+1)))
νΉμ Naver NER (F1) μ μ¬μ©ν μ½λλ₯Ό 곡κ°νμ€ μκ°μ μμΌμ κ°μ?
κ°μ¬ν©λλ€.
μλ νμΈμ
μ’μ νλ‘μ νΈ κ°μ¬ν©λλ€
λ€μκ³Ό κ°μ μν©μμ μλ¬κ° λ°μν©λλ€
tokenizer = KoBertTokenizer.from_pretrained('monologg/kobert')
μ²λΌ ν ν¬λμ΄μ λ₯Ό κ°μ Έμμ
"νκ΅μ΄λ‘λ μλΌ??γ
' μ λ¬Έμ₯μ tokenizer.tokenize( )
νκ² λλ©΄ λ€μκ³Ό κ°μ μμνμ΄ λμ΅λλ€
νμ§λ§ λ§μ§λ§ κ°μ νκΈ μμ 'γ 'κ³Ό λ€λ₯Έ κ°μ λλ€. (μμ 'γ ')
μ€μ λ‘ tokenizer.convert_tokens_to_ids('γ
')
νκ² λλ©΄ unknown κ°μΈ 0μ΄ λ¦¬ν΄λκ³ , μμ 'γ
' κ°μ λ£μΌλ©΄ μ μμ μΌλ‘ λμ΅λλ€.
μ΄ λλ¬Έμ λ€μκ³Ό κ°μ μν©μμ μλ¬κ° λ°μν©λλ€
μν λλ €λ³΄κ³ λ°μ΄ν°μ λ§μΆ°μ μ λ°μ΄ν°μ λ§μΆ°μ λλ €λ³΄λ €κ³ νλλ°,
download.py
binarize.sh
train_single_gpu_3_layer.sh
μμλλ‘ ν΄μΌλ κ² κ°λλΌκ΅¬μ.
κ·Έλ°λ°, download.pyμ μλ https://drive.google.com/uc?id=1-jXAnrHcKzzFiFhri37YOXH2OjP7DwMgλ‘ μ κ·Όμ΄ μλ©λλ€.
λ°μ΄ν°κ° μμ΄μμΈμ§ λͺ¨λ₯΄κ² μ§λ§ binarize.shλ₯Ό μ€νμμΌλ Can't load tokenizer for 'kobert'λΌκ³ μλ¬κ° λꡬμ..
Layer=6μ κ²½μ°, Distillation κ³Όμ μμ GPU λͺ¨λΈμ μ΄λ€ κ²μ 8κ° μ°μ
μ, μ΄λμ λμ μκ°μ΄ μμλμλμ?? λ°°μΉ μ¬μ΄μ¦λ 1000μ΄λΌκ³ 보면 λ§μκΉμ?
κ°μ¬ν©λλ€.
μλ νμΈμ.
λ¨Όμ λͺ¨λΈ 곡μ ν΄μ£Όμ μ λ무 κ°μ¬λ립λλ€. μ λ§ μ μ©νκ² νμ©νκ³ μμ΅λλ€.
training datasetμ λν μ§λ¬Έμ΄ μμ΄μ μ΄λ κ² μ§λ¬Έμ λ¨κΈ°κ² λμμ΅λλ€.
DistilkoBERTλ koBERTμ κ°μ training datasetμ μ¬μ©νμ μ νΈλ μ΄λνμ 건κ°μ?
*NMTμ PrLMμ outputμ μ¬μ©νλ νλ‘μ νΈλ₯Ό μ§ν μ€μΈλ°, NLU tasksμμ koBERTμ DistilkoBERTμ μ±λ₯ μ°¨μ΄κ° NMTμμλ λΉμ·ν μμμΌλ‘ λνλλμ§ νμΈνλ €ν©λλ€. training datasetμ΄ κ°μμΌ μ’ λ 곡μ ν λΉκ΅λ₯Ό ν μ μμ κ² κ°μ μ΄λ κ² μ§λ¬Έ λ립λλ€.
κ΅¬κΈ mutilingual BERT λ‘ λ§λ€μ΄μ§ νλ‘κ·Έλ¨μ
koBert λ‘ μ ν κ°λ₯ν κΉμ?
μλ
νμΈμ! νμ΄μ¬μ 곡λΆμ€μΈ νμμ
λλ€!
KoBert λͺ¨λΈμ μ¬μ©νλ €λ λμ€ ν ν¬λμ΄μ λ₯Ό λΆλ¬μ€λλ° μλ¬κ° λ°μνμ¬ μ§λ¬Έμ λ¨κΉλλ€!
tokenizer = KoBertTokenizer.from_pretrained('monologg/kobert')
μ½λ μ€ν μ
AttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 tokenizer = KoBertTokenizer.from_pretrained('monologg/kobert')
5 frames
/content/drive/MyDrive/tokenization_kobert.py in get_vocab(self)
123
124 def get_vocab(self):
--> 125 return dict(self.token2idx, **self.added_tokens_encoder)
126
127 def getstate(self):
AttributeError: 'KoBertTokenizer' object has no attribute 'token2idx'
λΌλ μλ¬κ° λ°μνλλ° νΉμ ν΄κ²°λ°©λ²μ΄ μλμ?!
Thanks for releasing the KoBERT model! However, I found that the parameters of BertOnlyMLMHead
layer might be missing in the monologg/kobert
model, which I think is a common issue that I also found in released BERT models for others languages, like Greek and Russian.
To reproduce this issue:
from transformers import *
m1 = AutoModelWithLMHead.from_pretrained('monologg/kobert')
print(m1.cls.predictions.transform.dense.weight)
m2 = AutoModelWithLMHead.from_pretrained('monologg/kobert')
print(m2.cls.predictions.transform.dense.weight) # different from m1
Is it possible to upload the pretrained model with the missing parameters (either in huggingface's transformers
or providing a link to the original tf checkpoint)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.