add all files
Browse files- README.md +4 -11
- app.py +59 -0
- khaanaGPT/added_tokens.json +5 -0
- khaanaGPT/config.json +39 -0
- khaanaGPT/merges.txt +0 -0
- khaanaGPT/pytorch_model.bin +3 -0
- khaanaGPT/special_tokens_map.json +6 -0
- khaanaGPT/tokenizer.json +0 -0
- khaanaGPT/tokenizer_config.json +11 -0
- khaanaGPT/training_args.bin +3 -0
- khaanaGPT/vocab.json +0 -0
- poetry.lock +0 -0
- pyproject.toml +17 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,12 +1,5 @@
|
|
1 |
-
|
2 |
-
title: KhaanaGPT
|
3 |
-
emoji: 🦀
|
4 |
-
colorFrom: indigo
|
5 |
-
colorTo: gray
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.18.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
---
|
11 |
|
12 |
-
|
|
|
|
|
|
1 |
+
# खानाGPT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
Just a basic app to generate Indian recipes from listed ingredients. It's good, not great, it might add more ingredients or ignore some existing ingredients.
|
4 |
+
|
5 |
+
This was my first attempt at fine-tuning causalLM models. I used `GPT-2 Small` for this and it was fun, learnt a lot and the outputs are as expected.
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
import warnings
|
5 |
+
warnings.simplefilter('ignore')
|
6 |
+
|
7 |
+
model_path = './khaanaGPT'
|
8 |
+
|
9 |
+
contrastive_search_config = dict(
|
10 |
+
penalty_alpha = 0.5,
|
11 |
+
top_k = 5,
|
12 |
+
max_new_tokens = 512,
|
13 |
+
pad_token_id = 50259
|
14 |
+
)
|
15 |
+
|
16 |
+
model = pipeline('text-generation',model=model_path)
|
17 |
+
|
18 |
+
def create_prompt(ingredients):
|
19 |
+
ingredients = ','.join([x.strip() for x in ingredients.split(',')])
|
20 |
+
ingredients = ingredients.strip().replace(',','\n').lower()
|
21 |
+
s = f"<|startoftext|>Ingredients:\n{ingredients}\n\nInstructions:\n"
|
22 |
+
return s
|
23 |
+
|
24 |
+
def generate(prompt):
|
25 |
+
recipe = model(prompt,**contrastive_search_config)[0]['generated_text']
|
26 |
+
recipe = recipe.replace('<|startoftext|>','')
|
27 |
+
return recipe
|
28 |
+
|
29 |
+
def wrapper(ingredients):
|
30 |
+
prompt = create_prompt(ingredients)
|
31 |
+
recipe = generate(prompt)
|
32 |
+
return recipe
|
33 |
+
|
34 |
+
intro_html = """
|
35 |
+
<center><h1>खानाGPT</h1></center>
|
36 |
+
<center>
|
37 |
+
<p>it's not perfect, may ± ingredients. The recipes are coherent,
|
38 |
+
but the main purpose of this project was to understand fine-tuning a causalLM like GPT-2.
|
39 |
+
This model was fine-tuned on GPT-2 Small.</p>
|
40 |
+
</center>
|
41 |
+
"""
|
42 |
+
|
43 |
+
with gr.Blocks() as demo:
|
44 |
+
gr.HTML(intro_html)
|
45 |
+
|
46 |
+
ingredients = gr.Textbox(label="ingredients",
|
47 |
+
placeholder='separate the ingredients with a comma.')
|
48 |
+
|
49 |
+
output = gr.Textbox(label="recipe",lines=15,)
|
50 |
+
greet_btn = gr.Button("Create a recipe!")
|
51 |
+
|
52 |
+
gr.Examples(['yellow dal, turmeric, green peas, tomatoes',
|
53 |
+
'chicken, soy sauce, tomato sauce, vinegar'],
|
54 |
+
inputs=ingredients
|
55 |
+
)
|
56 |
+
|
57 |
+
greet_btn.click(fn=wrapper, inputs=ingredients, outputs=output)
|
58 |
+
|
59 |
+
demo.launch()
|
khaanaGPT/added_tokens.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"<|pad|>": 50259,
|
3 |
+
"<|startoftext|>": 50257,
|
4 |
+
"<|unknown|>": 50258
|
5 |
+
}
|
khaanaGPT/config.json
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "gpt2",
|
3 |
+
"activation_function": "gelu_new",
|
4 |
+
"architectures": [
|
5 |
+
"GPT2LMHeadModel"
|
6 |
+
],
|
7 |
+
"attn_pdrop": 0.1,
|
8 |
+
"bos_token_id": 50256,
|
9 |
+
"embd_pdrop": 0.1,
|
10 |
+
"eos_token_id": 50256,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"layer_norm_epsilon": 1e-05,
|
13 |
+
"model_type": "gpt2",
|
14 |
+
"n_ctx": 1024,
|
15 |
+
"n_embd": 768,
|
16 |
+
"n_head": 12,
|
17 |
+
"n_inner": null,
|
18 |
+
"n_layer": 12,
|
19 |
+
"n_positions": 1024,
|
20 |
+
"reorder_and_upcast_attn": false,
|
21 |
+
"resid_pdrop": 0.1,
|
22 |
+
"scale_attn_by_inverse_layer_idx": false,
|
23 |
+
"scale_attn_weights": true,
|
24 |
+
"summary_activation": null,
|
25 |
+
"summary_first_dropout": 0.1,
|
26 |
+
"summary_proj_to_labels": true,
|
27 |
+
"summary_type": "cls_index",
|
28 |
+
"summary_use_proj": true,
|
29 |
+
"task_specific_params": {
|
30 |
+
"text-generation": {
|
31 |
+
"do_sample": true,
|
32 |
+
"max_length": 50
|
33 |
+
}
|
34 |
+
},
|
35 |
+
"torch_dtype": "float32",
|
36 |
+
"transformers_version": "4.20.1",
|
37 |
+
"use_cache": true,
|
38 |
+
"vocab_size": 50260
|
39 |
+
}
|
khaanaGPT/merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
khaanaGPT/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3565459822f2fe308ed7e0ac736366ef029c2f64b69379ab11306f805f3157ea
|
3 |
+
size 510405737
|
khaanaGPT/special_tokens_map.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<|startoftext|>",
|
3 |
+
"eos_token": "<|endoftext|>",
|
4 |
+
"pad_token": "<|pad|>",
|
5 |
+
"unk_token": "<|unknown|>"
|
6 |
+
}
|
khaanaGPT/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
khaanaGPT/tokenizer_config.json
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"bos_token": "<|startoftext|>",
|
4 |
+
"eos_token": "<|endoftext|>",
|
5 |
+
"model_max_length": 1024,
|
6 |
+
"name_or_path": "gpt2",
|
7 |
+
"pad_token": "<|pad|>",
|
8 |
+
"special_tokens_map_file": null,
|
9 |
+
"tokenizer_class": "GPT2Tokenizer",
|
10 |
+
"unk_token": "<|unknown|>"
|
11 |
+
}
|
khaanaGPT/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ad32707bc4b19e7bc4f7e6089539caab91af3f0984c90926718351e222e31e12
|
3 |
+
size 3247
|
khaanaGPT/vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "khaanagpt"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["shreydan <iamshreydan@gmail.com>"]
|
6 |
+
readme = "README.md"
|
7 |
+
|
8 |
+
[tool.poetry.dependencies]
|
9 |
+
python = "^3.10"
|
10 |
+
transformers = "^4.26.1"
|
11 |
+
torch = "^1.13.1"
|
12 |
+
gradio = "^3.18.0"
|
13 |
+
|
14 |
+
|
15 |
+
[build-system]
|
16 |
+
requires = ["poetry-core"]
|
17 |
+
build-backend = "poetry.core.masonry.api"
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
gradio
|