Remove a word in a span from SpaCy?

后端 未结 2 1687
情深已故
情深已故 2020-12-31 14:26

I am parsing a sentence with Spacy like following:

import spacy
nlp = spacy.load(\"en\")
span = nlp(\"This is some text.\")

I am wondering

2条回答
  •  梦毁少年i
    2020-12-31 14:37

    The other answer requires you to lose POS information.

    def remove_i_element_from_span(span, index):
      nlp_list = list(span)
      del nlp_list[index]
      return nlp(" ".join([e.text for e in nlp_list]))
    

提交回复
热议问题