Skip to content

Instantly share code, notes, and snippets.

@lvngd
Last active June 13, 2020 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvngd/5b3784dfd7638b4cd6bbd892e86e08b5 to your computer and use it in GitHub Desktop.
Save lvngd/5b3784dfd7638b4cd6bbd892e86e08b5 to your computer and use it in GitHub Desktop.
import nltk
from nltk.tag.stanford import StanfordNERTagger
"""
Named Entity tagging in Python with NLTK and the Stanford NER tagger
"""
PATH_TO_JAR='/Users/christina/Projects/stanford_nlp/stanford-ner/stanford-ner.jar'
PATH_TO_MODEL = '/Users/christina/Projects/stanford_nlp/stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz'
tagger = StanfordNERTagger(model_filename=PATH_TO_MODEL,path_to_jar=PATH_TO_JAR, encoding='utf-8')
sentence = 'First up in London will be Riccardo Tisci, onetime Givenchy darling, favorite of Kardashian-Jenners everywhere, who returns to the catwalk with men’s and women’s wear after a year and a half away, this time to reimagine Burberry after the departure of Christopher Bailey.'
#split the sentence into words
words = nltk.word_tokenize(sentence)
tagged = tagger.tag(words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment