Views
No views yet
1from transformers import pipeline
2
3# Initialize the NER pipeline
4ner_pipeline = pipeline(
5 "token-classification",
6 model="rustemgareev/mdeberta-ner-ontonotes5",
7 aggregation_strategy="simple"
8)
9
10# Example text
11text = "Apple Inc. is looking at buying a U.K. startup for $1 billion in London next week."
12
13# Get predictions
14entities = ner_pipeline(text)
15
16# Print the results
17for entity in entities:
18 print(f"Entity: {entity['word']}, Label: {entity['entity_group']}, Score: {entity['score']:.4f}")
19
20# Expected output:
21# Entity: Apple Inc., Label: ORGANIZATION, Score: 0.9989
22# Entity: U.K., Label: GPE, Score: 0.9983
23# Entity: $1 billion, Label: MONEY, Score: 0.9984
24# Entity: London, Label: GPE, Score: 0.9987
25# Entity: next week, Label: DATE, Score: 0.9957