pull origin main

This commit is contained in:
Shogo Fujita 2023-08-08 11:29:05 +00:00
parent 36b5006db0
commit 06d356f113

98
mytest.ipynb Normal file
View File

@ -0,0 +1,98 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/shogo.fujita/.pyenv/versions/3.9.16/envs/transformers/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n",
"Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The full name of Donald is Donald J. Trump Jr., the president's son-in-law\n",
"The full name of Donald is Donald J. Trump Jr., the president of Donald J. Trump's\n",
"The full name of Donald is Donald J. Trump Jr., the president of Donald J. Trump.\n",
"The full name of Donald is Donald J. Trump Jr., the president of Donald J. Trump Organization\n",
"The full name of Donald is Donald J. Trump Jr., the president of the Trump Organization, a\n"
]
}
],
"source": [
"from transformers import AutoTokenizer, AutoModelForCausalLM\n",
"\n",
"model = AutoModelForCausalLM.from_pretrained(\"gpt2\")\n",
"tokenizer = AutoTokenizer.from_pretrained(\"gpt2\")\n",
"inputs = tokenizer([\"The full name of Donald is Donald\"], return_tensors=\"pt\")\n",
"\n",
"outputs = model.generate(**inputs, num_beams=5, num_return_sequences=5,do_sample=True)\n",
"print(\"\\n\".join(tokenizer.batch_decode(outputs, skip_special_tokens=True)))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The full name of Donald is Donald J. Trump Jr. He is the father of Donald J.\n",
"The full name of Donald is Donald J. Trump Jr., and his father is Donald J. Trump\n",
"The full name of Donald is Donald J. Trump Jr. He is the father of Donald Trump,\n",
"The full name of Donald is Donald J. Trump Jr., the father of Donald J. Trump.\n",
"The full name of Donald is Donald J. Trump Jr., the father of Donald J. Trump.\n"
]
}
],
"source": [
"from transformers import AutoTokenizer, AutoModelForCausalLM\n",
"\n",
"model = AutoModelForCausalLM.from_pretrained(\"gpt2\")\n",
"tokenizer = AutoTokenizer.from_pretrained(\"gpt2\")\n",
"inputs = tokenizer([\"The full name of Donald is Donald\"], return_tensors=\"pt\")\n",
"\n",
"outputs = model.generate(**inputs, num_beams=5, num_return_sequences=5,do_sample=True)\n",
"print(\"\\n\".join(tokenizer.batch_decode(outputs, skip_special_tokens=True)))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "transformers",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}