To extract named entities using NLTK's Named Entity Recognizer (NER) for generative tasks, you can use the nltk.ne_chunk() function after tokenizing and part-of-speech tagging the text. Here is the code snippet you can refer to:

In the above code, we are using the following.
- Tokenization & POS Tagging: Tokenize the input text and apply part-of-speech (POS) tagging using word_tokenize and pos_tag.
- NER with ne_chunk: Use ne_chunk to identify named entities in the tagged text.
- Extract Named Entities: Traverse the parse tree and collect named entities.
The output of the above code would be:

Hence, this method extracts named entities like organizations, locations, and people, which can be used in generative tasks to create sentences with relevant entities.