吴恩达 Chatgpt prompt 工程--5.Transforming

news2024/11/25 18:48:20

探索如何将大型语言模型用于文本转换任务,如语言翻译、拼写和语法检查、音调调整和格式转换。

Setup

import openai
import os

from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env file

openai.api_key  = os.getenv('OPENAI_API_KEY')
def get_completion(prompt, model="gpt-3.5-turbo", temperature=0): 
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=temperature, 
    )
    return response.choices[0].message["content"]
翻译

ChatGPT使用多种语言的源代码进行训练。这使模型能够进行翻译。以下是一些如何使用此功能的示例。

prompt = f"""
Translate the following English text to Spanish: \ 
```Hi, I would like to order a blender```
"""
response = get_completion(prompt)
print(response)
Hola, me gustaría ordenar una licuadora.
prompt = f"""
Tell me which language this is: 
```Combien coûte le lampadaire?```
"""
response = get_completion(prompt)
print(response)
This is French.
prompt = f"""
Translate the following  text to French and Spanish
and English pirate: \
```I want to order a basketball```
"""
response = get_completion(prompt)
print(response)

在这里插入图片描述

prompt = f"""
Translate the following text to Spanish in both the \
formal and informal forms: 
'Would you like to order a pillow?'
"""
response = get_completion(prompt)
print(response)
Formal: ¿Le gustaría ordenar una almohada?
Informal: ¿Te gustaría ordenar una almohada?
通用翻译器
user_messages = [
  "La performance du système est plus lente que d'habitude.",  # System performance is slower than normal         
  "Mi monitor tiene píxeles que no se iluminan.",              # My monitor has pixels that are not lighting
  "Il mio mouse non funziona",                                 # My mouse is not working
  "Mój klawisz Ctrl jest zepsuty",                             # My keyboard has a broken control key
  "我的屏幕在闪烁"                                               # My screen is flashing
] 
for issue in user_messages:
    prompt = f"Tell me what language this is: ```{issue}```"
    lang = get_completion(prompt)
    print(f"Original message ({lang}): {issue}")

    prompt = f"""
    Translate the following  text to English \
    and Korean: ```{issue}```
    """
    response = get_completion(prompt)
    print(response, "\n")
Original message (This is French.): La performance du système est plus lente que d'habitude.
English: The system performance is slower than usual.
Korean: 시스템 성능이 평소보다 느립니다. 

Original message (This is Spanish.): Mi monitor tiene píxeles que no se iluminan.
English: My monitor has pixels that don't light up.
Korean: 내 모니터에는 불이 켜지지 않는 픽셀이 있습니다. 

Original message (This is Italian.): Il mio mouse non funziona
English: My mouse is not working.
Korean: 내 마우스가 작동하지 않습니다. 

Original message (This is Polish.): Mój klawisz Ctrl jest zepsuty
English: My Ctrl key is broken.
Korean: 제 Ctrl 키가 고장 났어요. 

Original message (This is Chinese (Simplified).): 我的屏幕在闪烁
English: My screen is flickering.
Korean: 내 화면이 깜빡입니다. 
音调变换(Tone Transformation)

写作可以根据预期受众的不同而有所不同。ChatGPT可以产生不同的音调。

prompt = f"""
Translate the following from slang to a business letter: 
'Dude, This is Joe, check out this spec on this standing lamp.'
"""
response = get_completion(prompt)
print(response)
Dear Sir/Madam,

I am writing to bring to your attention a standing lamp that I believe may be of interest to you. Please find attached the specifications for your review.

Thank you for your time and consideration.

Sincerely,

Joe
格式转换

ChatGPT可以在不同格式之间进行转换。提示应该描述输入和输出格式。

data_json = { "resturant employees" :[ 
    {"name":"Shyam", "email":"shyamjaiswal@gmail.com"},
    {"name":"Bob", "email":"bob32@gmail.com"},
    {"name":"Jai", "email":"jai87@gmail.com"}
]}

