How to Generate Text Automatically With Python? A Guide to the DeepAI API

Do you want to enrich your Python script with powerful text-generation capabilities? You’re in the right place!

What does it do? I just discovered DeepAI’s API that automatically generates a body of text, given a sentence fragment or topic keyword.

How can it be used? You can use this as a basis to generate text automatically.

My opinion: The generated text makes sense (kind of) but you may need to further process it or guide it to generate longer meaningful content. The biggest opportunity, in my opinion, is to use it as a step in a more complex pipeline towards the automatic generation of valuable content. On its own, it wouldn’t generate too much meaning (apart from the entertainment value of reading machine-generated text).

Table of Contents

Python Deep API Call

Ready? So, let’s have a look at the short Python script that asks the machine learning model to generate text for you—given a certain keyword such as ‘intelligence’, ‘Donald Trump’, or ‘Learn Python’.

import requests
r = requests.post(
    "https://api.deepai.org/api/text-generator",
    data={
        'text': 'intelligence',
    },
    headers={'api-key': 'quickstart-QUdJIGlzIGNvbWluZy4uLi4K'}
)
print(r.json()['output'])

You import Python’s standard library requests to issue web requests and access the DeepAI API that is hosted at the URL "https://api.deepai.org/api/text-generator".

Here’s the output the code snippet generated in my Python shell:

Automatically-Generated Text Example

Intelligence officials were able to confirm the existence of at least some Russian hacking operations, including the one apparent aimed at the White House.

The CIA brief, the statement said, “was made official by the Russian Government on the third assessment of a U.S. official that Russian Government officials had interfered in the 2016 presidential election. In my opinion, assertions that were made in the clear and unequivocal testimony of the public as well as in the public release on any of the Russian accounts were grossly improper, misleading, and should be seen to be completely absent from any official documents as well.”

It added: “In addition, the CIA’s assessment asserted the Russian Government’s claims were grossly misleading, misleading and misleading in their assertions. The CIA has concluded to date, including publicly, it has given credible facts to support the Russia’s claims, and there would be no justification for further claims, if such assertions are to be proven to be false.”

The CIA brief also claimed the CIA “should not” have “repeated, misleading details of Russian officials’ conduct.”

CIA spokeswoman Jane Harman told Fox News: “CIA Director John Brennan fully agrees that Director Brennan’s testimony confirms what we have heard from various intelligence agencies.

“He is clear that Director Brennan gave additional testimony to Congress on the subject, in the first instance in which he spoke frankly about the role of Russian intelligence.”

But Harman also said Brennan should have given “more proof” of “firm Russian intervention into the U.S. political environment” if such claims were to be believed about the same thing.

Brennan told me the U.S would “make public its best communications in Russia for all time.”

Brennan’s testimony was confirmed by CIA Director Gina Haspel.

Brennan’s public admission that the Clinton campaign was hacked “was, in fact, rejected by the CIA by the president,” the CIA brief said.

In a memo prepared to be published early Friday, CIA Director R. John Brennan outlined an intelligence assessment that a Russian national and political operative in the United States was responsible for leaking classified information to the Russian media and opposition leaders.

The CIA has denied the CIA’s assessment. But Brennan argued that the Russian “public claims are simply false assertions that are misleading, unconfirmed and improper.”

In the report, US intelligence provided more details to the National Security Council than a year ago, the first time in the United States that Russia was involved in the hack.

The CIA concluded that the Russian government hacked the DNC to help Trump and was trying to influence the 2016 election.

Russia has denied US attempts to influence the campaign. But President Obama, in a letter to US Secretary of State Rex Tillerson, said the US acted in “complete coordination with the Russian government” and “with Russian military officials, whom we have discussed with other countries.”

Russian election meddling and hacking of DNC were part of an international pattern of human rights violations in which countries have accused their governments of using disinformation to advance a political candidate and undermine a democratic election.

Dmitry Peskov, Russia’s president, said in December that the hacking was meant to interfere with the presidential election and may violate the election regulations.

“The cyberwar waged in this new Russia will not be stopped, the threats and security of the country will be the only legitimate measure,” he said, adding that the hackers “will have no chance to stop.”

The Russian state-sponsored cybercrime group F-Secure, which was based in Moscow, has claimed responsibility for a number of Russian cyber incidents that have been claimed by the United States, the Associated Press reports.

The Russian state-sponsored hacking groups include the computer firms Kaspersky Lab and DigiPG, both known for their malware and research programs, and the Moscow-based anti-virus firm Elemental.

The hacking groups have also said that as part of the election, they were targeting an array of Democratic political candidates.

The Russian military is responsible for the attack, according to Kremlin spokesman Dmitry Peskov.

Russia is often accused of using cyber hacks for its own interests. In December 2016, an Obama administration official stated that “every step is worth watching carefully” in the war in Afghanistan in 2014.

But Russia’s President Vladimir Putin, a Russian citizen and former head of the Communist Party, has denied that Russian state-backed separatists used hacking to support the presidential elections.

