Extract sentence embedding from GPT2

How can I get embedding of an input sentence as output from GPT2. I want to build semantic search on my text corpus by creating sentence embeddings using GPT2. I have implementation of the same using bert-base-nli-mean-tokens.
Need help to build it using GPT2.

© Copyright 2013-2020 Analytics Vidhya