There seems to be a problem with noun singularization with spacy in german. Spacy seems to rely on words to be capitalized to recognize them as nouns. An example:
import spacy
nlp = spacy.load("C:\\Users\\somepath\\spacy\\de_core_md\\de_core_news_md\\de_core_news_md-2.2.5")
def lemmatize_text(text):
"""returns the text with each word in its basic form"""
doc = nlp(text)
return [word.lemma_ for word in doc]
lemmatize_text('Das Wort Tests wird erkannt. Allerdings werden tests nicht erkannt')
--> ['der', 'Wort', 'Test', 'werden', 'erkennen', '.', 'Allerdings', 'werden', 'tests', 'nicht', 'erkennen']
# should say 'Test' for both sentences
That would not be a problem if I was lemmatizing the original text right away. However, my preprocessing looks like this:
- turn to lowercase
- remove punctuation
- remove stopwords
- lemmatize
Is there a recommended order in which to execute the above steps?
I am not lemmatizing first because words at the beginning of a sentence are then not recognized correctly:
lemmatize_text('Größer wird es nicht mehr. größer wird es nicht mehr.')
--> ['Größer', 'werden', 'ich', 'nicht', 'mehr', '.', 'groß', 'werden', 'ich', 'nicht', 'mehr', '.']
# should say 'groß' for both sentences