How to replace words in a sentence with their POS tag generated with SpaCy efficiently?
You can not replace tags in a sentence because Python strings are immutable. 

You can make another string with just the tags:

&gt;&gt;&gt; import spacy
&gt;&gt;&gt; nlp = spacy.load('en_core_web_sm')
&gt;&gt;&gt; doc = nlp("Apple is looking at buying U.K. startup for $1 billion")
&gt;&gt;&gt; " ".join(token.tag_ for token in doc)
'NNP VBZ VBG IN VBG NNP NN IN $ CD CD'


That example is based on the spaCy documentation.

If the tokens are split by several different non-space delimiters (called "multiple infix tokenization" in SpaCy), you would have to track that and the code would be more complex.