Downloads · 30 days
8
15% of all-time downloads
noridorimari/onnx_emotion_classifier
onnx_emotion_classifier is a text classification model from noridorimari. Use it when you need a label for a piece of text.
Downloads · 30 days
8
15% of all-time downloads
All-time downloads
52
Public
Repo size
218 MB
Likes
0
Public
Click a slice to open those files.
.onnx218 MB · 99%
From the Hugging Face model README
# 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}}
}