According to Shelley's own account, she was inspired by a conversation with her husband, the poet Percy Bysshe Shelley, and their friends, Lord Byron, and John Polidori, about galvanism and the possibility of reanimating dead tissue.
During the night, she had a vivid dream of a scientist who created a hideous creature in his laboratory. The creature came to life and turned on its creator, filled with rage and a desire for revenge.
When Shelley woke up, she was so struck by the power and vividness of the dream that she decided to write it down as a story. This eventually became the novel "Frankenstein, or the Modern Prometheus," published in 1818.