Example prompts for text manipulation

Now let’s try out some prompts with the completions module and see their results.

Prompt 1: Text Generation

Python3




p = """Tell me whether the tweet is positive, neutral, or negative.
Tweet: I don't like tomato!
Sentiment:"""
  
comp(p, outputs=1)


Output:

['Negative']

Prompt 2: Text Completion

Python3




p = """hey doctor, ____"""
  
comp(p,outputs=5)


Output:

['What seems to be the problem?',
'Good morning! How can I help you today?',
'What seems to be the trouble?',
'Good to see you! How can I help you today?',
'What seems to be the problem?']

Prompt 3: Text Generation

Python3




p = "Write a tagline for my shoe company"
Output = comp(p,outputs=3)
print(Output[0])
print(Output[1])
print(Output[2])


Output:

"Walk in Comfort, Walk with Us!"
"Walking in Style, Step by Step"
"Walk in style with our designer shoes!"

Prompt 4: Text Completion

Python3




p = """What is the sentiment of these tweets:
  
1. "GFG has the best DSA course"
2. "Got late for work and got fired for that"
3. "Can't wait for Diwali!!!"
4. "What do you have in mind?"
5. "I hate strawberry"
  
Tweet sentiment ratings:"""
  
print(comp(p, outputs=1)[0])


Output:

1. Positive
2. Negative
3. Positive
4. Neutral
5. Negative

Prompt 5: Text Completion

Python3




p="""Complete this conversation with an AI assistant. 
The assistant is helpful, sarcastic, clever, and very nice in nature. 
Human want to know some good places to eat.
  
Human: Hello, who are you?
AI: I am an AI created by OpenAI. How can I help you today?
Human:"""
Output = comp(p,MaxToken =35, outputs=3)
print(Output[0])
print('\n',Output[1])
print('\n',Output[2])


Output:

I'm looking for a good place to eat.
AI: Sounds like you've got a bit of a craving for something delicious. I know the perfect place! Let me
I'm looking for some good places to eat. Do you know any?
AI: Sure! Are you looking for something specific, like Italian, or do you just want
Could you recommend some good places to eat in this area?
AI: Of course! There are lots of great restaurants in the area. I recommend checking out the Seafood

Prompt 6: Translation

Python3




p="""
Translate this sentence in hindi, german and japanese:
'I am learning from w3wiki.'
"""
Output = comp(p,MaxToken=500,outputs=2)
print(Output[0])
print('\n',Output[1])


Output:

Hindi: मैं w3wiki से सीख रहा हूँ।
German: Ich lerne von w3wiki.
Japanese: 私はw3wikiから学んでいます。
Hindi: मैं w3wiki से सीख रहा हूँ।
German: Ich lerne von w3wiki.
Japanese: 私はw3wikiから学んでいます。

Prompt 7: Summarization

Python3




p="""
Summarize the below paragraph for a pre-school student explaining 
how dangerous Mt. Everest is:
  
Mount Everest, located in the Himalayas, is the highest 
peak in the world and a popular destination for mountaineers. 
Standing at an impressive elevation of 29,029 feet (8,848 meters), 
it poses a significant challenge to climbers due to its extreme 
altitude and unpredictable weather conditions. The mountain is 
situated on the border between Nepal and China, and it attracts 
adventurers from around the globe who are determined to conquer 
its formidable slopes. Mount Everest has a rich history of expeditions 
and has been a subject of fascination for explorers and adventurers
for centuries. Despite its allure, scaling Mount Everest is a 
dangerous undertaking that requires meticulous planning, physical
fitness, and mountaineering expertise.
"""
Output = comp(p,MaxToken=20,outputs=3)
print(Output[0])
print(Output[1])
print(Output[2])


Output:

Mount Everest is the highest mountain in the world. It's very dangerous- you have to be
Mount Everest is a very tall mountain located in the Himalayas. People from all around the
Mt. Everest is the highest peak in the world and it is very dangerous and hard to

Prompt 8: Translation

Python3




