Model Description
- Developed by: κΉμν / SANGHYUN KIM
- Finetuned from model [klue/roberta-large], trained with [klue/klue] dataset.
- μμΈ μ€νκ³Ό νμ΅ νκ²½μ νμ
Usage
Load model and tokenizer
from transformers import AutoTokenizer, AutoModelForTokenClassification
>>> model_path = "skimb22/roberta-large-klue-ner-epoch8"
>>> model = AutoModelForTokenClassification.from_pretrained(model_path)
>>> tokenizer = AutoTokenizer.from_pretrained(model_path)
Define NER Label list
>>> label_list = ['B-DT', 'I-DT', 'B-LC', 'I-LC', 'B-OG', 'I-OG', 'B-PS', 'I-PS', 'B-QT', 'I-QT', 'B-TI', 'I-TI', 'O']
>>> label2id = {label: i for i, label in enumerate(label_list)}
>>> id2label = {i: label for i, label in enumerate(label_list)}
Test with [klue] NER validation datasets.
from datasets import load_dataset
import random
import torch
dataset = load_dataset("klue/klue", "ner")
val_data = dataset["validation"]
samples = random.sample(list(val_data), 10)
for idx, sample in enumerate(samples):
tokens = sample["tokens"]
gold_labels = [label_list[tag] for tag in sample["ner_tags"]]
# tokenizer, model λ³μ μ€λΉλΌ μμ΄μΌ ν¨. (Load model and tokenizer μ°Έκ³ )
inputs = tokenizer(tokens, is_split_into_words=True, return_tensors="pt", truncation=True)
word_ids = inputs.word_ids()
with torch.no_grad():
outputs = model(**inputs).logits
preds = torch.argmax(outputs, dim=-1)[0].tolist()
print(f"\nπΉ Sample {idx + 1}: {' '.join(tokens)}")
print("Token\tGold\tPred")
seen = set()
for i, word_idx in enumerate(word_ids):
if word_idx is None or word_idx in seen:
continue
seen.add(word_idx)
token = tokens[word_idx]
gold = gold_labels[word_idx]
pred_id = preds[i]
pred = label_list[pred_id] if pred_id < len(label_list) else "O"
if gold == pred:
print(f"{token}\t{gold}\t{pred} β
")
else:
print(f"{token}\t{gold}\t{pred} β")
Sample Output
Sample Output
πΉ Sample 7: μ μ μ λ μ λ λ λ μ μ μ£Ό μ μ£Ό λ΄€ λ λ° μ΄ μ λΆ ν° μ λ³Ό κ² λ λ€ !
Token Gold Pred
μ O O β
μ O O β
μ O O β
λ O O β
μ B-PS B-PS β
λ I-PS O β
λ I-PS O β
λ O O β
μ O O β
μ O O β
μ£Ό O O β
μ O O β
μ£Ό O O β
λ΄€ O O β
λ O O β
λ° O O β
μ΄ O O β
μ O O β
λΆ O O β
ν° O O β
μ O O β
λ³Ό O O β
κ² O O β
λ O O β
λ€ O O β
! O O β
Training Hyperparameters
The following hyperparameters were used during training:
learning_rate: 3e-5
per_device_train_batch_size: 32
per_device_eval_batch_size: 32
weight_decay: 0.01
num_train_epochs: 8
Evaluation
π Classification Report
precision recall f1-score support
DT 0.84 0.87 0.85 2312
LC 0.70 0.75 0.73 1649
OG 0.74 0.78 0.76 2182
PS 0.88 0.86 0.87 4418
QT 0.91 0.93 0.92 3151
TI 0.90 0.92 0.91 545
micro avg 0.84 0.85 0.84 14257
macro avg 0.83 0.85 0.84 14257
weighted avg 0.84 0.85 0.84 14257
Testing Data
[https://huggingface.co/datasets/klue/klue] - NER Datasets - validation
- Downloads last month
- 7
Model tree for skimb22/roberta-large-klue-ner-epoch8
Base model
klue/roberta-largeDataset used to train skimb22/roberta-large-klue-ner-epoch8
Evaluation results
- F1 (weighted avg) on klue/klueself-reported0.840