回顾:什么是 GPT-2,如何安装、配置和使用它来接管世界?


请不要被OpenAPI荒谬的主张所迷惑。不要相信他们向公众发布 GPT-2 是为了造福人类的说法。OpenAPI 最终发布了 GPT-2(又名生成预训练转换器 2),这是他们曾经认为公众使用“太危险”的 AI 语言模型,因此他们可以从非营利组织过渡到商业实体,并使用 GPT-3 及以后来赚钱。尽管如此,他们还是给我们留下了 GPT-2,它非常酷且易于设置和使用。

什么是 GPT-2?

GPT-2 或生成式预训练转换器 2 是一种无监督转换器语言模型。它被训练的语料库称为WebText,包含略高于8万个文档,总共40 GB的文本来自Reddit提交中共享的URL,至少有3个赞成票。GPT-2019 于 2 年 <> 月首次宣布,出于对潜在滥用的担忧,包括可能产生假新闻的应用程序,GPT-<> 被扣留。

如何安装 GPT-2

我们将使用 Anaconda 作为 Python 环境。开始。打开 Anaconda 并切换到“环境”选项卡。单击环境旁边的箭头并打开终端。

输入以下内容以创建运行 GPT-2 的 Anaconda 环境。我们将创建一个运行 GPT-3 所需的 Python 2.x 环境。我们将此环境命名为“GPT2”

conda create -n GPT2 python=3

使用以下命令激活环境:

conda activate GPT2

GPT-2 项目在 Git 上可用,https://github.com/openai/gpt-2。使用以下命令将环境克隆到本地计算机。这将在当前文件夹中创建一个 gpt-2 目录。

git clone https://github.com/openai/gpt-2.git

接下来,安装 Git GPT-2 存储库的要求.txt中指定的要求。切换到 gpt-2 目录(使用上面的克隆创建)并输入此命令。

pip install --upgrade -r requirements.txt

现在我们需要下载预先训练的模型。有各种型号可供选择,尺寸不一。它们被命名为124M,355M,774M和1558M。774M 型号的大小约为 3.1 GB,1558M 约为 6.2 GB。下载脚本包含在 gpt-2 存储库中。使用此命令使用下载脚本安装您选择的模型。执行命令时,请确保您位于 gpt-2 目录中。

python download_model.py 774M

安装基本 Python 安装中可能缺少的其余模块。其中一些是在需求期间安装的.txt安装,但通常该步骤不起作用。

conda install numpy

conda install tensorflow==1.15.0

conda install tensorflow-gpu==2.0.0

conda install regex==2017.4.5

conda install fire>=0.1.3

conda install requests==2.21.0

conda install tqdm==4.31.1

conda install _regex

在 Anaconda 中选择 GPT2 环境,并在环境中安装 Python IDE Spyder。打开 Spyder 并在现有 GPT2 目录中创建一个新项目(项目>新项目)。现在,您应该会在 IDE 中看到 GPT2 目录。

我们需要在运行模型之前更改一个参数。在 /src 目录中打开interactive_conditional_samples.py文件。将model_name更改为您在上一步中下载的模型的名称(以下示例中为 774M)。

如何运行 GPT-2 模型

现在,您可以通过右键单击并选择“运行”来运行interactive_conditional_samples.py脚本。如果脚本错误缺少模块,请使用 conda 将它们安装在 Spyder 中。

conda install numpy

如何运行 GPT-2 模型

运行模型并键入一些文本。您可能需要等待一段时间才能收到响应。下面是一个示例。

输入的短语:

“Donald Trump should never have been elected president. He is a liar and a narcissist and an embarrassment to the United States.”

这是人工智能创造的艺术作品。

He also happens to be married to a woman who is a homophobe, banned from the Vatican and for which he proudly boasts.

To his credit, Mr. Trump has found a stroke of genius in his narrative that the media is refusing to critique him because it lacks an agenda: no agenda allowed. Any other time, in any other country, the media would have been out front, dissecting Mr. Trump as it should be doing just that. But we have a party in the United States that forbids dissent except with Islamic references, like Megyn Kelly, Mrs. Clinton, Kanye West, Joan Rivers and everyone on Broadway at the time was unable to eject card-carrying members of Monotheism.