p="""
How would Indian say this paragraph:
  
Mount Everest, located in the Himalayas, is the highest 
peak in the world and a popular destination for mountaineers. 
Standing at an impressive elevation of 29,029 feet (8,848 meters), 
it poses a significant challenge to climbers due to its extreme 
altitude and unpredictable weather conditions. The mountain is 
situated on the border between Nepal and China, and it attracts 
adventurers from around the globe who are determined to conquer 
its formidable slopes. Mount Everest has a rich history of expeditions 
and has been a subject of fascination for explorers and adventurers
for centuries. Despite its allure, scaling Mount Everest is a 
dangerous undertaking that requires meticulous planning, physical
fitness, and mountaineering expertise.
"""
Output = comp(p,MaxToken=1200,outputs=1)
print(Output[0])


Output:

माउंट एवरेस्ट, हिमालयों में स्थित, विश्व में सर्वोच्च चोटी है और पर्यावरण में श्रमिकों के लिए एक लोकप्रिय गंतव्य है। 
29,029 फीट (8,848 मीटर) की सुंदर ऊँचाई के साथ, यह अत्यधिक ऊँचाई और अनपेक्षित मौसम के कारण पर्यावरण में श्रमिकों को एक महत्वपूर्ण चुनौती देता है।
यह पर्वत नेपाल और चीन के सीमा पर स्थित है और यह पृथ्वी के हर कोणस्थल से ऊर्जा और अहंकार से प्रतीक्षा करने वाले अभ्यासीयकों को आकर्षित करता है।
माउंट एवरेस्ट का एक अत्यंत अधिक प्रयासों और आगमनों का अत्यधिक इतिहास है और यह दो घंटों से अन्वेषकों और आगमनाकारों के लिए आकर्षण रहा है।
माउंट एवरेस्ट के आकर्षण के बावजूद, उसे छोड़ने के लिए सख्त योजना की आवश्यकता, शारीरिक स्वस्थता और पर्वतारोहण के विद्या की आवश्यकता होती है।

Prompt 9: Text Conversion

Python3




PROMPT = """
Convert the below text to emoji's
Text:###
1. Hi
2. Geeks
3. For
###
Answer:
"""
print(comp(PROMPT, MaxToken=300, outputs=1)[0])


Output:

1. ????
2. ????
3. ????

Prompt 10: Text Conversion

Python3




PROMPT = """
Convert the below text to only special characters
Text:###
1. Hi
2. Geeks
3. For
###
Answer:
"""
print(comp(PROMPT, MaxToken=300, outputs=1)[0])


Output:

§1. ㅎㅣ
2. ㄱㅣㅇㄱㅅ
3. ㄹㅗ

Prompt 11: Retrieve factual information

Python3




PROMPT = """
How many states are in India?
Answer:
"""
print(comp(PROMPT, MaxToken=300, outputs=1)[0])


Output:

There are 28 states and 8 union territories in India.

Prompt 12: Retrieve factual information

Python3




PROMPT = """
How many countries are there in world?
Answer:
"""
print(comp(PROMPT, MaxToken=300, outputs=1)[0])


Output:

There are currently 195 countries in the world, according to the United Nations. This number includes 193 member states that are UN members, as well as 2 non-member observer states.

Text Manipulation using OpenAI

Open AI is a leading organization in the field of Artificial Intelligence and Machine Learning, they have provided the developers with state-of-the-art innovations like ChatGPT, WhisperAI, DALL-E, and many more to work on the vast unstructured data available. For text manipulation, OpenAI has compiled a Completions model which helps you to generate new text data, fill masks in strings, carry conversations, translate, and summarize. The completion module uses the power of GPT-3 to perform these tasks and give out fascinating results. In today’s article, we will be going through this Completions module and see how one can use this in Python.

Similar Reads

Steps to perform text manipulation using OpenAI

Now let’s explore how one can use GPT-3 to manipulate text data...

Example prompts for text manipulation

...

Frequently Asked Questions (FAQs)

...

Conclusion

Now let’s try out some prompts with the completions module and see their results....