prompt = f"""
Translate the following python dictionary from JSON to an HTML \
table with column headers and title: {data_json}
"""
response = get_completion(prompt)
print(response)
<table>
  <caption>Restaurant Employees</caption>
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Shyam</td>
      <td>shyamjaiswal@gmail.com</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>bob32@gmail.com</td>
    </tr>
    <tr>
      <td>Jai</td>
      <td>jai87@gmail.com</td>
    </tr>
  </tbody>
</table>
from IPython.display import display, Markdown, Latex, HTML, JSON
display(HTML(response))

在这里插入图片描述

拼写检查/语法检查

以下是一些常见语法和拼写问题的例子以及LLM的回应。

为了向LLM发出信号,表示你希望它校对你的文本,你指示模型“校对”或“校对并更正”。

text = [ 
  "The girl with the black and white puppies have a ball.",  # The girl has a ball.
  "Yolanda has her notebook.", # ok
  "Its going to be a long day. Does the car need it’s oil changed?",  # Homonyms
  "Their goes my freedom. There going to bring they’re suitcases.",  # Homonyms
  "Your going to need you’re notebook.",  # Homonyms
  "That medicine effects my ability to sleep. Have you heard of the butterfly affect?", # Homonyms
  "This phrase is to cherck chatGPT for speling abilitty"  # spelling
]
for t in text:
    prompt = f"""Proofread and correct the following text
    and rewrite the corrected version. If you don't find
    and errors, just say "No errors found". Don't use 
    any punctuation around the text:
    ```{t}```"""
    response = get_completion(prompt)
    print(response)
The girl with the black and white puppies has a ball.
No errors found.
It's going to be a long day. Does the car need its oil changed?
Their goes my freedom. There going to bring they're suitcases.

Corrected version: 
There goes my freedom. They're going to bring their suitcases.
You're going to need your notebook.
That medicine affects my ability to sleep. Have you heard of the butterfly effect?
This phrase is to check ChatGPT for spelling ability.
text = f"""
Got this for my daughter for her birthday cuz she keeps taking \
mine from my room.  Yes, adults also like pandas too.  She takes \
it everywhere with her, and it's super soft and cute.  One of the \
ears is a bit lower than the other, and I don't think that was \
designed to be asymmetrical. It's a bit small for what I paid for it \
though. I think there might be other options that are bigger for \
the same price.  It arrived a day earlier than expected, so I got \
to play with it myself before I gave it to my daughter.
"""
prompt = f"proofread and correct this review: ```{text}```"
response = get_completion(prompt)
print(response)
I got this for my daughter's birthday because she keeps taking mine from my room. Yes, adults also like pandas too. She takes it everywhere with her, and it's super soft and cute. However, one of the ears is a bit lower than the other, and I don't think that was designed to be asymmetrical. Additionally, it's a bit small for what I paid for it. I think there might be other options that are bigger for the same price. On the positive side, it arrived a day earlier than expected, so I got to play with it myself before I gave it to my daughter.
from redlines import Redlines

diff = Redlines(text,response)
display(Markdown(diff.output_markdown))

在这里插入图片描述

prompt = f"""
proofread and correct this review. Make it more compelling. 
Ensure it follows APA style guide and targets an advanced reader. 
Output in markdown format.
Text: ```{text}```
"""
response = get_completion(prompt)
display(Markdown(response))
Title: A Soft and Cute Panda Plush Toy for All Ages

Introduction: As a parent, finding the perfect gift for your child's birthday can be a daunting task. However, I stumbled upon a soft and cute panda plush toy that not only made my daughter happy but also brought joy to me as an adult. In this review, I will share my experience with this product and provide an honest assessment of its features.

Product Description: The panda plush toy is made of high-quality materials that make it super soft and cuddly. Its cute design is perfect for children and adults alike, making it a versatile gift option. The toy is small enough to carry around, making it an ideal companion for your child on their adventures.

Pros: The panda plush toy is incredibly soft and cute, making it an excellent gift for children and adults. Its small size makes it easy to carry around, and its design is perfect for snuggling. The toy arrived a day earlier than expected, which was a pleasant surprise.

Cons: One of the ears is a bit lower than the other, which makes the toy asymmetrical. Additionally, the toy is a bit small for its price, and there might be other options that are bigger for the same price.