And you know what? Directing that criticism at Hillary Clinton is a big mistake, because your Democratic opponents are on the table. The GOP front-runner, who is actively attacking the press, is Jeff Sessions. Maybe Sessions might actually be able to achieve his hopes for bigger federal statues of him than Robert E. Lee, but then Trump would be shrinking the map and the moral authority of America, and drawing less persecution from the genocidal 8th Cavalry of Free Truth.

Hillary Clinton is also CEO-like, despite her record including pay transparency and ethics rules and her own controversies. This can be a big problem for various people because there is no gap between leaders and employees in any company. If the gaps between people who distract you from destined excellence and people promoting themselves or left in charge are too large, even if that leadership is awesome, they make it difficult to stay awesome and to establish a recognizable identity. And then you become Jackass-like like, looking for any opportunity to disagree with anyone.

One can remain in the party, find a middle ground, or take on the loudest voices. But it can’t have some former president ( who Trump says criticizes him because he is a disgrace to his party) whispering in your ear, then announce that President Traitor Anthony Weiner hid millions of emails from local cops knowing that Hillary chose to use the exact same setup, the Party didn’t notice and this is how the emails got out soon after.

Trump too has expended energy and energy resources on helping your causes, seeming distrustingly at you when you ask him to be quick to accept qualification because he just doesn’t like what you say. You are insane: he chooses his words carefully and clearly.

还不够强大,无法接管世界,但仍然很酷。

如何重新训练 GPT-2

您可以使用任何文本数据(诗歌、小说、歌词、问题和答案、科学论文、新闻或文章)重新训练 GPT-2。获取每个源并使用以下行编译为单个文件,以分隔每个源。

<|endoftext|>

训练不需要分隔符,但可帮助模型学习训练数据的格式。

将训练数据移动到 GPT-2 项目的 src 目录中。

将 encode.py 脚本复制到 src 目录。

像这样对训练数据进行编码。training_data.txt是输入训练数据,training_data_encoded.npz 是编码数据集。

python encode.py training_data.txt training_data_encoded.npz

可以使用此命令训练模型。

python train.py --dataset lyric.npz

每 100 个步骤,脚本将输出 3 个样本。将显示损失率,并应随着时间的推移而降低。如果损失没有减少,则模型没有学到任何东西。要更正此问题,请使用 –learning-_rate 参数降低学习率。

python train.py --dataset training_data_encoded.npz --batch_size 2 --learning_rate 0.0001

在上面的示例中,我们还将batch_size从 1 增加到 2,这应该有助于加快速度(假设您有足够的 RAM 来处理增加的批大小)。

若要停止训练,请按 Ctrl + C。模型每 1,000 步自动保存其进度。

您可以使用以下内容恢复训练:

python train.py --dataset training_data_encoded.npz

输出可以按如下方式解密。输出示例:[340 | 75.38] 损失=0.66 平均值=0.66:

340:指训练步骤的数量。将其视为每次运行后将增加 1 的计数器。

75.38:自训练开始以来经过的时间(以秒为单位)。您可以使用第一步作为参考来确定运行一个步骤所需的时间。

损失和平均:它们都是指交叉熵(对数损失)和平均损失。您可以使用它来确定模型的性能。理论上,随着训练步骤的增加,损失应该会减小,直到收敛到某个值。越低越好。

如何使用新的、重新训练的模型运行 GPT-2

使用 Ctrl + C 停止训练后,将在 src 目录中创建一个检查点目录。在 src/models 目录中,创建一个名称为 mydata 的新文件夹。

转到 src/checkpoint/run1 文件夹,并将以下文件复制到新目录。“xxx”是您停止训练的步骤号。

接下来,转到原始模型文件夹之一(例如 774M),并将以下文件复制到新目录中:

新文件夹中应该有 7 个文件。

编辑interactive_conditional_samples.py以将模型名称更改为新目录的名称。

运行新模型。

展开阅读全文

页面更新:2024-04-20

标签:示例   脚本   模型   步骤   损失   命令   环境   文件   目录   数据   世界

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top