How to use the sense2vec.load function in sense2vec

To help you get started, we’ve selected a few sense2vec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github explosion / spacy-services / sense2vec / app.py View on Github external
import hug
from hug_middleware_cors import CORSMiddleware
from spacy.lang.en import English
import sense2vec

# fmt: off
SENSES = ["auto", "ADJ", "ADP", "ADV", "AUX", "CONJ", "DET", "INTJ", "NOUN",
          "NUM", "PART", "PERSON", "PRON", "PROPN", "PUNCT", "SCONJ", "SYM",
          "VERB", "NORP", "FACILITY", "ORG", "GPE", "LOC", "PRODUCT", "EVENT",
          "WORK_OF_ART", "LANGUAGE"]
# fmt: on

print("Loading")
LEMMATIZER = English().vocab.morphology.lemmatizer
S2V = sense2vec.load("reddit_vectors-1.1.0")
print("Loaded!")


@hug.get("/senses")
def senses():
    """Get all available 'senses', i.e. tags and labels."""
    return SENSES


@hug.post("/find")
def find(word: str, sense: str = "auto", n_results: int = 200):
    """Find similar terms for a given term and optional sense."""
    best_word, best_sense = get_best(word, sense)
    if not word or not best_word:
        return {"text": word, "sense": sense, "results": [], "count": 0}
    results = []
github drwiner / ScreenPy / screenpy.py View on Github external
from screenpy_vars import *
import sys
DO_TEST = 0
DO_PRINT = 0


def Log(message):
	if DO_PRINT:
		print(message)


# if 'sense2vec' not in sys.modules:
import sense2vec
print('loading sense2vec')

s2v_model = sense2vec.load()
print('done loading')


def loadSpacy():
	import spacy
	print('loading SPACY english')
	nlp = spacy.load('en')
	return nlp


def sense2vec_sim(token1, token2):
	try:
		return s2v_model.data.similarity(s2v_model[token1][1], s2v_model[token2][1])
	except ValueError:
		return 0
	except KeyError:
github explosion / spacy-services / sense2vec / sense2vec_service / service.py View on Github external
def __init__(self):
        self.handler = Similarity(
            spacy.load('en', parser=False, entity=False),
            sense2vec.load())