Chuyển đổi văn bản

Kỹ thuật Prompt với OpenAI API

Fouad Trad

Machine Learning Engineer

Chuyển đổi văn bản

  • Biến đổi văn bản để tạo văn bản mới
  • Nhiều ứng dụng
    • Dịch ngôn ngữ
    • Điều chỉnh giọng điệu
    • Cải thiện viết

Hình minh họa cách chuyển từ văn bản gốc sang văn bản đã biến đổi với biểu diễn rất giống nhau.

Kỹ thuật Prompt với OpenAI API

Dịch ngôn ngữ

  • Chỉ định ngôn ngữ đầu vào và đầu ra trong prompt
text = "XYZ Scooter is a cutting-edge electric scooter designed for urban 
adventurers. Its sleek design, long-lasting battery, and smart connectivity offer 
a seamless and eco-friendly way to navigate city streets."

prompt = f"""Translate the English text delimited by triple backticks to French: ```{text}```""" print(get_response(prompt))
XYZ Scooter est une trottinette électrique de pointe conçue pour les aventuriers 
urbains. Avec son design élégant, sa batterie longue durée et sa connectivité 
intelligente, elle offre un moyen fluide et respectueux de l'environnement de se 
déplacer dans les rues de la ville.
Kỹ thuật Prompt với OpenAI API

Khi không biết ngôn ngữ văn bản ...

text = "Das Produkt ist wirklich schön, und der Preis ist fair."

Yêu cầu mô hình xác định ngôn ngữ văn bản

prompt = f"""Tell me which language is the text delimited by triple backticks:
           ```{text}```"""

print(get_response(prompt))
The text delimited by triple backticks (```) is in the German language.
Kỹ thuật Prompt với OpenAI API

Dịch đa ngôn ngữ

  • Dịch sang nhiều ngôn ngữ cùng lúc
text = "The product combines top quality with a fair price."
prompt =  f"""Translate the English text delimited by triple backticks to French, 
Spanish, and German:
```{text}```"""
French: Le produit allie une qualité supérieure à un prix équitable.
Spanish: El producto combina una calidad superior con un prix juste.
German: Das Produkt vereint Spitzenqualität mit einem fairen Preis.
  • Lưu ý: Cần kiểm tra bản dịch của mô hình nếu liên quan đến khách hàng
Kỹ thuật Prompt với OpenAI API

Điều chỉnh giọng điệu

  • Viết lại văn bản theo giọng điệu khác
text = "Hey there! Check out our awesome summer deals! They're super cool, and you 
won't want to miss them. Grab 'em now!"

prompt = f"""Write the text delimited by triple backticks using a formal and persuasive tone: ```{text}```""" print(get_response(prompt))
Kỹ thuật Prompt với OpenAI API

Điều chỉnh giọng điệu

Dear [Recipient's Name],

We cordially invite you to explore our exceptional summer offers! These exclusive 
deals are truly extraordinary and should not be missed. Time is limited, so we 
encourage you to seize these incredible opportunities promptly.

[...]

Don't miss out on this chance! Take swift action to secure these remarkable summer 
deals before they expire. You won't find a more enticing selection of offers 
elsewhere.

[...]
Kỹ thuật Prompt với OpenAI API

Điều chỉnh giọng: xác định đối tượng

text = "Our cutting-edge widget employs state-of-the-art microprocessors and 
advanced algorithms, delivering unparalleled efficiency and performance for a wide 
range of applications."

prompt = f"""Write the text delimited by triple backticks to be suitable for a non-technical audience: ```{text}```""" print(get_response(prompt))
Our advanced widget uses the latest technology to provide exceptional efficiency 
and performance for a variety of uses.
Kỹ thuật Prompt với OpenAI API

Cải thiện ngữ pháp và hành văn

  • Sửa lỗi chính tả, ngữ pháp, dấu câu mà không thay đổi yếu tố khác
text = "Dear sir, I wanted too discus a potentiel opportunity for colabration. 
Pls let me know wen you're avaliable."
prompt = f"""Proofread the text delimited by triple backticks while keeping the 
original text structure intact:
           ```{text}```"""
print(get_response(prompt))
Dear sir, I wanted to discuss a potential opportunity for collaboration. Please 
let me know when you are available.
Kỹ thuật Prompt với OpenAI API

Cải thiện ngữ pháp và hành văn

  • Tăng độ rõ ràng bằng cách chỉnh cấu trúc văn bản
text = "Dear sir, I wanted too discus a potentiel opportunity for colabration. 
Pls let me know wen you're avaliable."
prompt = f"""Proofread and restructure the text delimited by triple backticks for 
enhanced readability, flow, and coherence:
           ```{text}```"""
print(get_response(prompt))
Dear sir,

I wanted to discuss with you a potential opportunity for collaboration. 
Please let me know your availability.

Thank you.
Kỹ thuật Prompt với OpenAI API

Nhiều biến đổi

  • Yêu cầu nhiều biến đổi cùng lúc -> prompt nhiều bước
text = "omg, I cant believe how awesome this product is! Its like the best thing ever! You guys gotta 
try it out!"

prompt = f"""Transform the text delimited by triple backticks with the following two steps: Step 1 - Proofread it without changing its structure Step 2 - Change the tone to be professional ```{text}```""" response = get_response(prompt)
Step 1 - OMG, I can't believe how awesome this product is! It's like the best thing ever! You guys 
gotta try it out!
Step 2 - I am astounded by the exceptional qualities of this product. It represents a remarkable 
solution that surpasses expectations. I highly recommend trying it out, as its benefits are truly 
impressive.
Kỹ thuật Prompt với OpenAI API

Ayo berlatih!

Kỹ thuật Prompt với OpenAI API

Preparing Video For Download...