¿Cómo hacer el preprocesamiento de texto usando spaCy?

Cómo realizar pasos de preprocesamiento como la eliminación de Stopword, la eliminación de la puntuación, la derivación y la lematización en spaCy utilizando python.

Tengo datos de texto en archivos csv como párrafos y oraciones. Quiero hacer limpieza de texto.

Por favor dé el ejemplo cargando csv en el dataframe de pandas

Se puede hacer fácilmente a través de unos pocos comandos. También tenga en cuenta que Spacy no soporta la derivación. Puede referirse a este hilo

import spacy nlp = spacy.load('en') # sample text text = """Lorem Ipsum is simply dummy text of the printing and typesetting industry. \ Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown \ printer took a galley of type and scrambled it to make a type specimen book. It has survived not \ only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \ It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, \ and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\ There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration \ in some form, by injected humour, or randomised words which don't look even slightly believable. If you are \ going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the \ middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, \ making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined \ with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated \ Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.""" # convert the text to a spacy document document = nlp(text) # all spacy documents are tokenized. You can access them using document[i] document[0:10] # = Lorem Ipsum is simply dummy text of the printing and #the good thing about spacy is a lot of things like lemmatization etc are done when you convert them to a spacy document `using nlp(text)`. You can access sentences using document.sents list(document.sents)[0] # lemmatized words can be accessed using document[i].lemma_ and you can check # if a word is a stopword by checking the `.is_stop` attribute of the word. # here I am extracting the lemmatized form of each word provided they are not a stop word lemmas = [token.lemma_ for token in document if not token.is_stop] 

Por favor, lea sus documentos, aquí hay un ejemplo:


Esto puede ayudar a quien está buscando una respuesta para esta pregunta.

 import spacy #load spacy nlp = spacy.load("en", disable=['parser', 'tagger', 'ner']) stops = stopwords.words("english") def normalize(comment, lowercase, remove_stopwords): if lowercase: comment = comment.lower() comment = nlp(comment) lemmatized = list() for word in comment: lemma = word.lemma_.strip() if lemma: if not remove_stopwords or (remove_stopwords and lemma not in stops): lemmatized.append(lemma) return " ".join(lemmatized) Data['Text_After_Clean'] = Data['Text'].apply(normalize, lowercase=True, remove_stopwords=True)