spaCy-Wordnet

A simple extension for spaCy to leverage WordNet, one of the richest knowledge databases in the world. Use your favorite NLP tool together with a powerful dictionary.

I want to withdraw 100 euros

draw
take out
draw off

need
require

    
      import spacy
      from spacy_wordnet.wordnet_annotator import WordnetAnnotator
      # Load an spacy model (supported models are "es" and "en")
      nlp = spacy.load('en')
      nlp.add_pipe(WordnetAnnotator(nlp.lang), after='tagger')
      token = nlp('prices')[0]

      # wordnet object link spacy token with nltk wordnet interface by giving acces to
      token._.wordnet.synsets()
      token._.wordnet.lemmas()

      # And automatically tags with wordnet domains
      token._.wordnet.wordnet_domains()

      # spaCy WordNet lets you find synonyms by domain of interest for example economy
      sentence = nlp('I want to withdraw 5,000 euros')
      economy_domains = ['finance', 'banking']

      token_with_synsets = [(token, token._.wordnet.wordnet_synsets_for_domain(economy_domains)) for token in sentence]
      enriched_sentence = []
      for token, synsets in token_with_synsets:
          if not synsets:
              enriched_sentence.append(token.text)
          else:
              lemmas_for_synset = {lemma for s in synsets for lemma in s.lemma_names()}
              enriched_sentence.append('({})'.format('|'.join(lemmas_for_synset)))
      print(' '.join(enriched_sentence))
      # >> I (need|want|require) to (draw|withdraw|draw_off|take_out) 5,000 euros
    
    

Recognai is an artificial intelligence software company who help teams and data scientists to cope with information overload.

We enable companies to convert unstructured data and text into accessible and valuable information, as a prerequisite for high-quality digital processes. We do this by providing easy access to cutting-edge technology in natural language processing and machine learning.

  • ree
  • airbus-group_1
  • atresmedia
  • dzbank
  • reale
  • uniserv