न्यूज़ हेडलाइनों में named entities पहचानना
समाचार संस्थाएँ सर्च, इंडेक्सिंग, और रिकमेंडेशन बेहतर करने के लिए अक्सर हेडलाइनों में लोगों, स्थानों और संगठनों जैसी named entities को टैग करती हैं. आपका काम Hugging Face की pipeline का उपयोग करके किसी न्यूज़ हेडलाइन में इन entities को अपने-आप पहचानना और समूहित करना है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Natural Language Processing (NLP)
अभ्यास निर्देश
"dslim/bert-base-NER"मॉडल का उपयोग करके एकner_pipelineबनाएँ.- दिए गए
headlineसे named entities निकालें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
from transformers import pipeline
# Create the NER pipeline
ner_pipeline = pipeline(
task="____",
model="____",
grouped_entities=True
)
headline = "Apple is planning to open a new office in San Francisco next year."
# Get named entities
entities = ____
for entity in entities:
print(f"{entity['entity_group']}: {entity['word']}")