fittar commited on
Commit
56992ea
·
1 Parent(s): 54499b0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +38 -19
README.md CHANGED
@@ -30,45 +30,64 @@ ViPE: Visualize Pretty-much Everything, is the first automated model for transla
30
  - **Paper:** [EMNLP2023](https://2023.emnlp.org/program/)
31
  - **Demo:**[ViPE Videos] (youtube link)
32
 
33
- ## Uses
34
-
35
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
36
 
37
  ### Direct Use
38
 
39
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
40
 
41
- [More Information Needed]
42
 
43
- ### Downstream Use [optional]
44
 
45
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
46
 
47
- [More Information Needed]
48
 
49
- ### Out-of-Scope Use
 
 
 
50
 
51
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
52
 
53
- [More Information Needed]
 
54
 
55
- ## Bias, Risks, and Limitations
 
 
56
 
57
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
58
 
59
- [More Information Needed]
 
 
60
 
61
- ### Recommendations
 
 
62
 
63
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
64
 
65
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
66
 
67
- ## How to Get Started with the Model
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- Use the code below to get started with the model.
70
 
71
- [More Information Needed]
72
 
73
  ## Training Details
74
 
 
30
  - **Paper:** [EMNLP2023](https://2023.emnlp.org/program/)
31
  - **Demo:**[ViPE Videos] (youtube link)
32
 
 
 
 
33
 
34
  ### Direct Use
35
 
36
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
37
 
38
+ you can directly use the model to generate detailed prompts for any arbitrary text.
39
 
 
40
 
41
+ ```python
42
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
43
 
 
44
 
45
+ def generate(text, model, tokenizer,device,do_sample,top_k=100, epsilon_cutoff=.00005, temperature=1):
46
+ #mark the text with special tokens
47
+ text=[tokenizer.eos_token + i + tokenizer.eos_token for i in text]
48
+ batch=tokenizer(text, padding=True, return_tensors="pt")
49
 
50
+ input_ids = batch["input_ids"].to(device)
51
+ attention_mask = batch["attention_mask"].to(device)
52
 
53
+ #how many new tokens to generate at max
54
+ max_prompt_length=50
55
 
56
+ 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)
57
+ #return only the generated prompts
58
+ pred_caps = tokenizer.batch_decode(generated_ids[:, -(generated_ids.shape[1] - input_ids.shape[1]):], skip_special_tokens=True)
59
 
60
+ return pred_caps
61
 
62
+ device='cpu'
63
+ model = GPT2LMHeadModel.from_pretrained('fittar/ViPE-M-CTX7')
64
+ model.to(device)
65
 
66
+ #ViPE-M's tokenizer is identical to that of GPT2-Medium
67
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2-medium')
68
+ tokenizer.pad_token = tokenizer.eos_token
69
 
70
+ # A list of abstract/figurative or any arbitrary combinations of keywords
71
+ texts=['lalala', 'I wanna start learning', 'free your mind; you will see the other side of life', 'brave; fantasy']
72
 
73
+ prompts=generate(texts,model,tokenizer,do_sample=True,device=device)
74
+ for t,p in zip(texts,prompts):
75
+ print('{} --> {}'.format(t,p))
76
 
77
+ lalala --> A group of people chanting "la la la" around a bonfire on a beach at night
78
+ I wanna start learning --> A child sitting in a library surrounded by books, excitedly flipping through pages of a book
79
+ free your mind; you will see the other side of life --> An astronaut floating in space with a sense of floating weightlessness, looking down towards the earth
80
+ brave; fantasy --> A brave knight with shining armor fighting a fierce dragon in a misty forest
81
+
82
+ ```
83
+
84
+
85
+ ### Recommendations
86
+
87
+ For combining multiple keywords, separate them using a comma. for example ['dark, fantasy, brave']
88
+ for phrases or sentences, a semicolon is preferable. For example ['This is gonna be the best day of my life; do you agree?']
89
 
 
90
 
 
91
 
92
  ## Training Details
93