“I call on all government officials and political parties to avoid interference and the international community to take up arms for the political and economic purposes of Russia. We are not engaged, and should not be used,” Putin said in a speech in Moscow in February.

He said the Kremlin is not to blame for a country’s cyber crimes against the country during the presidential election.

Putin also said that “there is nothing new or wrong with the election result.”

Short Discussion

You can see that the generated text is quite detailed and looks professional. But is it correct? And does it contain plagiarism? To check these questions, I checked it with Grammarly. Here’s the result:

The text has high writing quality and is original!

But it’s obviously fake news—otherwise, Grammarly should have found the quotes of “CIA officials”. That’s why I think that the powerful text-generation ability should be used in a pipeline or system that ensures to create some real value-add—rather than using it as a stand-alone tool.

Try It Yourself (Interactive Shell)

Challenge

Challenge: Find ways to create real value using the Python API call in a more advanced code snippet and share it with the Finxter community. You can contact me by signing up on the Finxter Email Academy:

I’ll share the results of this poll in a follow-up blog article—so, stay tuned!

Author: Shantun Parmar

133 thoughts on “How to Generate Text Automatically With Python? A Guide to the DeepAI API

  1. My husband and i ended up being cheerful Albert could carry out his analysis because of the ideas he acquired from your blog. It’s not at all simplistic just to always be freely giving facts a number of people could have been making money from. And now we acknowledge we’ve got the blog owner to appreciate because of that. All of the explanations you’ve made, the easy blog menu, the friendships you aid to create – it’s all amazing, and it’s aiding our son and our family believe that that article is amusing, and that’s especially essential. Many thanks for all!

  2. Hey very nice web site!! Man .. Beautiful .. Amazing .. I’ll bookmark your site and take the
    feeds additionally? I am satisfied to find so many useful info
    right here within the post, we need work out extra
    techniques in this regard, thanks for sharing. . . . . .

  3. Heya i’m for the first time here. I came across this board
    and I find It really helpful & it helped me out a lot.

    I am hoping to give one thing back and aid others such as you helped
    me.

  4. I like the valuable info you provide in your articles.

    I’ll bookmark your blog and check again here regularly. I
    am quite sure I’ll learn plenty of new stuff right here!
    Best of luck for the next!

  5. Definitely believe that which you said. Your favorite justification seemed
    to be on the internet the easiest thing to be aware of.
    I say to you, I definitely get irked while people think about worries
    that they just do not know about. You managed to hit the nail upon the top as well as defined out the whole
    thing without having side-effects , people can take a signal.
    Will probably be back to get more. Thanks

  6. Hi there! I’m at work browsing your blog from my new iphone 3gs!
    Just wanted to say I love reading your blog and look forward to all your posts!
    Carry on the great work!

  7. First of all I would like to say excellent blog!
    I had a quick question which I’d like to ask if you do
    not mind. I was interested to know how you center yourself and clear your thoughts before writing.
    I’ve had difficulty clearing my mind in getting my ideas out there.
    I truly do enjoy writing but it just seems
    like the first 10 to 15 minutes are wasted simply just trying to figure out how to begin.
    Any suggestions or hints? Many thanks!

  8. Thanks for the auspicious writeup. It in fact was a
    leisure account it. Look advanced to far introduced agreeable from you!
    By the way, how could we be in contact?

  9. This design is wicked! You definitely know how to keep a reader
    entertained. Between your wit and your videos, I was almost
    moved to start my own blog (well, almost…HaHa!) Fantastic job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  10. I’m gone to convey my little brother, that he should also pay a visit this website on regular basis
    to obtain updated from newest reports.

  11. I was wondering if you ever considered changing the page layout of your site?
    Its very well written; I love what youve got to say.

    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or two
    pictures. Maybe you could space it out better?

  12. I have been surfing online more than three hours today, yet I
    never found any interesting article like yours.
    It’s pretty worth enough for me. In my view, if all website
    owners and bloggers made good content as you did,
    the web will be much more useful than ever before.

  13. You actually make it seem so easy with your presentation but I find this topic
    to be really something which I think I would never understand.
    It seems too complicated and extremely broad for me.

    I am looking forward for your next post, I will try to get
    the hang of it!

  14. I have been surfing online more than 2 hours today, yet I never found any interesting article like
    yours. It’s pretty worth enough for me. In my opinion,
    if all website owners and bloggers made good content as you did, the internet will be much more useful than ever before.

  15. Hi, this weekend is pleasant in support of me, since this time i am reading this
    impressive informative article here at my residence.

  16. What i don’t realize is in fact how you’re not actually much more smartly-liked
    than you may be now. You’re very intelligent. You understand thus considerably
    in terms of this matter, produced me individually imagine
    it from so many numerous angles. Its like men and women are not
    involved except it is one thing to accomplish with Woman gaga!

    Your individual stuffs nice. Always take care of it up!

  17. I think this is among the most vital info for me.
    And i am glad reading your article. But should remark on few general things, The website style is
    ideal, the articles is really nice : D. Good job, cheers

  18. I know this web page presents quality depending articles
    or reviews and additional material, is there any other website which presents these stuff in quality?

  19. Hey I know this is off topic but I was wondering if you knew of any widgets I could add
    to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have
    some experience with something like this. Please let me know if
    you run into anything. I truly enjoy reading
    your blog and I look forward to your new updates.

  20. I’m not that much of a internet reader to be honest but your blogs really nice,
    keep it up! I’ll go ahead and bookmark your site to come back later.
    Many thanks

  21. Definitely believe that which you said. Your favorite reason seemed to be on the net
    the easiest thing to be aware of. I say to
    you, I definitely get annoyed while people consider worries
    that they just don’t know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect ,
    people could take a signal. Will likely be back to get more.
    Thanks

  22. I’ll immediately seize your rss feed as I can not in finding your email subscription hyperlink or e-newsletter service.
    Do you have any? Please allow me realize in order that I may subscribe.
    Thanks.

  23. Hello! Would you mind if I share your blog with my myspace group?
    There’s a lot of folks that I think would really enjoy your content.

    Please let me know. Many thanks

  24. I’m curious to find out what blog system you are utilizing?
    I’m having some small security issues with my latest site and I would like to find something more risk-free.
    Do you have any recommendations?

  25. excellent points altogether, you just won a logo new reader.
    What may you suggest about your publish that you just made a few days ago?
    Any certain?

  26. Having read this I believed it was rather enlightening. I appreciate you spending some time
    and effort to put this short article together. I once
    again find myself personally spending way too much time both reading and leaving
    comments. But so what, it was still worthwhile!

  27. Most reside score apps have handy interfaces with vibrant and colourful graphics
    and up-to-date statistics related to the event live streaming is also a
    welcome feature.

  28. I think this is among the most significant information for me.
    And i’m glad reading your article. But want to remark
    on few general things, The website style is perfect, the articles
    is really great : D. Good job, cheers

  29. whoah this blog is magnificent i really like studying your articles.
    Keep up the good work! You realize, a lot
    of persons are hunting around for this information, you could aid them greatly.

  30. wonderful put up, very informative. I wonder why the opposite specialists of
    this sector do not notice this. You must proceed your writing.
    I am confident, you’ve a huge readers’ base already!

  31. Terrific post however I was wanting to know if you could write a litte more on this topic?

    I’d be very grateful if you could elaborate a little bit further.

    Kudos!

  32. Hmm is anyone else having problems with the pictures on this blog loading?
    I’m trying to find out if its a problem on my end
    or if it’s the blog. Any suggestions would be greatly appreciated.

  33. This is very attention-grabbing, You are a very professional blogger.
    I’ve joined your rss feed and sit up for in the hunt for extra of your magnificent post.
    Additionally, I’ve shared your site in my social networks

  34. Excellent beat ! I wish to apprentice whilst you amend your site, how could i subscribe for a weblog website?
    The account helped me a appropriate deal. I were tiny bit acquainted of this your broadcast offered brilliant clear idea

  35. I am extremely impressed together with your writing
    talents and also with the structure to your weblog.
    Is this a paid subject or did you modify it yourself?

    Either way stay up the nice quality writing, it’s uncommon to see
    a great weblog like this one today..

  36. continuously i used to read smaller posts which also clear
    their motive, and that is also happening with this piece of writing which I am reading
    at this time.

  37. With havin so much content and articles do you
    ever run into any problems of plagorism or copyright violation? My website has a
    lot of completely unique content I’ve either authored myself or outsourced but it looks like
    a lot of it is popping it up all over the web without
    my agreement. Do you know any techniques to help
    reduce content from being stolen? I’d truly appreciate
    it.

  38. Its like you read my mind! You appear to know so much about this,
    like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit,
    but other than that, this is magnificent blog.
    An excellent read. I will definitely be back.

  39. I am really impressed with your writing skills and also with the layout
    on your weblog. Is this a paid theme or did you customize it yourself?
    Either way keep up the nice quality writing, it is rare to see a great blog like this one nowadays.

  40. Hello there! This article couldn’t be written much better!

    Going through this article reminds me of my previous roommate!
    He constantly kept preaching about this. I’ll forward this article to him.
    Pretty sure he’ll have a very good read. I appreciate you for sharing!

  41. Fantastic goods from you, man. I’ve keep in mind your stuff previous to and you are simply extremely excellent.
    I really like what you have acquired here, really like what you are
    stating and the way during which you assert it. You make it entertaining and you continue to take care
    of to stay it sensible. I can not wait to read much more from you.
    This is really a terrific web site.

  42. Howdy just wanted to give you a quick heads up.
    The text in your article seem to be running off the screen in Firefox.
    I’m not sure if this is a format issue or something to do with web browser compatibility but I
    thought I’d post to let you know. The design look great though!
    Hope you get the problem solved soon. Many thanks

  43. You made some decent points there. I looked on the web to learn more about the
    issue and found most people will go along with your views on this site.

Leave a Reply

Your email address will not be published.