File size: 1,392 Bytes
3935a33
 
85e94c0
 
c6e4eff
 
 
 
 
 
 
85e94c0
 
 
 
 
d82d74a
 
3935a33
85e94c0
c6e4eff
 
a78de63
 
2951a3a
c6e4eff
85e94c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15085ad
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
---
license: creativeml-openrail-m
language:
- en
widget:
- text: "1girl"
- text: "1boy"
- text: "1girl, masterpiece"
- text: "1boy, national basketball association"
- text: "1girl, 1boy"
- text: "1girl, highres"
tags:
- stable-diffusion
- anime
- anything-v4
- art
datasets:
- FredZhang7/anime-prompts-180K
---

## Fast Anime PromptGen

Trained on the 80K Safebooru prompts

(todo: complete data preprocessing and training description)


## Greedy Search
```python
import torch
from transformers import GPT2Tokenizer, GPT2LMHeadModel, pipeline
tokenizer = GPT2Tokenizer.from_pretrained('distilgpt2')
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
model = GPT2LMHeadModel.from_pretrained('FredZhang7/anime-anything-promptgen')

prompt = r'1girl, master piece,'

# generate text using fine-tuned model
nlp = pipeline('text-generation', model=model, tokenizer=tokenizer)

# generate 10 samples using greedy search
outs = nlp(prompt, max_length=76, num_return_sequences=10, do_sample=True, temperature=0.7, top_k=4, early_stopping=True)

print('\nInput:\n' + 100 * '-')
print('\033[96m' + prompt + '\033[0m')
print('\nOutput:\n' + 100 * '-')
for i in range(len(outs)):
    # remove trailing commas and double spaces
    outs[i] = str(outs[i]['generated_text']).replace('  ', '').rstrip(',')
print('\033[92m' + '\n\n'.join(outs) + '\033[0m\n')
```

Output Example:

![](./greedy_search.png)