Conclusion: Overall, the panda plush toy is an excellent gift option for children and adults who love cute and cuddly toys. Despite its small size and asymmetrical design, the toy's softness and cuteness make up for its shortcomings. If you're looking for a versatile gift option that will bring joy to your child and yourself, this panda plush toy is an excellent choice.

bad-grammar-examples

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/475960.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2.6 浮点运算方法和浮点运算器

学习目标&#xff1a; 以下是一些具体的学习目标&#xff1a; 理解浮点数的基本概念和表示方法&#xff0c;包括符号位、指数和尾数。学习浮点数的运算规则和舍入规则&#xff0c;包括加、减、乘、除、开方等。了解浮点数的常见问题和误差&#xff0c;例如舍入误差、溢出、下…

Unity一般打包流程

Unity一般打包流程 通常打包流程主要是通过 Building setting来选择需要打包的场景后出包到指定文件夹位置&#xff0c;也可以采用 [MenuItem("MyMenu/Do Something")]中使用static函数来选择打包路径和打包方式——需要将该脚本放置在 Editor文件夹下 [MenuItem(&…

Vue3源码 第六篇-JavaScript AST transform函数

系列文章目录 Vue3源码 第一篇-总览 Vue3源码 第二篇-Reactive API Vue3源码 第三篇-Vue3是如何实现响应性 Vue3源码 第四篇-Vue3 setup Vue3源码 第五篇-Vue3 模版compile AST生成篇 文章目录 系列文章目录前言一、transform 转换二、traverseNode 遍历节点&#xff0c;trave…

B/S结构系统的会话机制(session)

B/S结构系统的会话机制(session) 文章目录 B/S结构系统的会话机制(session)每博一文案1. session 会话机制的概述2. 什么是 session 的会话3. session 的作用4. session 的实现原理解释5. 补充&#xff1a; Cookie禁用了&#xff0c;session还能找到吗 &#xff1f;6. 总结一下…

PCA学习

前置知识 统计 假设数据集 X ∈ R n m \mathbf{X}\in\mathbb{R}^{n\times m} X∈Rnm,其中 n n n表示样本数量&#xff0c; m m m表示特征个数 均值 X ˉ 1 n e T X 1 n ∑ i 1 n X i \bar{\mathbf{X}} \frac{1}{n}\mathbf{e}^T\mathbf{X} \frac{1}{n} \sum_{i1}^{n}\mat…

[架构之路-178]-《软考-系统分析师》- 分区操作系统(Partition Operating System)概述

目录&#xff1a; 本文概述&#xff1a; 1.1 什么是分区操作系统 1.2 分区操作系统出现背景 1. 前后台系统(Foreground/Background System) 2. 实时操作系统(RTOS) 本文概述&#xff1a; 随着嵌入式系统日趋复杂化以及对安全性要求的不断提高&#xff0c;采用空间隔离、时…

java学习之枚举二

目录 一、enum关键字实现枚举 二、注意事项 一、对Season2进行反编译&#xff08;javap&#xff09; ​编辑 三、练习题 第一题 第二题 一、enum关键字实现枚举 package enum_;public class Enumeration03 {public static void main(String[] args) {System.out.println…

el-upload组件的文件回显功能和添加文件到elupload组件

省流&#xff1a; 先获取这个文件对象&#xff0c;使用handleStart方法添加到组件。 this.$refs.uploadRefName.handleStart(rawfile); 在开发的时候遇到表单里需要上传图片的功能。看了下el-upload组件的使用方法&#xff0c;在修改表单的时候&#xff0c;el-upload组件的回显…

flutter学习之旅(二)

如果不知道怎么安装编写可以查看这篇 创建项目 另一个创建方法 flutter create 项目名热部署 vscode 热部署 vscode很简单&#xff1a;可以通过Debug进行调试 使用flutter查看设备 flutter devices如图所见我现在用的是windows所以&#xff0c;我们检测不到ios因为 我们看…

【Fluent】边界类型总结,什么时候用壁面对(wall-shadow pair)、什么时候用interface?

