This is an example of Named Entity Recognition(NER) problem. One can build a sequence model such as an LSTM to perform this task. However, as shown in both the sentences above, forward only LSTM might fail here.
Using forward only direction LSTM might result in a model which recognises Teddy as a product : “bear”, which is on sale. This is because it does not look at context after the occurrence of the word, as in Teddy Roosvelt.
Using BiDirectional RNNs can resolve the above problem. As context of “President” in w2 can be transferred back to the word “Teddy” which makes it easier to call it a person and not a product.