Код: Выделить всё
import polars as pl
import spacy
# Load SpaCy with GPU enabled
spacy.require_gpu()
nlp = spacy.load("en_core_web_sm") # Load the SpaCy model
# Sample Polars DataFrame
df_cleaned = pl.DataFrame({
"TITLE": ["This is a title", "Another title", "Sample title"]
})
Вот что я пробовал:
Код: Выделить всё
def remove_stopwords(text):
doc = nlp(text) # Process the text with SpaCy
return " ".join([token.text for token in doc if not token.is_stop]) # Return processed text
# Attempting to apply the function to the TITLE column
df_cleaned = df_cleaned.with_columns(
pl.col("TITLE").apply(remove_stopwords).alias("TITLE")
)
Как я могу эффективно удалить стоп-слова из Столбец Polars DataFrame при использовании SpaCy для обработки текста? Есть ли обходной путь для применения функций, как в Pandas?
Подробнее здесь: https://stackoverflow.com/questions/790 ... -spacy-gpu