Spaces:
Build error
Build error
Matthew Hollings
commited on
Commit
·
30973d8
1
Parent(s):
6b9687e
Interleave poem lines
Browse files- .gitignore +2 -1
- .prettierrc +4 -0
- README.md +21 -1
- app.py +71 -30
- fine-tune-llm.ipynb +292 -15
- test.py +0 -2
.gitignore
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
__pycache__
|
2 |
-
flagged/
|
|
|
|
1 |
__pycache__
|
2 |
+
flagged/
|
3 |
+
gutenberg-dammit-files-v002.zip
|
.prettierrc
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"tabWidth": 2,
|
3 |
+
"useTabs": false
|
4 |
+
}
|
README.md
CHANGED
@@ -9,4 +9,24 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
- 1. fine-tune a large language model (LLM) using the text corpus of a specific poet
|
13 |
+
- 1.1 if possible the entire poem should be used for generating the next line not
|
14 |
+
just the last line
|
15 |
+
- 2. build a web interface for a user to prompt and then respond
|
16 |
+
- 2.1 the poem should persist on machine reload
|
17 |
+
- 2.2 it should be possible to remove the last line and rerun
|
18 |
+
- 2.3 retry to get a new response from the model
|
19 |
+
|
20 |
+
run in a docker container and transfer to another machine
|
21 |
+
|
22 |
+
## Research
|
23 |
+
|
24 |
+
<https://github.com/aparrish/gutenberg-dammit/>
|
25 |
+
TODO:
|
26 |
+
automatically activate conda env on cd in directory
|
27 |
+
implement language generation with a basic transformer
|
28 |
+
get the website running to display responses in a user friendly way
|
29 |
+
Docker image?
|
30 |
+
|
31 |
+
<https://github.com/aparrish/gutenberg-poetry-corpus>
|
32 |
+
Gutenberg Poetry Autocomplete, a search engine-like interface for writing poems mined from Project Gutenberg. (A poem written using this interface was recently published in the Indianapolis Review!)
|
app.py
CHANGED
@@ -1,50 +1,91 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# A sequence of lines both those typed in and the line so far
|
4 |
# when save is clicked the txt file is downloaded
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
def add_to_lines(new_line):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
17 |
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
|
|
|
|
23 |
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
# Need to render a group of these
|
29 |
-
with gr.Group():
|
30 |
-
with gr.Row():
|
31 |
-
inp = gr.Textbox(placeholder="What is your name?")
|
32 |
-
out = gr.Textbox()
|
33 |
-
btn = gr.Button("Run")
|
34 |
-
btn.click(fn=add_to_lines, inputs=inp, outputs=out)
|
35 |
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Set up the generatove model transformer pipeline
|
6 |
+
generator = pipeline("text-generation", model="gpt2")
|
7 |
|
8 |
# A sequence of lines both those typed in and the line so far
|
9 |
# when save is clicked the txt file is downloaded
|
10 |
+
source_lines = []
|
11 |
+
generated_lines = []
|
12 |
+
|
13 |
+
|
14 |
+
def twolists(list1, list2):
|
15 |
+
newlist = []
|
16 |
+
a1 = len(list1)
|
17 |
+
a2 = len(list2)
|
18 |
+
|
19 |
+
for i in range(max(a1, a2)):
|
20 |
+
if i < a1:
|
21 |
+
newlist.append(list1[i])
|
22 |
+
if i < a2:
|
23 |
+
newlist.append(list2[i])
|
24 |
+
|
25 |
+
return newlist
|
26 |
|
27 |
|
28 |
+
# This function structures the space already, set boundarys to the possible.
|
29 |
+
def build_poem(source_lines, generated_lines):
|
30 |
+
# return a list with the two lists interspersed
|
31 |
+
print("____build_poem")
|
32 |
+
print("____source_lines")
|
33 |
+
print(source_lines)
|
34 |
+
print("____generated_lines")
|
35 |
+
print(generated_lines)
|
36 |
+
|
37 |
+
return twolists(source_lines, generated_lines)
|
38 |
|
39 |
|
40 |
def add_to_lines(new_line):
|
41 |
+
print("____new_line")
|
42 |
+
print(new_line)
|
43 |
+
source_lines.append(new_line)
|
44 |
+
# NOTE: pass the whole array of line to the generator
|
45 |
+
# There is a compounding of the effect, a spiral of interaction.
|
46 |
+
poem = build_poem(source_lines, generated_lines)
|
47 |
|
48 |
+
print("__poem")
|
49 |
+
print(poem)
|
50 |
|
51 |
+
# pass the full poem into the generator
|
52 |
+
result = generator("".join(poem), max_length=30, num_return_sequences=3)
|
53 |
+
# result = generator(poem, max_length=30, num_return_sequences=3)
|
54 |
|
55 |
+
print("____result")
|
56 |
+
print(result[0]["generated_text"])
|
57 |
|
58 |
+
response = result[0]["generated_text"]
|
59 |
|
60 |
+
# TODO: remove each source_line from the poem
|
61 |
+
response = response.replace("".join(poem), "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
print("____response")
|
64 |
+
print(response)
|
65 |
|
66 |
+
generated_lines.append(response)
|
67 |
+
|
68 |
+
# html = [f"<p>{line}</p>" for line in build_poem(source_lines, generated_lines)]
|
69 |
+
html = [f"{line}<br/>" for line in build_poem(source_lines, generated_lines)]
|
70 |
+
|
71 |
+
return html
|
72 |
+
|
73 |
+
|
74 |
+
demo = gr.Interface(
|
75 |
+
fn=add_to_lines,
|
76 |
+
inputs=gr.Textbox(
|
77 |
+
lines=1,
|
78 |
+
value="The drought had lasted now for ten million years, and the reign of the terrible lizards had long since ended.",
|
79 |
+
),
|
80 |
+
outputs="html",
|
81 |
+
allow_flagging="never",
|
82 |
+
)
|
83 |
|
84 |
|
85 |
if __name__ == "__main__":
|
86 |
demo.launch()
|
87 |
+
|
88 |
+
|
89 |
+
def downloadtext():
|
90 |
+
# somehow print the values from the list
|
91 |
+
pass
|
fine-tune-llm.ipynb
CHANGED
@@ -225,41 +225,76 @@
|
|
225 |
},
|
226 |
{
|
227 |
"cell_type": "code",
|
228 |
-
"execution_count":
|
229 |
"metadata": {},
|
230 |
"outputs": [
|
231 |
{
|
232 |
"data": {
|
233 |
"application/vnd.jupyter.widget-view+json": {
|
234 |
-
"model_id": "
|
235 |
"version_major": 2,
|
236 |
"version_minor": 0
|
237 |
},
|
238 |
"text/plain": [
|
239 |
-
"Downloading: 0%| | 0.00/
|
240 |
]
|
241 |
},
|
242 |
"metadata": {},
|
243 |
"output_type": "display_data"
|
244 |
},
|
245 |
{
|
246 |
-
"
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
},
|
252 |
{
|
253 |
"data": {
|
|
|
|
|
|
|
|
|
|
|
254 |
"text/plain": [
|
255 |
-
"
|
256 |
-
" {'generated_text': \"something to start with. You don't have to have a real connection with the people in this building to have any sort of connection with them. And\"},\n",
|
257 |
-
" {'generated_text': \"something to start with, as I've seen several years to come. You're supposed to be a good, loving parent, and your kids are supposed\"}]"
|
258 |
]
|
259 |
},
|
260 |
-
"execution_count": 3,
|
261 |
"metadata": {},
|
262 |
-
"output_type": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
}
|
264 |
],
|
265 |
"source": [
|
@@ -270,8 +305,11 @@
|
|
270 |
"# model = AutoModelForCausalLM.from_pretrained(\"BritishLibraryLabs/bl-books-genre\")\n",
|
271 |
"# \"BritishLibraryLabs/bl-books-genre\"\n",
|
272 |
"\n",
|
273 |
-
"tokenizer = AutoTokenizer.from_pretrained(\"gpt2\")\n",
|
274 |
-
"model = AutoModelForCausalLM.from_pretrained(\"gpt2\")\n",
|
|
|
|
|
|
|
275 |
"\n",
|
276 |
"# generator = pipeline('text-generation', model = \"BritishLibraryLabs/bl-books-genre\")\n",
|
277 |
"# generator(\"Hello, I'm a language model\", max_length = 30, num_return_sequences=3)\n",
|
@@ -280,6 +318,245 @@
|
|
280 |
"generator('something to start with', max_length = 30, num_return_sequences=3)\n"
|
281 |
]
|
282 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
{
|
284 |
"cell_type": "code",
|
285 |
"execution_count": null,
|
|
|
225 |
},
|
226 |
{
|
227 |
"cell_type": "code",
|
228 |
+
"execution_count": 6,
|
229 |
"metadata": {},
|
230 |
"outputs": [
|
231 |
{
|
232 |
"data": {
|
233 |
"application/vnd.jupyter.widget-view+json": {
|
234 |
+
"model_id": "f140e2c426e04c9ea09061a9796baf30",
|
235 |
"version_major": 2,
|
236 |
"version_minor": 0
|
237 |
},
|
238 |
"text/plain": [
|
239 |
+
"Downloading: 0%| | 0.00/29.0 [00:00<?, ?B/s]"
|
240 |
]
|
241 |
},
|
242 |
"metadata": {},
|
243 |
"output_type": "display_data"
|
244 |
},
|
245 |
{
|
246 |
+
"data": {
|
247 |
+
"application/vnd.jupyter.widget-view+json": {
|
248 |
+
"model_id": "16398286849d4ecaa30d961e2665924a",
|
249 |
+
"version_major": 2,
|
250 |
+
"version_minor": 0
|
251 |
+
},
|
252 |
+
"text/plain": [
|
253 |
+
"Downloading: 0%| | 0.00/411 [00:00<?, ?B/s]"
|
254 |
+
]
|
255 |
+
},
|
256 |
+
"metadata": {},
|
257 |
+
"output_type": "display_data"
|
258 |
},
|
259 |
{
|
260 |
"data": {
|
261 |
+
"application/vnd.jupyter.widget-view+json": {
|
262 |
+
"model_id": "91b51416d67b42fda574db1335bb114e",
|
263 |
+
"version_major": 2,
|
264 |
+
"version_minor": 0
|
265 |
+
},
|
266 |
"text/plain": [
|
267 |
+
"Downloading: 0%| | 0.00/208k [00:00<?, ?B/s]"
|
|
|
|
|
268 |
]
|
269 |
},
|
|
|
270 |
"metadata": {},
|
271 |
+
"output_type": "display_data"
|
272 |
+
},
|
273 |
+
{
|
274 |
+
"data": {
|
275 |
+
"application/vnd.jupyter.widget-view+json": {
|
276 |
+
"model_id": "c1a3c1b3cbd24e91b4b455e7bbbcc6d4",
|
277 |
+
"version_major": 2,
|
278 |
+
"version_minor": 0
|
279 |
+
},
|
280 |
+
"text/plain": [
|
281 |
+
"Downloading: 0%| | 0.00/426k [00:00<?, ?B/s]"
|
282 |
+
]
|
283 |
+
},
|
284 |
+
"metadata": {},
|
285 |
+
"output_type": "display_data"
|
286 |
+
},
|
287 |
+
{
|
288 |
+
"ename": "ValueError",
|
289 |
+
"evalue": "Unrecognized configuration class <class 'transformers.models.distilbert.configuration_distilbert.DistilBertConfig'> for this kind of AutoModel: AutoModelForCausalLM.\nModel type should be one of GPTJConfig, RemBertConfig, RoFormerConfig, BigBirdPegasusConfig, GPTNeoConfig, BigBirdConfig, Speech2Text2Config, BlenderbotSmallConfig, BertGenerationConfig, CamembertConfig, XLMRobertaConfig, PegasusConfig, MarianConfig, MBartConfig, MegatronBertConfig, BartConfig, BlenderbotConfig, ReformerConfig, RobertaConfig, BertConfig, OpenAIGPTConfig, GPT2Config, TransfoXLConfig, XLNetConfig, XLMProphetNetConfig, ProphetNetConfig, XLMConfig, CTRLConfig.",
|
290 |
+
"output_type": "error",
|
291 |
+
"traceback": [
|
292 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
293 |
+
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
294 |
+
"Cell \u001b[0;32mIn [6], line 12\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# tokenizer = AutoTokenizer.from_pretrained(\"BritishLibraryLabs/bl-books-genre\")\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# model = AutoModelForCausalLM.from_pretrained(\"BritishLibraryLabs/bl-books-genre\")\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;66;03m# \"BritishLibraryLabs/bl-books-genre\"\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \n\u001b[1;32m 8\u001b[0m \u001b[38;5;66;03m# tokenizer = AutoTokenizer.from_pretrained(\"gpt2\")\u001b[39;00m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;66;03m# model = AutoModelForCausalLM.from_pretrained(\"gpt2\")\u001b[39;00m\n\u001b[1;32m 11\u001b[0m tokenizer \u001b[38;5;241m=\u001b[39m AutoTokenizer\u001b[38;5;241m.\u001b[39mfrom_pretrained(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdistilbert-base-cased\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 12\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mAutoModelForCausalLM\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdistilbert-base-cased\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;66;03m# generator = pipeline('text-generation', model = \"BritishLibraryLabs/bl-books-genre\")\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;66;03m# generator(\"Hello, I'm a language model\", max_length = 30, num_return_sequences=3)\u001b[39;00m\n\u001b[1;32m 17\u001b[0m generator \u001b[38;5;241m=\u001b[39m pipeline(task\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtext-generation\u001b[39m\u001b[38;5;124m\"\u001b[39m, model\u001b[38;5;241m=\u001b[39mmodel, tokenizer\u001b[38;5;241m=\u001b[39mtokenizer)\n",
|
295 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py:420\u001b[0m, in \u001b[0;36m_BaseAutoModelClass.from_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 418\u001b[0m model_class \u001b[39m=\u001b[39m _get_model_class(config, \u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m_model_mapping)\n\u001b[1;32m 419\u001b[0m \u001b[39mreturn\u001b[39;00m model_class\u001b[39m.\u001b[39mfrom_pretrained(pretrained_model_name_or_path, \u001b[39m*\u001b[39mmodel_args, config\u001b[39m=\u001b[39mconfig, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m--> 420\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 421\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mUnrecognized configuration class \u001b[39m\u001b[39m{\u001b[39;00mconfig\u001b[39m.\u001b[39m\u001b[39m__class__\u001b[39m\u001b[39m}\u001b[39;00m\u001b[39m for this kind of AutoModel: \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m\u001b[39m__name__\u001b[39m\u001b[39m}\u001b[39;00m\u001b[39m.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\"\u001b[39m\n\u001b[1;32m 422\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mModel type should be one of \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m, \u001b[39m\u001b[39m'\u001b[39m\u001b[39m.\u001b[39mjoin(c\u001b[39m.\u001b[39m\u001b[39m__name__\u001b[39m \u001b[39mfor\u001b[39;00m c \u001b[39min\u001b[39;00m \u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m_model_mapping\u001b[39m.\u001b[39mkeys())\u001b[39m}\u001b[39;00m\u001b[39m.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 423\u001b[0m )\n",
|
296 |
+
"\u001b[0;31mValueError\u001b[0m: Unrecognized configuration class <class 'transformers.models.distilbert.configuration_distilbert.DistilBertConfig'> for this kind of AutoModel: AutoModelForCausalLM.\nModel type should be one of GPTJConfig, RemBertConfig, RoFormerConfig, BigBirdPegasusConfig, GPTNeoConfig, BigBirdConfig, Speech2Text2Config, BlenderbotSmallConfig, BertGenerationConfig, CamembertConfig, XLMRobertaConfig, PegasusConfig, MarianConfig, MBartConfig, MegatronBertConfig, BartConfig, BlenderbotConfig, ReformerConfig, RobertaConfig, BertConfig, OpenAIGPTConfig, GPT2Config, TransfoXLConfig, XLNetConfig, XLMProphetNetConfig, ProphetNetConfig, XLMConfig, CTRLConfig."
|
297 |
+
]
|
298 |
}
|
299 |
],
|
300 |
"source": [
|
|
|
305 |
"# model = AutoModelForCausalLM.from_pretrained(\"BritishLibraryLabs/bl-books-genre\")\n",
|
306 |
"# \"BritishLibraryLabs/bl-books-genre\"\n",
|
307 |
"\n",
|
308 |
+
"# tokenizer = AutoTokenizer.from_pretrained(\"gpt2\")\n",
|
309 |
+
"# model = AutoModelForCausalLM.from_pretrained(\"gpt2\")\n",
|
310 |
+
"\n",
|
311 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"distilbert-base-cased\")\n",
|
312 |
+
"model = AutoModelForCausalLM.from_pretrained(\"distilbert-base-cased\")\n",
|
313 |
"\n",
|
314 |
"# generator = pipeline('text-generation', model = \"BritishLibraryLabs/bl-books-genre\")\n",
|
315 |
"# generator(\"Hello, I'm a language model\", max_length = 30, num_return_sequences=3)\n",
|
|
|
318 |
"generator('something to start with', max_length = 30, num_return_sequences=3)\n"
|
319 |
]
|
320 |
},
|
321 |
+
{
|
322 |
+
"cell_type": "code",
|
323 |
+
"execution_count": 11,
|
324 |
+
"metadata": {},
|
325 |
+
"outputs": [
|
326 |
+
{
|
327 |
+
"name": "stderr",
|
328 |
+
"output_type": "stream",
|
329 |
+
"text": [
|
330 |
+
"If you want to use `RobertaLMHeadModel` as a standalone, add `is_decoder=True.`\n"
|
331 |
+
]
|
332 |
+
},
|
333 |
+
{
|
334 |
+
"ename": "ValueError",
|
335 |
+
"evalue": "num_return_sequences has to be 1, but is 3 when doing greedy search.",
|
336 |
+
"output_type": "error",
|
337 |
+
"traceback": [
|
338 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
339 |
+
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
340 |
+
"Cell \u001b[0;32mIn [11], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m generator \u001b[38;5;241m=\u001b[39m pipeline(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtext-generation\u001b[39m\u001b[38;5;124m'\u001b[39m, model \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mroberta-base\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43mgenerator\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mHello, I\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mm a language model\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_length\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m30\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum_return_sequences\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m\n",
|
341 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/transformers/pipelines/text_generation.py:150\u001b[0m, in \u001b[0;36mTextGenerationPipeline.__call__\u001b[0;34m(self, text_inputs, **kwargs)\u001b[0m\n\u001b[1;32m 121\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mself\u001b[39m, text_inputs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 122\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 123\u001b[0m \u001b[39m Complete the prompt(s) given as inputs.\u001b[39;00m\n\u001b[1;32m 124\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 148\u001b[0m \u001b[39m -- The token ids of the generated text.\u001b[39;00m\n\u001b[1;32m 149\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 150\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39msuper\u001b[39;49m()\u001b[39m.\u001b[39;49m\u001b[39m__call__\u001b[39;49m(text_inputs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
|
342 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/transformers/pipelines/base.py:915\u001b[0m, in \u001b[0;36mPipeline.__call__\u001b[0;34m(self, inputs, num_workers, *args, **kwargs)\u001b[0m\n\u001b[1;32m 913\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mget_iterator(inputs, num_workers, preprocess_params, forward_params, postprocess_params)\n\u001b[1;32m 914\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 915\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mrun_single(inputs, preprocess_params, forward_params, postprocess_params)\n",
|
343 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/transformers/pipelines/base.py:922\u001b[0m, in \u001b[0;36mPipeline.run_single\u001b[0;34m(self, inputs, preprocess_params, forward_params, postprocess_params)\u001b[0m\n\u001b[1;32m 920\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mrun_single\u001b[39m(\u001b[39mself\u001b[39m, inputs, preprocess_params, forward_params, postprocess_params):\n\u001b[1;32m 921\u001b[0m model_inputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpreprocess(inputs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mpreprocess_params)\n\u001b[0;32m--> 922\u001b[0m model_outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mforward(model_inputs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mforward_params)\n\u001b[1;32m 923\u001b[0m outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpostprocess(model_outputs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mpostprocess_params)\n\u001b[1;32m 924\u001b[0m \u001b[39mreturn\u001b[39;00m outputs\n",
|
344 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/transformers/pipelines/base.py:871\u001b[0m, in \u001b[0;36mPipeline.forward\u001b[0;34m(self, model_inputs, **forward_params)\u001b[0m\n\u001b[1;32m 869\u001b[0m \u001b[39mwith\u001b[39;00m torch\u001b[39m.\u001b[39mno_grad():\n\u001b[1;32m 870\u001b[0m model_inputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_ensure_tensor_on_device(model_inputs, device\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdevice)\n\u001b[0;32m--> 871\u001b[0m model_outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_forward(model_inputs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mforward_params)\n\u001b[1;32m 872\u001b[0m model_outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_ensure_tensor_on_device(model_outputs, device\u001b[39m=\u001b[39mtorch\u001b[39m.\u001b[39mdevice(\u001b[39m\"\u001b[39m\u001b[39mcpu\u001b[39m\u001b[39m\"\u001b[39m))\n\u001b[1;32m 873\u001b[0m \u001b[39melse\u001b[39;00m:\n",
|
345 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/transformers/pipelines/text_generation.py:165\u001b[0m, in \u001b[0;36mTextGenerationPipeline._forward\u001b[0;34m(self, model_inputs, **generate_kwargs)\u001b[0m\n\u001b[1;32m 163\u001b[0m input_ids \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 164\u001b[0m prompt_text \u001b[39m=\u001b[39m model_inputs\u001b[39m.\u001b[39mpop(\u001b[39m\"\u001b[39m\u001b[39mprompt_text\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m--> 165\u001b[0m generated_sequence \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmodel\u001b[39m.\u001b[39;49mgenerate(input_ids\u001b[39m=\u001b[39;49minput_ids, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mgenerate_kwargs) \u001b[39m# BS x SL\u001b[39;00m\n\u001b[1;32m 166\u001b[0m \u001b[39mreturn\u001b[39;00m {\u001b[39m\"\u001b[39m\u001b[39mgenerated_sequence\u001b[39m\u001b[39m\"\u001b[39m: generated_sequence, \u001b[39m\"\u001b[39m\u001b[39minput_ids\u001b[39m\u001b[39m\"\u001b[39m: input_ids, \u001b[39m\"\u001b[39m\u001b[39mprompt_text\u001b[39m\u001b[39m\"\u001b[39m: prompt_text}\n",
|
346 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/torch/autograd/grad_mode.py:27\u001b[0m, in \u001b[0;36m_DecoratorContextManager.__call__.<locals>.decorate_context\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[39m@functools\u001b[39m\u001b[39m.\u001b[39mwraps(func)\n\u001b[1;32m 25\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mdecorate_context\u001b[39m(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 26\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mclone():\n\u001b[0;32m---> 27\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
|
347 |
+
"File \u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/augmented_poetry/lib/python3.8/site-packages/transformers/generation_utils.py:984\u001b[0m, in \u001b[0;36mGenerationMixin.generate\u001b[0;34m(self, input_ids, max_length, min_length, do_sample, early_stopping, num_beams, temperature, top_k, top_p, repetition_penalty, bad_words_ids, bos_token_id, pad_token_id, eos_token_id, length_penalty, no_repeat_ngram_size, encoder_no_repeat_ngram_size, num_return_sequences, max_time, max_new_tokens, decoder_start_token_id, use_cache, num_beam_groups, diversity_penalty, prefix_allowed_tokens_fn, output_attentions, output_hidden_states, output_scores, return_dict_in_generate, forced_bos_token_id, forced_eos_token_id, remove_invalid_values, synced_gpus, **model_kwargs)\u001b[0m\n\u001b[1;32m 982\u001b[0m \u001b[39mif\u001b[39;00m is_greedy_gen_mode:\n\u001b[1;32m 983\u001b[0m \u001b[39mif\u001b[39;00m num_return_sequences \u001b[39m>\u001b[39m \u001b[39m1\u001b[39m:\n\u001b[0;32m--> 984\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 985\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mnum_return_sequences has to be 1, but is \u001b[39m\u001b[39m{\u001b[39;00mnum_return_sequences\u001b[39m}\u001b[39;00m\u001b[39m when doing greedy search.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 986\u001b[0m )\n\u001b[1;32m 988\u001b[0m \u001b[39m# greedy search\u001b[39;00m\n\u001b[1;32m 989\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mgreedy_search(\n\u001b[1;32m 990\u001b[0m input_ids,\n\u001b[1;32m 991\u001b[0m logits_processor\u001b[39m=\u001b[39mlogits_processor,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 998\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mmodel_kwargs,\n\u001b[1;32m 999\u001b[0m )\n",
|
348 |
+
"\u001b[0;31mValueError\u001b[0m: num_return_sequences has to be 1, but is 3 when doing greedy search."
|
349 |
+
]
|
350 |
+
}
|
351 |
+
],
|
352 |
+
"source": [
|
353 |
+
"generator = pipeline('text-generation', model = 'roberta-base')\n",
|
354 |
+
"generator(\"Hello, I'm a language model\", max_length = 30, num_return_sequences=3)"
|
355 |
+
]
|
356 |
+
},
|
357 |
+
{
|
358 |
+
"cell_type": "code",
|
359 |
+
"execution_count": 14,
|
360 |
+
"metadata": {},
|
361 |
+
"outputs": [
|
362 |
+
{
|
363 |
+
"data": {
|
364 |
+
"text/plain": [
|
365 |
+
"'[Illustration: \"I saw there something missing from'"
|
366 |
+
]
|
367 |
+
},
|
368 |
+
"execution_count": 14,
|
369 |
+
"metadata": {},
|
370 |
+
"output_type": "execute_result"
|
371 |
+
}
|
372 |
+
],
|
373 |
+
"source": [
|
374 |
+
"from gutenbergdammit.ziputils import retrieve_one\n",
|
375 |
+
"text = retrieve_one(\"gutenberg-dammit-files-v002.zip\", \"123/12345.txt\")\n",
|
376 |
+
"# text = retrieve_one(\"gutenberg-dammit-files-v002.zip\", \"123/12345.txt\")\n",
|
377 |
+
"text[:50]"
|
378 |
+
]
|
379 |
+
},
|
380 |
+
{
|
381 |
+
"cell_type": "code",
|
382 |
+
"execution_count": 17,
|
383 |
+
"metadata": {},
|
384 |
+
"outputs": [
|
385 |
+
{
|
386 |
+
"data": {
|
387 |
+
"text/plain": [
|
388 |
+
"{'Author': ['Jules Verne'],\n",
|
389 |
+
" 'Author Birth': [1828],\n",
|
390 |
+
" 'Author Death': [1905],\n",
|
391 |
+
" 'Author Given': ['Jules'],\n",
|
392 |
+
" 'Author Surname': ['Verne'],\n",
|
393 |
+
" 'Copyright Status': ['Not copyrighted in the United States.'],\n",
|
394 |
+
" 'Language': ['English'],\n",
|
395 |
+
" 'LoC Class': ['PQ: Language and Literatures: Romance literatures: French, Italian, Spanish, Portuguese'],\n",
|
396 |
+
" 'Num': '103',\n",
|
397 |
+
" 'Subject': ['Adventure stories', 'Voyages around the world -- Fiction'],\n",
|
398 |
+
" 'Title': ['Around the World in 80 Days'],\n",
|
399 |
+
" 'charset': 'us-ascii',\n",
|
400 |
+
" 'gd-num-padded': '00103',\n",
|
401 |
+
" 'gd-path': '001/00103.txt',\n",
|
402 |
+
" 'href': '/1/0/103/103.zip'}"
|
403 |
+
]
|
404 |
+
},
|
405 |
+
"execution_count": 17,
|
406 |
+
"metadata": {},
|
407 |
+
"output_type": "execute_result"
|
408 |
+
}
|
409 |
+
],
|
410 |
+
"source": [
|
411 |
+
"from gutenbergdammit.ziputils import loadmetadata\n",
|
412 |
+
"metadata = loadmetadata(\"gutenberg-dammit-files-v002.zip\")\n",
|
413 |
+
"metadata[100]\n",
|
414 |
+
"# ['Essays in the Art of Writing']"
|
415 |
+
]
|
416 |
+
},
|
417 |
+
{
|
418 |
+
"cell_type": "code",
|
419 |
+
"execution_count": 16,
|
420 |
+
"metadata": {},
|
421 |
+
"outputs": [
|
422 |
+
{
|
423 |
+
"name": "stdout",
|
424 |
+
"output_type": "stream",
|
425 |
+
"text": [
|
426 |
+
"Entertaining Made Easy 108314\n",
|
427 |
+
"Reading Made Easy for Foreigners - Third Reader 209964\n",
|
428 |
+
"The Art of Cookery Made Easy and Refined 262990\n",
|
429 |
+
"Shaving Made Easy\tWhat the Man Who Shaves Ought to Know 44982\n",
|
430 |
+
"Writing and Drawing Made Easy, Amusing and Instructive\tContaining The Whole Alphabet in all the Characters now\tus'd, Both in Printing and Penmanship 10036\n",
|
431 |
+
"Etiquette Made Easy 119372\n"
|
432 |
+
]
|
433 |
+
}
|
434 |
+
],
|
435 |
+
"source": [
|
436 |
+
"from gutenbergdammit.ziputils import searchandretrieve\n",
|
437 |
+
"for info, text in searchandretrieve(\"gutenberg-dammit-files-v002.zip\", {'Title': 'Made Easy'}):\n",
|
438 |
+
" print(info['Title'][0], len(text))\n"
|
439 |
+
]
|
440 |
+
},
|
441 |
+
{
|
442 |
+
"cell_type": "code",
|
443 |
+
"execution_count": null,
|
444 |
+
"metadata": {},
|
445 |
+
"outputs": [],
|
446 |
+
"source": [
|
447 |
+
"# from gutenbergdammit.ziputils import retrieve_one\n",
|
448 |
+
"# search and retrieve only poetry text\n",
|
449 |
+
"# fine tune with line-by-line"
|
450 |
+
]
|
451 |
+
},
|
452 |
+
{
|
453 |
+
"cell_type": "code",
|
454 |
+
"execution_count": null,
|
455 |
+
"metadata": {},
|
456 |
+
"outputs": [],
|
457 |
+
"source": []
|
458 |
+
},
|
459 |
+
{
|
460 |
+
"cell_type": "code",
|
461 |
+
"execution_count": null,
|
462 |
+
"metadata": {},
|
463 |
+
"outputs": [],
|
464 |
+
"source": []
|
465 |
+
},
|
466 |
+
{
|
467 |
+
"cell_type": "code",
|
468 |
+
"execution_count": 19,
|
469 |
+
"metadata": {},
|
470 |
+
"outputs": [
|
471 |
+
{
|
472 |
+
"data": {
|
473 |
+
"text/plain": [
|
474 |
+
"False"
|
475 |
+
]
|
476 |
+
},
|
477 |
+
"execution_count": 19,
|
478 |
+
"metadata": {},
|
479 |
+
"output_type": "execute_result"
|
480 |
+
}
|
481 |
+
],
|
482 |
+
"source": [
|
483 |
+
"# from transformers import AutoModel\n",
|
484 |
+
"# model_clpt = \"distilbert-base-uncased\"\n",
|
485 |
+
"# device = torch.device(\"cuda\" id tor)\n",
|
486 |
+
"import torch\n",
|
487 |
+
"torch.cuda.is_available()"
|
488 |
+
]
|
489 |
+
},
|
490 |
+
{
|
491 |
+
"cell_type": "code",
|
492 |
+
"execution_count": 20,
|
493 |
+
"metadata": {},
|
494 |
+
"outputs": [
|
495 |
+
{
|
496 |
+
"name": "stdout",
|
497 |
+
"output_type": "stream",
|
498 |
+
"text": [
|
499 |
+
"WARNING:tensorflow:From /var/folders/vr/wjfjpzn1755bvptln8g22f9r0000gn/T/ipykernel_91499/3763141526.py:2: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.\n",
|
500 |
+
"Instructions for updating:\n",
|
501 |
+
"Use `tf.config.list_physical_devices('GPU')` instead.\n"
|
502 |
+
]
|
503 |
+
},
|
504 |
+
{
|
505 |
+
"data": {
|
506 |
+
"text/plain": [
|
507 |
+
"False"
|
508 |
+
]
|
509 |
+
},
|
510 |
+
"execution_count": 20,
|
511 |
+
"metadata": {},
|
512 |
+
"output_type": "execute_result"
|
513 |
+
}
|
514 |
+
],
|
515 |
+
"source": [
|
516 |
+
"import tensorflow as tf\n",
|
517 |
+
"tf.test.is_gpu_available()\n"
|
518 |
+
]
|
519 |
+
},
|
520 |
+
{
|
521 |
+
"cell_type": "code",
|
522 |
+
"execution_count": 21,
|
523 |
+
"metadata": {},
|
524 |
+
"outputs": [
|
525 |
+
{
|
526 |
+
"data": {
|
527 |
+
"text/plain": [
|
528 |
+
"[]"
|
529 |
+
]
|
530 |
+
},
|
531 |
+
"execution_count": 21,
|
532 |
+
"metadata": {},
|
533 |
+
"output_type": "execute_result"
|
534 |
+
}
|
535 |
+
],
|
536 |
+
"source": [
|
537 |
+
"tf.config.list_physical_devices('GPU')"
|
538 |
+
]
|
539 |
+
},
|
540 |
+
{
|
541 |
+
"cell_type": "code",
|
542 |
+
"execution_count": 22,
|
543 |
+
"metadata": {},
|
544 |
+
"outputs": [
|
545 |
+
{
|
546 |
+
"data": {
|
547 |
+
"text/plain": [
|
548 |
+
"[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]"
|
549 |
+
]
|
550 |
+
},
|
551 |
+
"execution_count": 22,
|
552 |
+
"metadata": {},
|
553 |
+
"output_type": "execute_result"
|
554 |
+
}
|
555 |
+
],
|
556 |
+
"source": [
|
557 |
+
"tf.config.list_physical_devices('CPU')"
|
558 |
+
]
|
559 |
+
},
|
560 |
{
|
561 |
"cell_type": "code",
|
562 |
"execution_count": null,
|
test.py
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
-
print("hello")
|
|
|
|
|
|