Views
No views yet
1from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
2from peft import PeftModel
3
4base = "bert-base-cased"
5adapter = "starkdv123/conll2003-bert-ner-lora"
6
7tok = AutoTokenizer.from_pretrained(base)
8base_model = AutoModelForTokenClassification.from_pretrained(base, num_labels=9)
9model = PeftModel.from_pretrained(base_model, adapter)
10
11clf = pipeline("token-classification", model=model, tokenizer=tok, aggregation_strategy="simple")
12clf("Chris Hoiles hit his 22nd homer for Baltimore.") LOC MISC O ORG PER
LOC 384 6 35 43 5
MISC 12 2138 80 100 33
O 57 119 38060 58 21
ORG 43 109 36 2304 11
PER 1 27 18 22 2705