Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
pipeline_tag: text2text-generation
|
5 |
+
inference: false
|
6 |
+
---
|
7 |
+
# ViPE-S-CTX7
|
8 |
+
|
9 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
10 |
+
|
11 |
+
ViPE: Visualize Pretty-much Everything, is the first automated model for translating any arbitrary piece of text into a visualizable prompt. It helps any text-to-image model in figurative or non-lexical language visualizations.
|
12 |
+
|
13 |
+
### Model Description
|
14 |
+
|
15 |
+
<!-- Provide a longer summary of what this model is. -->
|
16 |
+
|
17 |
+
- **Developed by:** [Computer Graphics Group, University of Tuebingen](https://uni-tuebingen.de/fakultaeten/mathematisch-naturwissenschaftliche-fakultaet/fachbereiche/informatik/lehrstuehle/computergrafik/lehrstuhl/)
|
18 |
+
- **Model type:** Auto-Regressive
|
19 |
+
- **Language:** English
|
20 |
+
- **License:** [MIT License for Non-Commercial Use](https://github.com/Hazel1994/ViPE/blob/main/LICENSE)
|
21 |
+
- **Based on:** [GPT2-Small](https://huggingface.co/gpt2)
|
22 |
+
- **Versions:** [ViPE-M-CTX7](https://huggingface.co/fittar/ViPE-M-CTX7) (255M parameters) and [ViPE-S-CTX7](https://huggingface.co/fittar/ViPE-S-CTX7) (117M parameters),
|
23 |
+
|
24 |
+
|
25 |
+
### Model Sources
|
26 |
+
|
27 |
+
<!-- Provide the basic links for the model. -->
|
28 |
+
|
29 |
+
- **Repository:** [Github](https://github.com/Hazel1994/ViPE)
|
30 |
+
- **Paper:** [EMNLP2023](https://2023.emnlp.org/program/)
|
31 |
+
|
32 |
+
### Down Stream Applications
|
33 |
+
ViPE provides a robust backbone for many practical applications such as music video generation and creative writing.
|
34 |
+
- #### Music Video Genrations
|
35 |
+
- **Repository:** [Github](https://github.com/Hazel1994/ViPE)
|
36 |
+
- **Demo:** [ViPE Videos](youtube link)
|
37 |
+
- #### Creative Writing
|
38 |
+
- **Demo:** [Hugging Face Playground](https://huggingface.co/spaces/fittar/ViPE)
|
39 |
+
|
40 |
+
|
41 |
+
### Direct Use
|
42 |
+
|
43 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
44 |
+
|
45 |
+
You can directly use the model to generate detailed prompts for any arbitrary text.
|
46 |
+
|
47 |
+
|
48 |
+
```python
|
49 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
50 |
+
|
51 |
+
|
52 |
+
def generate(text, model, tokenizer,device,do_sample,top_k=100, epsilon_cutoff=.00005, temperature=1):
|
53 |
+
#mark the text with special tokens
|
54 |
+
text=[tokenizer.eos_token + i + tokenizer.eos_token for i in text]
|
55 |
+
batch=tokenizer(text, padding=True, return_tensors="pt")
|
56 |
+
|
57 |
+
input_ids = batch["input_ids"].to(device)
|
58 |
+
attention_mask = batch["attention_mask"].to(device)
|
59 |
+
|
60 |
+
#how many new tokens to generate at max
|
61 |
+
max_prompt_length=50
|
62 |
+
|
63 |
+
generated_ids = model.generate(input_ids=input_ids,attention_mask=attention_mask, max_new_tokens=max_prompt_length, do_sample=do_sample,top_k=top_k, epsilon_cutoff=epsilon_cutoff, temperature=temperature)
|
64 |
+
#return only the generated prompts
|
65 |
+
pred_caps = tokenizer.batch_decode(generated_ids[:, -(generated_ids.shape[1] - input_ids.shape[1]):], skip_special_tokens=True)
|
66 |
+
|
67 |
+
return pred_caps
|
68 |
+
|
69 |
+
device='cpu'
|
70 |
+
model = GPT2LMHeadModel.from_pretrained('fittar/ViPE-S-CTX7')
|
71 |
+
model.to(device)
|
72 |
+
|
73 |
+
#ViPE-M's tokenizer is identical to that of GPT2-Medium
|
74 |
+
tokenizer = GPT2Tokenizer.from_pretrained('gpt2-medium')
|
75 |
+
tokenizer.pad_token = tokenizer.eos_token
|
76 |
+
|
77 |
+
# A list of abstract/figurative or any arbitrary combinations of keywords
|
78 |
+
texts=['lalala', 'I wanna start learning', 'free your mind; you will see the other side of life', 'brave; fantasy']
|
79 |
+
|
80 |
+
prompts=generate(texts,model,tokenizer,do_sample=True,device=device)
|
81 |
+
for t,p in zip(texts,prompts):
|
82 |
+
print('{} --> {}'.format(t,p))
|
83 |
+
|
84 |
+
|
85 |
+
```
|
86 |
+
|
87 |
+
|
88 |
+
### Recommendations
|
89 |
+
|
90 |
+
You can use either a comma or a semicolon to combine multiple keywords. for example ['dark, fantasy, brave'] or ['This is gonna be the best day of my life; do you agree?'].
|
91 |
+
However, a semicolon draws a stronger boundary between the keywords and encourages the model to transfer the last keyword in a given context (previous keywords).
|
92 |
+
|
93 |
+
|
94 |
+
## Training Details
|
95 |
+
|
96 |
+
### Training Data
|
97 |
+
|
98 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
99 |
+
|
100 |
+
[More Information Needed]
|
101 |
+
|
102 |
+
### Training Procedure
|
103 |
+
|
104 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
105 |
+
|
106 |
+
|
107 |
+
## Evaluation
|
108 |
+
|
109 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
110 |
+
|
111 |
+
|
112 |
+
## Citation
|
113 |
+
|
114 |
+
If you find ViPE useful, please cite our paper.
|
115 |
+
|
116 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
117 |
+
|
118 |
+
|
119 |
+
## Model Card Contact
|
120 |
+
|
121 |
+
[Hassan Shahmohammadi](https://fittar.me/)
|