File size: 2,657 Bytes
bc73095
 
 
 
 
fcda7c5
 
 
5e6371d
03f29b2
ae4f0e0
bc73095
 
 
1155cac
bc73095
 
fcda7c5
 
bc73095
fcda7c5
 
d290ea8
d1e314e
 
bc73095
d290ea8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa25af6
d290ea8
 
 
d1e314e
d290ea8
d1e314e
d290ea8
 
 
 
 
 
d1e314e
 
 
 
 
fcda7c5
bc73095
d290ea8
fcda7c5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
license: mit
model-index:
- name: chef-gpt-base
  results: []
language:
- bg
pipeline_tag: text-generation
widget:
- text: "[ING]1 картоф[REC]"
- text: "[ING]4 бр. яйца[EOL]1 кофичка кисело мляко[EOL]1/4 ч.л. сода[REC]"
---

# chef-gpt-base
GPT-2 architecture trained to generate recipes based on ingredients. [Visit website](https://chef-gpt.streamlit.app/).

## Model description
This is GPT-2 pretrained on a custom dataset of recipies in Bulgarian.
You can find the dataset [here](https://www.kaggle.com/datasets/auhide/bulgarian-recipes-dataset).

## Usage
```python
import re
# Using this library to beautifully print the long recipe string.
from pprint import pprint

from transformers import AutoModelForCausalLM, AutoTokenizer


# Load the model and tokenizer:
MODEL_ID = "auhide/chef-gpt-base"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
chef_gpt = AutoModelForCausalLM.from_pretrained(MODEL_ID)

# Prepare the input:
ingredients = [
    "1 ч.ч. брашно",
    "4 яйца",
    "1 кофичка кисело мляко",
    "1/4 ч.л. сода",
]
input_text = f"[ING]{'[EOL]'.join(ingredients)}[REC]"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids

# Generate text:
output = chef_gpt.generate(input_ids, max_length=150)
recipe = tokenizer.batch_decode(output)[0]
# Get the generated recipe - it is up until the 1st [SEP] token.
recipe = re.findall(r"\[REC\](.+?)\[SEP\]", recipe)[0]

print("Съставки/Ingredients:")
pprint(ingredients)
print("\nРецепта/Recipe:")
pprint(recipe)
```
```bash
Съставки/Ingredients:
['1 ч.ч. брашно', '4 яйца', '1 кофичка кисело мляко', '1/4 ч.л. сода']

Рецепта/Recipe:
('В дълбока купа се разбиват яйцата. Добавя се киселото мляко, в което '
 'предварително е сложена содата, и се разбива. Добавя се брашното и се омесва '
 'тесто. Ако е много гъсто се добавя още малко брашно, ако е много гъсто се '
 'добавя още малко брашно. Фурната се загрява предварително на 180С градуса. '
 'Когато тестото е готово, се вади от фурната и се разделя на три части.')
```


## Additional tokens
- [ING] - ingredients token; denotes the begining of the tokens representing the ingredients
- [EOL] - end-of-line token; equivalent to a newline
- [REC] - recipe token; denotes the begining of the recipe