一、fluent自动生成边界类型的规律 Enclosure是包裹在外面的气体&#xff08;流体&#xff09;&#xff0c;mold是模具&#xff08;固体&#xff09;&#xff0c;sheet是模具上的薄板件&#xff08;固体&#xff09;。 1.1 正向思维 不管是流体域还是固体域&#xff0c;每一…

高度可定制可用于商用目的全流程供应链系统(全部源码)

一、开源项目简介 高度可定制零售供应链中台基础系统&#xff0c;集成零售管理, 电子商务, 供应链管理, 财务管理, 车队管理, 仓库管理, 人员管理, 产品管理, 订单管理, 会员管理, 连锁店管理, 加盟管理, 前端React/Ant Design, 后端Java Spring自有开源框架&#xff0c;全面支…

软件测试之黑盒测试的具体方法详解

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一.基于需求的设计方法二.等价类三.边界值四.判定表4.1 **关系**4.2 如何设计测试用例4.3 实际案例第一步第二步第三步第四步 五.正交排列5.1 什么是正交表5.2 …

shell脚本的判断式

文章目录 shell脚本的判断式利用test命令的测试功能关于某个文件名的【文件类型】判断关于文件的权限检测两个文件之间的比较关于两个整数之间的比较判定字符串的数据多重条件判定例题 利用判断符号[ ]例题 shell脚本的默认变量($0、$1...)例题shift&#xff1a;造成参数变量号…

Linux安装Mysql操作步骤详解

目录 1. 检测当前系统中是否安装了MySql数据库 2. 使用FinalShell自带的上传工具将jdk的二进制发布包上传到Linux 3. 解压并解包到/usr/local/mysql&#xff08;便于区分&#xff09; 第一步&#xff1a;将包先移动到该目录下 第二步&#xff1a;解压解包 第三步&#xff1a…

LeetCode 105.106. 从前序|后序与中序遍历序列构造二叉树 | C++语言版

LeetCode 105. 从前序与中序遍历序列构造二叉树 | C语言版 LeetCode 105. 从前序与中序遍历序列构造二叉树题目描述解题思路思路一&#xff1a;使用递归代码实现运行结果参考文章&#xff1a; 思路二&#xff1a;减少遍历节点数代码实现运行结果参考文章&#xff1a; LeetCode …

C语言复习笔记1

1.不同数据类型所占字节数。 bit 01二进制的比特位 byte 字节 8 bit 比特 之后的单位都是以1024为倍数 #include<stdio.h> #include<unistd.h>int main() {printf("sizeof(char)%d\n",sizeof(char));printf("sizeof(short)%d\n",sizeof(sh…

JavaScript 笔记

1 简介 JavaScript 诞生于1995年&#xff0c;是由网景公司发明&#xff0c;起初命名为LiveScript&#xff0c;后来由于SUN公司的介入&#xff0c;更名为 JavaScript。1996年微软在其最新的IE3浏览器中引入了自己对JavaScript的实现JScript&#xff0c;于是市面上就存在两个版本…

Mybatis 框架 ( 三 ) Mybatis-Plus

4.Mybatis-plus 官网 : https://www.baomidou.com/ MyBatis-Plus 是一个 MyBatis 的增强工具&#xff0c;在 MyBatis 的基础上封装了大量常规操作&#xff0c;减少了SQL的编写量。 4.1.Maven依赖 使用时通常通过Springboot框架整合使用 并且使用Lombok框架简化实体类 <…

软件测试——基础篇(软件测试的生命周期和BUG的概念)

目录 一、软件测试生命周期 1. 软件生命周期 2. 软件测试生命周期 二、BUG 1. 如何描述一个BUG 2. BUG的级别 3. BUG的生命周期 一、软件测试生命周期 1. 软件生命周期 软件生命周期&#xff1a;需求分析&#xff0c;计划&#xff0c;设计&#xff0c;编码&#xff0c;…

20 printf 的调试

前言 在最开始的 cmd 编程中, 我们会使用到的最常见的输出, 包括一些时候调试的时候 我们最常使用到的函数 那肯定是 printf 了 我们这里来调试一下 这个 printf 还有一个原因是 之前在调试 malloc 的时候, malloc 虚拟内存分配的调试(1) 可以发现, 不仅仅是在 malloc 的时…