Я использую Mac (чип M2, память 32 ГБ)
Это мой код: р>
Код: Выделить всё
import torch
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
# Step 1: Choose a pre-trained NER model from Hugging Face's Model Hub
# Here we use "dbmdz/bert-large-cased-finetuned-conll03-english", which is a common NER model fine-tuned on the CoNLL-2003 dataset
model_name = "dbmdz/bert-large-cased-finetuned-conll03-english"
# Step 2: Load the model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)
# Step 3: Set up a pipeline for NER
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer, grouped_entities=True)
# Step 4: Input text to perform NER on
text = "Hugging Face Inc. is a company based in New York City. Its headquarters are in DUMBO, Brooklyn."
# Step 5: Use the pipeline to get named entities
entities = ner_pipeline(text)
# Step 6: Print the recognized entities
for entity in entities:
print(f"Entity: {entity['word']}, Label: {entity['entity_group']}, Score: {entity['score']:.3f}")
Код: Выделить всё
Kernel Restarting
The kernel for appears to have died. It will restart automatically.
Моя память не заполнена, ноутбук совершенно новый.
Подробнее здесь: https://stackoverflow.com/questions/791 ... ace-models