Удаление французских стоп-слов с помощью Spacy: руководство по обработке естественного языка

Чтобы удалить французские стоп-слова с помощью Spacy, выполните следующие действия:

Метод 1. Использование встроенного списка стоп-слов Spacy

import spacy
# Load the French language model
nlp = spacy.load("fr_core_news_sm")
# Get the list of French stopwords
stopwords = spacy.lang.fr.stop_words.STOP_WORDS
# Example sentence
sentence = "Voici un exemple de phrase en français."
# Tokenize the sentence
doc = nlp(sentence)
# Remove stopwords
tokens_without_stopwords = [token.text for token in doc if token.text.lower() not in stopwords]
# Print the filtered tokens
print(tokens_without_stopwords)

Метод 2: собственный список стоп-слов

import spacy
# Load the French language model
nlp = spacy.load("fr_core_news_sm")
# Define your custom list of stopwords
custom_stopwords = ["le", "la", "les", "de", "du", "des"]
# Example sentence
sentence = "Voici un exemple de phrase en français."
# Tokenize the sentence
doc = nlp(sentence)
# Remove stopwords
tokens_without_stopwords = [token.text for token in doc if token.text.lower() not in custom_stopwords]
# Print the filtered tokens
print(tokens_without_stopwords)