Untitled
model_name = "dbmdz/bert-large-cased-finetuned-conll03-english" ner_pipeline = pipeline('ner', model=model_name, tokenizer=model_name) # List of simple sentences to analyze sentences = [ "Barack Obama was born in Hawaii.", "Apple Inc. was founded by Steve Job.", "Microsoft is based in California.", "The Great Wall of China is very long.", "New York is a city in the USA.", "The Pacific Ocean is the largest ocean.","Amazon is an online retailer." ] # Analyze each sentence for NER for i, sentence in enumerate(sentences): print(f"\nSentence {i+1}:") results = ner_pipeline(sentence) # Print results print("Named Entity Recognition Results:") for entity in results: # Extract the entity text from the original text using start and end indices entity_text = sentence[entity['start']:entity['end']] print(f"Entity: {entity_text}, Category: {entity['entity']}, Start: {entity['start']}, End: {entity['end']}")
Leave a Comment