File size: 462 Bytes
12fcbe0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import torch
from transformers import pipeline
MODEL_NAME = "dslim/bert-base-NER"
device = 0 if torch.cuda.is_available() else -1
ner = pipeline(
"ner",
model=MODEL_NAME,
aggregation_strategy="simple",
device=device
)
texts = [
"Barack Obama was born in Hawaii.",
"Elon Musk founded SpaceX in California."
]
for text in texts:
print(f"Text: {text}")
for ent in ner(text):
print(ent)
print()
|