spacy

Spacy add_alias, TypeError

Spacy add_alias, TypeError Question: MWE from spacy.kb import KnowledgeBase import spacy #kb.add_entity already called. nlp = spacy.blank("en") kb = KnowledgeBase(vocab=nlp.vocab, entity_vector_length=96) name = "test" qid = 1 # type(qid) => int kb.add_alias(alias=name.lower(), entities=[qid], probabilities=[1]) produces the error at the last line: TypeError: an integer is required A previous SO post suggested that the same error …

Total answers: 1

ValueError: [E966] `nlp.add_pipe` when changing the sentence segmentaion rule of spaCy model

ValueError: [E966] `nlp.add_pipe` when changing the sentence segmentaion rule of spaCy model Question: I am using Python 3.9.7 and the spaCy library and want to change the way the model segments a given sentence. Here is a sentence and the segmentation rule I created as an example: import spacy nlp=spacy.load(‘en_core_web_sm’) doc2=nlp(u’"Management is doing the right …

Total answers: 1

How to extract cities with Spacy / Can't load French model

How to extract cities with Spacy / Can't load French model Question: I know it’s perhaps an easy question but i’m not very familiar with Spacy. So i’m trying to extract cities in a text file. My code is that : pip install spacy_lefff pip install spacy download fr import spacy from spacy_lefff import LefffLemmatizer …

Total answers: 1

creating and visualizing spacy spans

creating and visualizing spacy spans Question: I have a problem visualizing manually created spans in spacy: given the simple code: from spacy.tokens import Span text = "Welcome to the Bank of China. " nlp = spacy.blank("en") doc = nlp(text) doc.spans["xx"] = [Span(doc, 0, 1, "ORG")] doc.spans["sc"] = [ Span(doc, 3, 6, "ORG"), Span(doc, 5, 6, …

Total answers: 1

Create API with Flask that receives 2 strings and returns the similarity between them with spacy

Create API with Flask that receives 2 strings and returns the similarity between them with spacy Question: I have this code that compute the similarity between 2 strings: import spacy from spacy.lang.pt.examples import sentences X ="some string 1" Y ="some string 2" nlp = spacy.load(‘pt_core_news_sm’) X_nlp = nlp(X) Y_nlp = nlp(Y) token_x = [token.text for …

Total answers: 1

spacy entity ruler – how to order patterns

spacy entity ruler – how to order patterns Question: I would like to label all entities which have not been labeled by a prior pattern as "unknown". Unfortunately the entity ruler seems not to care about the order of patterns which were provided: import spacy nlp = spacy.blank("en") ruler = nlp.add_pipe("entity_ruler") patterns = [ {‘label’: …

Total answers: 2

How to access span custom attributes with a variable name

How to access span custom attributes with a variable name Question: I am using spacy to categorize custom spans in documents. Then I create custom extension on the spans for every type of span. The example of the documentation is: from spacy.tokens import Span city_getter = lambda span: any(city in span.text for city in ("New …

Total answers: 1