Views
No views yet
ChemicalDiseaseO (non-entity tokens)B-Chemical, I-Disease, O.1from transformers import AutoTokenizer, AutoModelForTokenClassification
2from transformers import pipeline
3
4tokenizer = AutoTokenizer.from_pretrained("Francesco-A/BiomedNLP-PubMedBERT-base-uncased-abstract-bc5cdr-ner-v1")
5model = AutoModelForTokenClassification.from_pretrained("Francesco-A/BiomedNLP-PubMedBERT-base-uncased-abstract-bc5cdr-ner-v1")
6
7ner = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="first")
8
9demo_texts = [
10 "Aspirin is often used to treat inflammation, but may cause gastric bleeding.",
11 "Naloxone reverses the antihypertensive effect of clonidine.",
12]
13
14for t in demo_texts:
15 print("\nText:", t)
16 preds = ner(t)
17 for p in preds:
18 print(f' - {p["word"]}: {p["entity_group"]} (score {p["score"]:.2f})')| Training Loss | Epoch | Step | Validation Loss | Precision | Recall | F1 | Accuracy |
|---|---|---|---|---|---|---|---|
| No log | 0.9836 | 15 | 0.5775 | 0.0299 | 0.0002 | 0.0004 | 0.8627 |
| No log | 1.9672 | 30 | 0.2332 | 0.7252 | 0.5753 | 0.6416 | 0.9284 |
| No log | 2.9508 | 45 | 0.1237 | 0.7610 | 0.8265 | 0.7924 | 0.9606 |
| No log | 4.0 | 61 | 0.0937 | 0.8364 | 0.8859 | 0.8605 | 0.9690 |
| No log | 4.9836 | 76 | 0.0860 | 0.8510 | 0.8927 | 0.8714 | 0.9714 |
| No log | 5.9672 | 91 | 0.0833 | 0.8502 | 0.8995 | 0.8741 | 0.9724 |
| 0.3513 | 6.9508 | 106 | 0.0859 | 0.8494 | 0.8992 | 0.8736 | 0.9714 |
| 0.3513 | 7.8689 | 120 | 0.0835 | 0.8582 | 0.8977 | 0.8775 | 0.9727 |