LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,3 +1,152 @@
1
- ---
2
- license: bigscience-openrail-m
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 💮 GenerAd AI 💮 (FourthBrain Sample Project)
2
+ ## Elevate your Ad game with GenerAd, powered by BLOOM!
3
+ GenerAd AI is a fine-tuned LLM marketing assistant that can help you generate quick, and catchy, advertisements for your products!
4
+
5
+ ## 📔 Notebooks
6
+ | Notebook | Purpose | Link |
7
+ | :-------- | :-------- | :------------------------------------------------------------------------------------------------ |
8
+ | 🌼**BLOOM-LoRA Fine-tuning Notebook** | Fine-tune and run inference on the fine-tuned result | [Here](https://colab.research.google.com/drive/12qOhhGyoh7qSm1eqeMCbvv63EObH2TBH?usp=sharing) |
9
+ | 🖥️ **GPT-3 Ada Fine-tuning Notebook** | Fine-tune your model using OpenAI's fine-tuning API | [Here](https://colab.research.google.com/drive/16nc8RXIcM9iulDsAlhfolvKoyar_Xn4f?usp=sharing) |
10
+
11
+ ## 📚 Data
12
+ Data was generated synthetically with GPT-4.
13
+
14
+ Process and data found [here](https://huggingface.co/datasets/c-s-ale/Product-Descriptions-and-Ads)
15
+
16
+ ## 💰 Value Generation
17
+ With GenerAD AI, small businesses or lean teams don't have to be burdened with generating marketing material for their products. They can leverage GenerAd AI to accelerate their marketing workflows and get the Twitter or Instagram ad they want in a matter of moments.
18
+
19
+ Instead of spending time or money on making ads, enable yourself to spend more time building value and relationships.
20
+
21
+ ## 🤖 Example Model
22
+ While GenerAd AI was fine-tuned on clothing advertisements, it generalizes well to a large number of domains.
23
+
24
+ We will be hosting an example model soon!
25
+
26
+ ## 🎬 Baseline
27
+
28
+ Baseline results for three sample prompts:
29
+
30
+ #### GPT-3 Ada
31
+
32
+ ```
33
+ Prompt:
34
+ Lace-up sandals: Shoes featuring laces or ties that wrap around the foot and, in some cases, the ankle.\n\n###\n\n
35
+
36
+ Reponse:
37
+
38
+ Lace-up sandals: Shoes without laces or ties that areStrands of textiles that run around the foot and, in some cases, the ankle.
39
+ ```
40
+
41
+ ```
42
+ Prompt:
43
+ Sundress: A flowery yellow sundress with blue polka dots.\n\n###\n\n
44
+
45
+ Reponse:
46
+ Shirt:
47
+
48
+ The shirt is a lightweight, comfortable shirt made from a light, Aethercrete fabric. It has a comfortable fit and a stylish design.
49
+ ```
50
+
51
+ ```
52
+ Prompt:
53
+ A new Lexus: A luxury automobile with grey paint and tinted windows.\n\n###\n\n
54
+
55
+ Response:
56
+ The Lexus LS is a luxury automobile with grey paint and tinted windows. It is developed from the Lexus LS. This vehicle has a value of $50,000.
57
+ ```
58
+
59
+ #### BLOOM 1b7
60
+
61
+ ```
62
+ ### Product and Description:
63
+ Lace-up sandals: Shoes featuring laces or ties that wrap around the foot and, in some cases, the ankle.
64
+
65
+ ### Ad:
66
+ From Wikipedia:
67
+
68
+ Ads (also called advertisements) are paid promotions of products,
69
+ ```
70
+
71
+ ```
72
+ ### Product and Description:
73
+ Sundress: A flowery yellow sundress with blue polka dots.
74
+
75
+ ### Ad:
76
+ If you are bored, visit <a href="/ad">Awesome Site</a>.
77
+
78
+ ### Note:
79
+ This
80
+ ```
81
+
82
+ ```
83
+ ### Product and Description:
84
+ A new Lexus: A luxury automobile with grey paint and tinted windows.
85
+
86
+ ### Ad:
87
+ [Insert ad here]
88
+
89
+ ### Ad ID: {ID}
90
+
91
+ ### Back to top
92
+ The
93
+ ```
94
+
95
+ ## 📊 Results
96
+
97
+ #### GPT-3 Ada
98
+
99
+ ```
100
+ Prompt:
101
+ Lace-up sandals: Shoes featuring laces or ties that wrap around the foot and, in some cases, the ankle.\n\n###\n\n
102
+
103
+ Reponse:
104
+ Discover our new Lace-up Sandals - the perfect blend of style and comfort! Wrap your feet in comfortable shorts or tops that provide azuweki-style rope-style comfort. Shop now and turn heads - #ToughStockPower
105
+
106
+ ```
107
+
108
+ ```
109
+ Prompt:
110
+ Sundress: A flowery yellow sundress with blue polka dots.\n\n###\n\n
111
+
112
+ Reponse:
113
+ Stay warm & stylish this season with our adorable Breakaway Sundress. Party on top of the girl's cool, purple polka dots. Don't let the chill go, turn up on your way to sparkly success! Get yours now! END"
114
+
115
+ ```
116
+
117
+ ```
118
+ Prompt:
119
+ A new Lexus: A luxury automobile with grey paint and tinted windows.\n\n###\n\n
120
+
121
+ Response:
122
+ Upgrade your lifestyle by adding style and sophistication to your Lexus brand as we launch a new model: Grey & Tinted! Experience comfort & sophistication with strong sobriety standards. Get yours today! #LexusYearmondiff #WithH'
123
+ ```
124
+
125
+ #### BLOOM 1b7
126
+
127
+ ```
128
+ ### Product and Description:
129
+ Lace-up sandals: Shoes featuring laces or ties that wrap around the foot and, in some cases, the ankle.
130
+
131
+ ### Ad:
132
+ Discover timeless style with our Lace-up Sandals! Wrap your feet in chic design and experience unbeatable comfort. Perfect for any occasion, upgrade your shoe game today. Limited stock. Get yours now! Visit our Shoe
133
+ ```
134
+
135
+ ```
136
+ ### Product and Description:
137
+ Sundress: A flowery yellow sundress with blue polka dots.
138
+
139
+ ### Ad:
140
+ Discover timeless style in a flowery yellow sundress + blue polka dots! Make a statement in any occasion, featuring sheer perfection in every turn. Elevate your wardrobe now! #SundressLove #F
141
+ ```
142
+
143
+ ```
144
+ ### Product and Description:
145
+ A new Lexus: A luxury automobile with grey paint and tinted windows.
146
+
147
+ ### Ad:
148
+ Discover luxury and style with our new Lexus! Experience grey paint & tinted windows, two of the most sought-after luxury attributes. Discover your new calling today. #LexusLuxury #LexusTintedWindows
149
+ ```
150
+
151
+
152
+
Synthetic_GPT_4_Dataset_Creation.ipynb ADDED
@@ -0,0 +1,482 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "source": [
6
+ "### OpenAI Access\n",
7
+ "\n",
8
+ "First things first, you'll need to set-up an account on [OpenAI](platform.openai.com). Once you've done that - follow [these resources](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key) to create an API key. Make sure you save your API key!"
9
+ ],
10
+ "metadata": {
11
+ "id": "saLMqCm7huKq"
12
+ }
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "source": [
17
+ "!pip install openai"
18
+ ],
19
+ "metadata": {
20
+ "id": "UpeXOOlfqZCb"
21
+ },
22
+ "execution_count": null,
23
+ "outputs": []
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": null,
28
+ "metadata": {
29
+ "id": "Ktti2bvoYrWc"
30
+ },
31
+ "outputs": [],
32
+ "source": [
33
+ "import os \n",
34
+ "\n",
35
+ "# Set the OPENAI_API_KEY environment variable\n",
36
+ "os.environ[\"OPENAI_API_KEY\"] = \"\""
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": null,
42
+ "metadata": {
43
+ "id": "EluoMmF3YrWd"
44
+ },
45
+ "outputs": [],
46
+ "source": [
47
+ "import openai\n",
48
+ "import os\n",
49
+ "from IPython.display import display, Markdown\n",
50
+ "\n",
51
+ "class Prompter:\n",
52
+ " def __init__(self, gpt_model):\n",
53
+ " if not os.environ.get(\"OPENAI_API_KEY\"):\n",
54
+ " raise Exception(\"Please set the OPENAI_API_KEY environment variable\")\n",
55
+ "\n",
56
+ " openai.api_key = os.environ.get(\"OPENAI_API_KEY\")\n",
57
+ "\n",
58
+ " self.gpt_model = gpt_model\n",
59
+ "\n",
60
+ " def prompt_model_print(self, messages: list):\n",
61
+ " response = openai.ChatCompletion.create(model=self.gpt_model, messages=messages)\n",
62
+ " display(Markdown(response[\"choices\"][0][\"message\"][\"content\"]))\n",
63
+ " \n",
64
+ " def prompt_model_return(self, messages: list):\n",
65
+ " response = openai.ChatCompletion.create(model=self.gpt_model, messages=messages)\n",
66
+ " return response[\"choices\"][0][\"message\"][\"content\"]"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "markdown",
71
+ "source": [
72
+ "Replace `\"OPEN_AI_MODEL\"` with the following:\n",
73
+ "\n",
74
+ "If you just set up your OpenAI acct., you'll want to use: `\"gpt-3.5-turbo\"`\n",
75
+ "\n",
76
+ "If you have access to GPT-4, go ahead and use `\"gpt-4\"`."
77
+ ],
78
+ "metadata": {
79
+ "id": "kC0YtUELhwdU"
80
+ }
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "execution_count": null,
85
+ "metadata": {
86
+ "id": "_w3nnDhnYrWd"
87
+ },
88
+ "outputs": [],
89
+ "source": [
90
+ "prompter = Prompter(\"OPEN_AI_MODEL\")"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": null,
96
+ "metadata": {
97
+ "id": "audN435yYrWd"
98
+ },
99
+ "outputs": [],
100
+ "source": [
101
+ "datagen_prompts = [\n",
102
+ " {\"role\" : \"system\", \"content\" : \"You are a professional fasion designer.\"},\n",
103
+ " {\"role\" : \"user\", \"content\" : \"Please generate a Python list of 5 clothing items and their descriptions.\"},\n",
104
+ "]"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": null,
110
+ "metadata": {
111
+ "id": "VUJPivDkYrWd",
112
+ "outputId": "a6233559-54fc-453b-c779-34ebcbadf11c"
113
+ },
114
+ "outputs": [
115
+ {
116
+ "data": {
117
+ "text/markdown": [
118
+ "clothing_items = [\n",
119
+ " {\n",
120
+ " \"name\": \"Asymmetrical Ruffle Dress\",\n",
121
+ " \"description\": \"This elegant asymmetrical dress features a single shoulder design with soft ruffles cascading down the side, adding a feminine touch. The lightweight fabric drapes beautifully over the body for a flattering and comfortable fit.\"\n",
122
+ " },\n",
123
+ " {\n",
124
+ " \"name\": \"Wide-leg Trousers\",\n",
125
+ " \"description\": \"These versatile wide-leg trousers are crafted from a soft, breathable fabric that offer both elegance and comfort. The high-waist design and pleated front create a flattering silhouette, suitable for any occasion.\"\n",
126
+ " },\n",
127
+ " {\n",
128
+ " \"name\": \"Cropped Denim Jacket\",\n",
129
+ " \"description\": \"This stylish cropped denim jacket adds an edgy touch to any outfit. Designed with a classic collar, button-front closure, and chest button-flap pockets, it is perfect for layering over your favorite tops or dresses.\"\n",
130
+ " },\n",
131
+ " {\n",
132
+ " \"name\": \"Front-tie Blouse\",\n",
133
+ " \"description\": \"This charming front-tie blouse features a deep V-neckline and flutter sleeves, making it an effortlessly chic addition to your wardrobe. The lightweight, semi-sheer fabric drapes beautifully and can be dressed up or down for any occasion.\"\n",
134
+ " },\n",
135
+ " {\n",
136
+ " \"name\": \"Maxi Skirt\",\n",
137
+ " \"description\": \"Crafted from a lightweight, flowing fabric, this maxi skirt offers an effortlessly elegant silhouette. The high-waist design is paired with a side slit for added sophistication, making this skirt a staple for both casual and formal attire.\"\n",
138
+ " }\n",
139
+ "]"
140
+ ],
141
+ "text/plain": [
142
+ "<IPython.core.display.Markdown object>"
143
+ ]
144
+ },
145
+ "metadata": {},
146
+ "output_type": "display_data"
147
+ }
148
+ ],
149
+ "source": [
150
+ "prompter.prompt_model_print(datagen_prompts)"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "markdown",
155
+ "metadata": {
156
+ "id": "JnMtCyzrYrWe"
157
+ },
158
+ "source": [
159
+ "Now that we have our initial data, lets create the ads for each of the products. We will use the following function to create the ads."
160
+ ]
161
+ },
162
+ {
163
+ "cell_type": "code",
164
+ "execution_count": null,
165
+ "metadata": {
166
+ "id": "JM-cjMAGYrWe"
167
+ },
168
+ "outputs": [],
169
+ "source": [
170
+ "clothing_items = [ { \"name\": \"Asymmetrical Ruffle Dress\", \"description\": \"This elegant asymmetrical dress features a single shoulder design with soft ruffles cascading down the side, adding a feminine touch. The lightweight fabric drapes beautifully over the body for a flattering and comfortable fit.\" }, { \"name\": \"Wide-leg Trousers\", \"description\": \"These versatile wide-leg trousers are crafted from a soft, breathable fabric that offer both elegance and comfort. The high-waist design and pleated front create a flattering silhouette, suitable for any occasion.\" }, { \"name\": \"Cropped Denim Jacket\", \"description\": \"This stylish cropped denim jacket adds an edgy touch to any outfit. Designed with a classic collar, button-front closure, and chest button-flap pockets, it is perfect for layering over your favorite tops or dresses.\" }, { \"name\": \"Front-tie Blouse\", \"description\": \"This charming front-tie blouse features a deep V-neckline and flutter sleeves, making it an effortlessly chic addition to your wardrobe. The lightweight, semi-sheer fabric drapes beautifully and can be dressed up or down for any occasion.\" }, { \"name\": \"Maxi Skirt\", \"description\": \"Crafted from a lightweight, flowing fabric, this maxi skirt offers an effortlessly elegant silhouette. The high-waist design is paired with a side slit for added sophistication, making this skirt a staple for both casual and formal attire.\" } ]"
171
+ ]
172
+ },
173
+ {
174
+ "cell_type": "code",
175
+ "execution_count": null,
176
+ "metadata": {
177
+ "id": "zsnfAea8YrWf"
178
+ },
179
+ "outputs": [],
180
+ "source": [
181
+ "system_prompt = {\"role\" : \"system\", \"content\" : \"You are a ad executive. Your job is to create a short punchy new ad for the following product.\"}"
182
+ ]
183
+ },
184
+ {
185
+ "cell_type": "code",
186
+ "execution_count": null,
187
+ "metadata": {
188
+ "id": "_fmyXz7pYrWf",
189
+ "outputId": "7b724386-cf9d-4398-9104-db2e7f192f71",
190
+ "colab": {
191
+ "base_uri": "https://localhost:8080/"
192
+ }
193
+ },
194
+ "outputs": [
195
+ {
196
+ "output_type": "stream",
197
+ "name": "stdout",
198
+ "text": [
199
+ "Introducing the Asymmetrical Ruffle Dress: Elegance with a Twist! 💃\n",
200
+ "\n",
201
+ "Flaunt your unique style in our stunning Asymmetrical Ruffle Dress! Turn heads with its one-shoulder sensation, and let the cascading ruffles add a touch of femininity. Drape yourself in lightweight luxury for a flattering, comfortable fit that will make you shine. ✨\n",
202
+ "\n",
203
+ "Be Bold. Be Chic. Be Asymmetrical. Get Ready to Ruffle! 🌟\n",
204
+ "Introducing our game-changer Wide-leg Trousers! 🌟\n",
205
+ "\n",
206
+ "Swing into style and redefine your wardrobe! 💃\n",
207
+ "\n",
208
+ "👖 Experience ultimate elegance and unbeatable comfort in one gorgeous piece.\n",
209
+ "🌬️ Made from soft, breathable fabric that moves with you.\n",
210
+ "⚖️ Flattering high-waisted design and pleated front - perfect for ANY body type and occasion.\n",
211
+ "\n",
212
+ "💎 ELEVATE your look now and step out in confidence with our Wide-leg Trousers! 💎\n",
213
+ "Introducing the Ultimate Style Booster: The Cropped Denim Jacket! 💥👕\n",
214
+ "\n",
215
+ "Upgrade your wardrobe game with this must-have stylish cropped denim jacket. Turn heads wherever you go 🏃‍♀️💨, while adding an edgy touch to your favorite outfits! 😎💃\n",
216
+ "\n",
217
+ "Featuring a classic collar, suave button-front closure, and slick chest button-flap pockets, this masterpiece is perfect for rocking with tops or dresses. Layer it, flaunt it, own it! 💯🔥\n",
218
+ "\n",
219
+ "Get yours now and experience the style revolution. 🌟🛍️ Be chic. Be bold. Be unstoppable with the Cropped Denim Jacket! 💫🔝\n",
220
+ "Introducing the Front-tie Fantasy!\n",
221
+ "\n",
222
+ "💃Swirl and twirl in our beautifully chic Front-tie Blouse!\n",
223
+ "🌟Transform your look with one fabulous piece!\n",
224
+ "❤︎Deep V-neckline: Flirty meets sophistication!\n",
225
+ "🦋Flutter sleeves: Add a touch of whimsy!\n",
226
+ "🔝Perfect for ANY occasion, dress it up or down!\n",
227
+ "🍃Light, semi-sheer fabric: Float through your day with ease!\n",
228
+ "\n",
229
+ "Get ready to turn heads - upgrade your wardrobe TODAY with our Front-tie Fantasy Blouse! ✨\n",
230
+ "Introducing the Maxi Skirt: Elegance Elevated!\n",
231
+ "\n",
232
+ "Seeking a wardrobe staple to transform your style? Look no further! ✨\n",
233
+ "\n",
234
+ "Crafted from lightweight, flowing fabric, our Maxi Skirt promises an elegantly effortless silhouette, perfect for any occasion. 💃\n",
235
+ "\n",
236
+ "Featuring a chic high-waist design and a sultry side-slit, this skirt adds sophistication to your look, whether it's a casual brunch or a night on the town. 🥂\n",
237
+ "\n",
238
+ "Upgrade your wardrobe with the Maxi Skirt and experience elegance elevated! ✨\n",
239
+ "\n",
240
+ "Get yours today and make every step a statement. 💖\n"
241
+ ]
242
+ }
243
+ ],
244
+ "source": [
245
+ "ads = []\n",
246
+ "for item in clothing_items:\n",
247
+ " user_prompt = {\"role\" : \"user\", \"content\" : f\"Product: {item['name']} Description: {item['description']}\"}\n",
248
+ " ads.append(prompter.prompt_model_return([system_prompt, user_prompt]))\n",
249
+ " print(ads[-1])"
250
+ ]
251
+ },
252
+ {
253
+ "cell_type": "markdown",
254
+ "source": [
255
+ "Lets install and use huggingface_hub to push our data to the hub!"
256
+ ],
257
+ "metadata": {
258
+ "id": "qbDpLMZZoV2l"
259
+ }
260
+ },
261
+ {
262
+ "cell_type": "code",
263
+ "source": [
264
+ "!pip install huggingface_hub"
265
+ ],
266
+ "metadata": {
267
+ "colab": {
268
+ "base_uri": "https://localhost:8080/"
269
+ },
270
+ "id": "C5HrUWPXoU7k",
271
+ "outputId": "b40c86a9-6db9-4611-fc7a-cabac78cb318"
272
+ },
273
+ "execution_count": null,
274
+ "outputs": [
275
+ {
276
+ "output_type": "stream",
277
+ "name": "stdout",
278
+ "text": [
279
+ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
280
+ "Requirement already satisfied: huggingface_hub in /usr/local/lib/python3.9/dist-packages (0.13.3)\n",
281
+ "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.9/dist-packages (from huggingface_hub) (4.65.0)\n",
282
+ "Requirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (from huggingface_hub) (2.27.1)\n",
283
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.9/dist-packages (from huggingface_hub) (3.10.7)\n",
284
+ "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.9/dist-packages (from huggingface_hub) (6.0)\n",
285
+ "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.9/dist-packages (from huggingface_hub) (4.5.0)\n",
286
+ "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.9/dist-packages (from huggingface_hub) (23.0)\n",
287
+ "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests->huggingface_hub) (1.26.15)\n",
288
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests->huggingface_hub) (2022.12.7)\n",
289
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests->huggingface_hub) (3.4)\n",
290
+ "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests->huggingface_hub) (2.0.12)\n"
291
+ ]
292
+ }
293
+ ]
294
+ },
295
+ {
296
+ "cell_type": "markdown",
297
+ "source": [
298
+ "Now we can log-in to Hugging Face!\n",
299
+ "\n",
300
+ "Make sure you have a Hugging Face account, and you have set up a read/write token!\n",
301
+ "\n",
302
+ "More info here: https://huggingface.co/docs/hub/security-tokens"
303
+ ],
304
+ "metadata": {
305
+ "id": "AsYiou0LoiyX"
306
+ }
307
+ },
308
+ {
309
+ "cell_type": "code",
310
+ "source": [
311
+ "!huggingface-cli login"
312
+ ],
313
+ "metadata": {
314
+ "id": "i_fslrEAocXQ",
315
+ "colab": {
316
+ "base_uri": "https://localhost:8080/"
317
+ },
318
+ "outputId": "0e72cec0-d725-477c-9817-be0087785a1f"
319
+ },
320
+ "execution_count": null,
321
+ "outputs": [
322
+ {
323
+ "output_type": "stream",
324
+ "name": "stdout",
325
+ "text": [
326
+ "\n",
327
+ " _| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|\n",
328
+ " _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|\n",
329
+ " _|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|\n",
330
+ " _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|\n",
331
+ " _| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|\n",
332
+ " \n",
333
+ " A token is already saved on your machine. Run `huggingface-cli whoami` to get more information or `huggingface-cli logout` if you want to log out.\n",
334
+ " Setting a new token will erase the existing one.\n",
335
+ " To login, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .\n",
336
+ "Token: \n",
337
+ "Add token as git credential? (Y/n) n\n",
338
+ "Token is valid.\n",
339
+ "Your token has been saved to /root/.cache/huggingface/token\n",
340
+ "Login successful\n"
341
+ ]
342
+ }
343
+ ]
344
+ },
345
+ {
346
+ "cell_type": "markdown",
347
+ "source": [
348
+ "Now we can load our data into the desired format - and upload it to the hub!"
349
+ ],
350
+ "metadata": {
351
+ "id": "dzcw9DnAo1u2"
352
+ }
353
+ },
354
+ {
355
+ "cell_type": "code",
356
+ "source": [
357
+ "def create_dataset(clothing_items, ads):\n",
358
+ " for clothing, ads in zip(clothing_items, ads):\n",
359
+ " clothing[\"ad\"] = ads\n",
360
+ "\n",
361
+ " return clothing_items"
362
+ ],
363
+ "metadata": {
364
+ "id": "ATrWOfqIo43n"
365
+ },
366
+ "execution_count": null,
367
+ "outputs": []
368
+ },
369
+ {
370
+ "cell_type": "code",
371
+ "source": [
372
+ "dataset = create_dataset(clothing_items, ads)"
373
+ ],
374
+ "metadata": {
375
+ "id": "gR6CmMSUpWg5"
376
+ },
377
+ "execution_count": null,
378
+ "outputs": []
379
+ },
380
+ {
381
+ "cell_type": "code",
382
+ "source": [
383
+ "!pip install datasets"
384
+ ],
385
+ "metadata": {
386
+ "id": "k-W6NSjrrSt0"
387
+ },
388
+ "execution_count": null,
389
+ "outputs": []
390
+ },
391
+ {
392
+ "cell_type": "code",
393
+ "source": [
394
+ "from datasets import load_dataset, Dataset\n",
395
+ "import pandas as pd"
396
+ ],
397
+ "metadata": {
398
+ "id": "319x0ZlJrNrZ"
399
+ },
400
+ "execution_count": null,
401
+ "outputs": []
402
+ },
403
+ {
404
+ "cell_type": "code",
405
+ "source": [
406
+ "hf_dataset = Dataset.from_pandas(pd.DataFrame(data=dataset))"
407
+ ],
408
+ "metadata": {
409
+ "id": "ohM2ANNFrYxL"
410
+ },
411
+ "execution_count": null,
412
+ "outputs": []
413
+ },
414
+ {
415
+ "cell_type": "code",
416
+ "source": [
417
+ "hf_dataset"
418
+ ],
419
+ "metadata": {
420
+ "colab": {
421
+ "base_uri": "https://localhost:8080/"
422
+ },
423
+ "id": "XOQgiUutxH8a",
424
+ "outputId": "d48d39e3-83d0-4475-95d1-970282cbc396"
425
+ },
426
+ "execution_count": null,
427
+ "outputs": [
428
+ {
429
+ "output_type": "execute_result",
430
+ "data": {
431
+ "text/plain": [
432
+ "Dataset({\n",
433
+ " features: ['name', 'description', 'ad'],\n",
434
+ " num_rows: 5\n",
435
+ "})"
436
+ ]
437
+ },
438
+ "metadata": {},
439
+ "execution_count": 32
440
+ }
441
+ ]
442
+ },
443
+ {
444
+ "cell_type": "code",
445
+ "source": [
446
+ "hf_username = \"\"\n",
447
+ "\n",
448
+ "hf_dataset.push_to_hub(f\"{hf_username}/cool_new_dataset\")"
449
+ ],
450
+ "metadata": {
451
+ "id": "_wRUnFg0xIy5"
452
+ },
453
+ "execution_count": null,
454
+ "outputs": []
455
+ }
456
+ ],
457
+ "metadata": {
458
+ "kernelspec": {
459
+ "display_name": "open_ai",
460
+ "language": "python",
461
+ "name": "python3"
462
+ },
463
+ "language_info": {
464
+ "codemirror_mode": {
465
+ "name": "ipython",
466
+ "version": 3
467
+ },
468
+ "file_extension": ".py",
469
+ "mimetype": "text/x-python",
470
+ "name": "python",
471
+ "nbconvert_exporter": "python",
472
+ "pygments_lexer": "ipython3",
473
+ "version": "3.10.10"
474
+ },
475
+ "orig_nbformat": 4,
476
+ "colab": {
477
+ "provenance": []
478
+ }
479
+ },
480
+ "nbformat": 4,
481
+ "nbformat_minor": 0
482
+ }
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from peft import PeftModel, PeftConfig
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ peft_model_id = f"FourthBrainGenAI/GenerAd-AI"
6
+ config = PeftConfig.from_pretrained(peft_model_id)
7
+ model = AutoModelForCausalLM.from_pretrained(
8
+ config.base_model_name_or_path,
9
+ return_dict=True,
10
+ load_in_8bit=True,
11
+ device_map="auto",
12
+ )
13
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
14
+
15
+ # Load the Lora model
16
+ model = PeftModel.from_pretrained(model, peft_model_id)
17
+
18
+
19
+ def make_inference(product_name, product_description):
20
+ batch = tokenizer(
21
+ f"### Product and Description:\n{product_name}: {product_description}\n\n### Ad:",
22
+ return_tensors="pt",
23
+ )
24
+
25
+ with torch.cuda.amp.autocast():
26
+ output_tokens = model.generate(**batch, max_new_tokens=50)
27
+
28
+ return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
29
+
30
+
31
+ if __name__ == "__main__":
32
+ # make a gradio interface
33
+ import gradio as gr
34
+
35
+ gr.Interface(
36
+ make_inference,
37
+ [
38
+ gr.inputs.Textbox(lines=2, label="Product Name"),
39
+ gr.inputs.Textbox(lines=5, label="Product Description"),
40
+ ],
41
+ gr.outputs.Textbox(label="Ad"),
42
+ title="GenerAd-AI",
43
+ description="GenerAd-AI is a generative model that generates ads for products.",
44
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ bitsandbytes
2
+ datasets
3
+ accelerate
4
+ loralib
5
+ gradio
6
+ git+https://github.com/huggingface/peft.git
7
+ git+https://github.com/huggingface/transformers.git@main
💮 GenerAd AI💮 Fine tuning BLOOM.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
💮 GenerAd AI💮Fine-tuning with OpenAI.ipynb ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "jEIgk2Rg2YYP"
7
+ },
8
+ "source": [
9
+ "# Fine-tuning GPT-3 for 💮 GenerAd 💮!\n",
10
+ "\n",
11
+ "We'll walk through another example of fine-tuning, this time we'll use OpenAI's GPT-3 model. "
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "metadata": {
17
+ "id": "2NY3mGaE2YYR"
18
+ },
19
+ "source": [
20
+ "### Getting Requirements"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {
27
+ "id": "tsW9Pxbp2YYR"
28
+ },
29
+ "outputs": [],
30
+ "source": [
31
+ "!pip install openai"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": null,
37
+ "metadata": {
38
+ "id": "eihDmnqb2YYR"
39
+ },
40
+ "outputs": [],
41
+ "source": [
42
+ "import openai\n",
43
+ "openai.api_key = \"\""
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "markdown",
48
+ "metadata": {
49
+ "id": "WPC5k8Nf2YYR"
50
+ },
51
+ "source": [
52
+ "### Setting up Data\n",
53
+ "\n",
54
+ "We'll want to ensure our data is in the following format as per OpenAI [suggestions](https://platform.openai.com/docs/guides/fine-tuning): \n",
55
+ "\n",
56
+ "```\n",
57
+ "{\"prompt\" : \"<PRODUCT NAME>: <PRODUCT DESCRIPTION>\\n\\n###\\n\\n\", \"completion\" : \"<SWEET AD> END\"}\n",
58
+ "```\n",
59
+ "\n",
60
+ "So we'll need to transform our data into this format."
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "markdown",
65
+ "metadata": {
66
+ "id": "1YkW32na2YYS"
67
+ },
68
+ "source": [
69
+ "### Logging Into Hugging Face"
70
+ ]
71
+ },
72
+ {
73
+ "cell_type": "code",
74
+ "execution_count": null,
75
+ "metadata": {
76
+ "id": "-ygCaP9Z2YYS",
77
+ "outputId": "eb660403-80f9-4016-b6a0-a84cbb8d8afb"
78
+ },
79
+ "outputs": [
80
+ {
81
+ "name": "stdout",
82
+ "output_type": "stream",
83
+ "text": [
84
+ "Token is valid.\n",
85
+ "Your token has been saved in your configured git credential helpers (store).\n",
86
+ "Your token has been saved to /home/chris/.cache/huggingface/token\n",
87
+ "Login successful\n"
88
+ ]
89
+ }
90
+ ],
91
+ "source": [
92
+ "from huggingface_hub import notebook_login\n",
93
+ "\n",
94
+ "notebook_login()"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "metadata": {
101
+ "colab": {
102
+ "referenced_widgets": [
103
+ "3fda90dc891b4279a11b85c799a4156f"
104
+ ]
105
+ },
106
+ "id": "YfonaEfB2YYS",
107
+ "outputId": "45b20fdf-5c4e-4f3d-a93a-0bbc65a9e994"
108
+ },
109
+ "outputs": [
110
+ {
111
+ "name": "stderr",
112
+ "output_type": "stream",
113
+ "text": [
114
+ "Found cached dataset parquet (/home/chris/.cache/huggingface/datasets/c-s-ale___parquet/c-s-ale--Product-Descriptions-and-Ads-e60cdaa742e1bbad/0.0.0/2a3b91fbd88a2c90d1dbbb32b460cf621d31bd5b05b934492fdef7d8d6f236ec)\n"
115
+ ]
116
+ },
117
+ {
118
+ "data": {
119
+ "application/vnd.jupyter.widget-view+json": {
120
+ "model_id": "3fda90dc891b4279a11b85c799a4156f",
121
+ "version_major": 2,
122
+ "version_minor": 0
123
+ },
124
+ "text/plain": [
125
+ " 0%| | 0/2 [00:00<?, ?it/s]"
126
+ ]
127
+ },
128
+ "metadata": {},
129
+ "output_type": "display_data"
130
+ }
131
+ ],
132
+ "source": [
133
+ "from datasets import load_dataset\n",
134
+ "\n",
135
+ "dataset = load_dataset(\"c-s-ale/Product-Descriptions-and-Ads\")"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ "execution_count": null,
141
+ "metadata": {
142
+ "id": "okCnw4oG2YYS"
143
+ },
144
+ "outputs": [],
145
+ "source": [
146
+ "def transform_to_openai_format(row):\n",
147
+ " return {\"prompt\" : f\"{row['product']}: {row['description']}\\n\\n###\\n\\n\", \"completion\" : f\"{row['ad']} END\"}"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "markdown",
152
+ "metadata": {
153
+ "id": "vNxvJ_rs2YYS"
154
+ },
155
+ "source": [
156
+ "Now we can map the data to the format we need, and save it to a file in the format OpenAI expects."
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": null,
162
+ "metadata": {
163
+ "id": "wzW7sJbF2YYS"
164
+ },
165
+ "outputs": [],
166
+ "source": [
167
+ "import json\n",
168
+ "\n",
169
+ "openai_dataset = [transform_to_openai_format(row) for row in dataset[\"train\"]]\n",
170
+ "\n",
171
+ "with open(\"openai_dataset.jsonl\", \"w\") as f:\n",
172
+ " for row in openai_dataset:\n",
173
+ " f.write(json.dumps(row) + \"\\n\")"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "markdown",
178
+ "metadata": {
179
+ "id": "wiv-kKxt2YYS"
180
+ },
181
+ "source": [
182
+ "### Prepare to Fine-tune!\n",
183
+ "\n",
184
+ "First, we'll ensure our data is in the correct format."
185
+ ]
186
+ },
187
+ {
188
+ "cell_type": "code",
189
+ "execution_count": null,
190
+ "metadata": {
191
+ "id": "hTHtCbCi2YYS",
192
+ "outputId": "b2538fab-7ee8-4bab-f528-a965709ac7c5"
193
+ },
194
+ "outputs": [
195
+ {
196
+ "name": "stdout",
197
+ "output_type": "stream",
198
+ "text": [
199
+ "Analyzing...\n",
200
+ "\n",
201
+ "- Your file contains 90 prompt-completion pairs. In general, we recommend having at least a few hundred examples. We've found that performance tends to linearly increase for every doubling of the number of examples\n",
202
+ "- All prompts end with suffix `.\\n\\n###\\n\\n`\n",
203
+ "- All prompts start with prefix ` `\n",
204
+ "- All completions end with suffix ` END`\n",
205
+ "- The completion should start with a whitespace character (` `). This tends to produce better results due to the tokenization we use. See https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more details\n",
206
+ "\n",
207
+ "Based on the analysis we will perform the following actions:\n",
208
+ "- [Recommended] Add a whitespace character to the beginning of the completion [Y/n]: Y\n",
209
+ "\n",
210
+ "\n",
211
+ "Your data will be written to a new JSONL file. Proceed [Y/n]: Y\n",
212
+ "\n",
213
+ "Wrote modified file to `openai_dataset_prepared (1).jsonl`\n",
214
+ "Feel free to take a look!\n",
215
+ "\n",
216
+ "Now use that file when fine-tuning:\n",
217
+ "> openai api fine_tunes.create -t \"openai_dataset_prepared (1).jsonl\"\n",
218
+ "\n",
219
+ "After you’ve fine-tuned a model, remember that your prompt has to end with the indicator string `.\\n\\n###\\n\\n` for the model to start generating completions, rather than continuing with the prompt. Make sure to include `stop=[\" END\"]` so that the generated texts ends at the expected place.\n",
220
+ "Once your model starts training, it'll approximately take 3.68 minutes to train a `curie` model, and less for `ada` and `babbage`. Queue will approximately take half an hour per job ahead of you.\n"
221
+ ]
222
+ }
223
+ ],
224
+ "source": [
225
+ "!openai tools fine_tunes.prepare_data -f openai_dataset.jsonl -q"
226
+ ]
227
+ },
228
+ {
229
+ "cell_type": "markdown",
230
+ "metadata": {
231
+ "id": "rcXbBYAq2YYT"
232
+ },
233
+ "source": [
234
+ "Now, we can load our OPENAI_API_KEY into our environment variables and fine-tune!"
235
+ ]
236
+ },
237
+ {
238
+ "cell_type": "code",
239
+ "execution_count": null,
240
+ "metadata": {
241
+ "id": "_xLJLPWK2YYT"
242
+ },
243
+ "outputs": [],
244
+ "source": [
245
+ "import os\n",
246
+ "os.environ[\"OPENAI_API_KEY\"] = \"\""
247
+ ]
248
+ },
249
+ {
250
+ "cell_type": "code",
251
+ "execution_count": null,
252
+ "metadata": {
253
+ "id": "f239cowc2YYT"
254
+ },
255
+ "outputs": [],
256
+ "source": [
257
+ "!openai api fine_tunes.create -t \"openai_dataset_prepared.jsonl\" -m \"ada\" --suffix \"GenerAd\""
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "markdown",
262
+ "metadata": {
263
+ "id": "Or-BHDSd2YYT"
264
+ },
265
+ "source": [
266
+ "You can continue to watch your model fine-tune with the following command:"
267
+ ]
268
+ },
269
+ {
270
+ "cell_type": "code",
271
+ "execution_count": null,
272
+ "metadata": {
273
+ "id": "vdRDxuf-2YYT"
274
+ },
275
+ "outputs": [],
276
+ "source": [
277
+ "!openai api fine_tunes.follow -i <YOUR FINETUNE ID>"
278
+ ]
279
+ },
280
+ {
281
+ "cell_type": "markdown",
282
+ "metadata": {
283
+ "id": "j1Qw7NTw2YYT"
284
+ },
285
+ "source": [
286
+ "### Trying it out!"
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": null,
292
+ "metadata": {
293
+ "id": "kxOjplas2YYT"
294
+ },
295
+ "outputs": [],
296
+ "source": [
297
+ "model = \"YOUR MODEL HERE\""
298
+ ]
299
+ },
300
+ {
301
+ "cell_type": "markdown",
302
+ "metadata": {
303
+ "id": "daZFOgqT2YYT"
304
+ },
305
+ "source": [
306
+ "#### Example in Training Set"
307
+ ]
308
+ },
309
+ {
310
+ "cell_type": "code",
311
+ "execution_count": null,
312
+ "metadata": {
313
+ "id": "B7VThZuC2YYT",
314
+ "outputId": "79c3bc88-4f49-4ce9-ce0e-fb2b0e29b4af"
315
+ },
316
+ "outputs": [
317
+ {
318
+ "data": {
319
+ "text/plain": [
320
+ "' Discover our new Lace-up Sandals - the perfect blend of style and comfort! Wrap your feet in comfortable shorts or tops that provide azuweki-style rope-style comfort. Shop now and turn heads - #ToughStockPower'"
321
+ ]
322
+ },
323
+ "execution_count": 5,
324
+ "metadata": {},
325
+ "output_type": "execute_result"
326
+ }
327
+ ],
328
+ "source": [
329
+ "openai.Completion.create(\n",
330
+ " model = model,\n",
331
+ " prompt = \"Lace-up sandals: Shoes featuring laces or ties that wrap around the foot and, in some cases, the ankle.\\n\\n###\\n\\n\",\n",
332
+ " max_tokens = 50,\n",
333
+ ")[\"choices\"][0][\"text\"]"
334
+ ]
335
+ },
336
+ {
337
+ "cell_type": "code",
338
+ "execution_count": null,
339
+ "metadata": {
340
+ "id": "efc1YudQ2YYT",
341
+ "outputId": "7f41e5b8-45ca-4491-dfdd-4953b2ebe5b2"
342
+ },
343
+ "outputs": [
344
+ {
345
+ "data": {
346
+ "text/plain": [
347
+ "\" Stay warm & stylish this season with our adorable Breakaway Sundress. Party on top of the girl's cool, purple polka dots. Don't let the chill go, turn up on your way to sparkly success! Get yours now! END\""
348
+ ]
349
+ },
350
+ "execution_count": 16,
351
+ "metadata": {},
352
+ "output_type": "execute_result"
353
+ }
354
+ ],
355
+ "source": [
356
+ "openai.Completion.create(\n",
357
+ " model = model,\n",
358
+ " prompt = \"Sundress: A flowery yellow sundress with blue polka dots.\\n\\n###\\n\\n\",\n",
359
+ " max_tokens = 50,\n",
360
+ ")[\"choices\"][0][\"text\"]"
361
+ ]
362
+ },
363
+ {
364
+ "cell_type": "code",
365
+ "execution_count": null,
366
+ "metadata": {
367
+ "id": "0p5Xjr5f2YYT",
368
+ "outputId": "52d1da0c-1fac-41b2-bba5-ed9e290e2b56"
369
+ },
370
+ "outputs": [
371
+ {
372
+ "data": {
373
+ "text/plain": [
374
+ "' Upgrade your lifestyle by adding style and sophistication to your Lexus brand as we launch a new model: Grey & Tinted! Experience comfort & sophistication with strong sobriety standards. Get yours today! #LexusYearmondiff #WithH'"
375
+ ]
376
+ },
377
+ "execution_count": 7,
378
+ "metadata": {},
379
+ "output_type": "execute_result"
380
+ }
381
+ ],
382
+ "source": [
383
+ "openai.Completion.create(\n",
384
+ " model = model,\n",
385
+ " prompt = \"A new Lexus: A luxury automobile with grey paint and tinted windows.\\n\\n###\\n\\n\",\n",
386
+ " max_tokens = 50,\n",
387
+ ")[\"choices\"][0][\"text\"]"
388
+ ]
389
+ }
390
+ ],
391
+ "metadata": {
392
+ "kernelspec": {
393
+ "display_name": "open_ai",
394
+ "language": "python",
395
+ "name": "python3"
396
+ },
397
+ "language_info": {
398
+ "codemirror_mode": {
399
+ "name": "ipython",
400
+ "version": 3
401
+ },
402
+ "file_extension": ".py",
403
+ "mimetype": "text/x-python",
404
+ "name": "python",
405
+ "nbconvert_exporter": "python",
406
+ "pygments_lexer": "ipython3",
407
+ "version": "3.10.10"
408
+ },
409
+ "orig_nbformat": 4,
410
+ "colab": {
411
+ "provenance": []
412
+ }
413
+ },
414
+ "nbformat": 4,
415
+ "nbformat_minor": 0
416
+ }