from transformers import pipeline
ner = pipeline("token-classification", model="chuuhtetnaing/myanmar-ner-model", grouped_entities=True)
result = ner("ကိုမောင်သည်ရန်ကုန်မြို့သို့သွားသည်။") # Ko Maung went to Yangon cityprint(result)
Evaluation Code
!pip install seqeval
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
from datasets import load_dataset
from tqdm import tqdm
from seqeval.metrics import classification_report
# Load model and tokenizer
model = AutoModelForTokenClassification.from_pretrained("chuuhtetnaing/myanmar-ner-model")
tokenizer = AutoTokenizer.from_pretrained("chuuhtetnaing/myanmar-ner-model")
deftokenize_and_align_labels(examples):
tokenized_inputs = tokenizer(examples["tokens"], truncation=True, is_split_into_words=True)
labels = []
for i, label inenumerate(examples["ner_tags"]):
word_ids = tokenized_inputs.word_ids(batch_index=i)
previous_word_idx = None
label_ids = []
for word_idx in word_ids:
if word_idx isNone:
label_ids.append(-100)
elif word_idx != previous_word_idx:
label_ids.append(label[word_idx])
else:
label_ids.append(-100)
previous_word_idx = word_idx
labels.append(label_ids)
tokenized_inputs["labels"] = labels
return tokenized_inputs
# Load and tokenize dataset
ner = pipeline("token-classification", model="chuuhtetnaing/myanmar-ner-model", aggregation_strategy=None)
ds = load_dataset("chuuhtetnaing/myanmar-ner-dataset")
tokenized_ds = ds.map(tokenize_and_align_labels, batched=True)
test_ds = tokenized_ds["test"]
# Get label mapping
label_list = model.config.id2label
y_true = []
y_pred = []
for example in tqdm(test_ds):
tokens = tokenizer.convert_ids_to_tokens(example["input_ids"])
true_labels = [label_list[l] if l != -100else"O"for l in example["labels"]]
text = tokenizer.decode(example["input_ids"], skip_special_tokens=True)
preds = ner(text)
pred_labels = ["O"] * len(true_labels)
for pred in preds:
idx = pred["index"]
if idx < len(pred_labels):
pred_labels[idx] = pred["entity"]
y_true.append([label_list[l] for l in example["labels"] if l != -100])
y_pred.append([p for p, l inzip(pred_labels, example["labels"]) if l != -100])
print(classification_report(y_true, y_pred))
NER Labels
Tag
Description
B-DATE
Beginning of Date
I-DATE
Inside Date
B-LOC
Beginning of Location
I-LOC
Inside Location
B-NUM
Beginning of Number
I-NUM
Inside Number
B-ORG
Beginning of Organization
I-ORG
Inside Organization
B-PER
Beginning of Person
I-PER
Inside Person
B-TIME
Beginning of Time
I-TIME
Inside Time
O
Outside (Not an entity)
Runs of chuuhtetnaing myanmar-ner-model on huggingface.co
43
Total runs
0
24-hour runs
0
3-day runs
4
7-day runs
4
30-day runs
More Information About myanmar-ner-model huggingface.co Model
myanmar-ner-model huggingface.co is an AI model on huggingface.co that provides myanmar-ner-model's model effect (), which can be used instantly with this chuuhtetnaing myanmar-ner-model model. huggingface.co supports a free trial of the myanmar-ner-model model, and also provides paid use of the myanmar-ner-model. Support call myanmar-ner-model model through api, including Node.js, Python, http.
myanmar-ner-model huggingface.co is an online trial and call api platform, which integrates myanmar-ner-model's modeling effects, including api services, and provides a free online trial of myanmar-ner-model, you can try myanmar-ner-model online for free by clicking the link below.
chuuhtetnaing myanmar-ner-model online free url in huggingface.co:
myanmar-ner-model is an open source model from GitHub that offers a free installation service, and any user can find myanmar-ner-model on GitHub to install. At the same time, huggingface.co provides the effect of myanmar-ner-model install, users can directly use myanmar-ner-model installed effect in huggingface.co for debugging and trial. It also supports api for free installation.