Created
March 4, 2024 08:25
-
-
Save tsh-code/d716a8dc6728350f1ab023fb17c3730b to your computer and use it in GitHub Desktop.
span marker example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from span_marker import SpanMarkerModel | |
modelPreTrained = SpanMarkerModel.from_pretrained("tomaarsen/span-marker-mbert-base-multinerd") | |
modelPreTrained.try_cuda() | |
def extract_people(text:str): | |
entities = modelPreTrained.predict(text) | |
full_names = set() | |
for entity in entities.ents: | |
if entity['label'] == 'PER': | |
# Check if the entity has both a first name and a last name | |
if len(entity.text.split()) >= 2: | |
full_names.add(entity.text) | |
return list(full_names) | |
content = 'text goes here' | |
entities = extract_people(content) | |
print(entities) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment