๋ฌธ์ฅ์ ๊ฐ์ ์ ๋ถ์ํ๊ธฐ ์ํ ๋ชจ๋ธ์ ๋๋ค.
KcELECTRA ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก ์ฝ 22๋ง๊ฐ์ ๊ฐ์ ๋ฌธ์ฅ์ ํ์ตํ์์ต๋๋ค.
๊ธฐ์กด FP16 ๋ชจ๋ธ์ ONNX FP16์ผ๋ก ๋ณํํ์ฌ CPU ํ๊ฒฝ์์์ ์ถ๋ก ์๋๋ฅผ ์ฝ 2๋ฐฐ ๋จ์ถํ์์ต๋๋ค.
๊ฐ์ ์ ์ด 6๊ฐ์ ์นดํ ๊ณ ๋ฆฌ๋ก ๋์ถ๋๋ฉฐ ๊ธฐ์จ, ๋นํฉ, ๋ถ๋ ธ, ๋ถ์, ์์ฒ, ์ฌํ ์ ๋๋ค.
# onnx๋ก ๋ฐ๊พธ๋ฉด์ softmax๊ฐ ํ๋ ธ์ผ๋ฏ๋ก ๋ค์ numpy๋ฅผ ์ฌ์ฉํด ๋ง๋ค์ด์ค
def softmax(x):
x = np.array(x)
e_x = np.exp(x - np.max(x))
return e_x / e_x.sum(axis=-1, keepdims=True)
def predict(text: str):
text = clean(text)
inputs = tokenizer(text, return_tensors="np")
ort_inputs = {
"input_ids": inputs["input_ids"],
"attention_mask": inputs["attention_mask"]
}
logits = session.run(["logits"], ort_inputs)[0] # (1, 6)
probs = softmax(logits)[0] # shape: (6,)
result = {id2label[i]: float(probs[i]) for i in range(6)}
return result
# pip install optimum[onnxruntime]
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
model_id = "noridorimari/onnx_emotion_classifier"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = ORTModelForSequenceClassification.from_pretrained(model_id)
inputs = tokenizer("์ค๋ ๊ธฐ๋ถ์ด ๋ณ๋ก ์ข์ง ์์.", return_tensors="pt")
outputs = model(**inputs)
print(outputs.logits)
@misc{lee2021kcelectra,
author = {Junbum Lee},
title = {KcELECTRA: Korean comments ELECTRA},
year = {2021},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/Beomi/KcELECTRA}}
}
- Downloads last month
- 9
Model tree for noridorimari/onnx_emotion_classifier
Base model
beomi/KcELECTRA-base