BigSalmon commited on
Commit
c80339a
·
1 Parent(s): ae1ca1c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +64 -0
README.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("BigSalmon/Infill")
5
+
6
+ model = AutoModelForCausalLM.from_pretrained("BigSalmon/Infill")
7
+ ```
8
+
9
+ ```
10
+ Demo:
11
+ https://huggingface.co/spaces/BigSalmon/FormalInformalConciseWordy
12
+ ```
13
+
14
+ ```
15
+ prompt = """informal english: corn fields are all across illinois, visible once you leave chicago.\nTranslated into the Style of Abraham Lincoln:"""
16
+ input_ids = tokenizer.encode(prompt, return_tensors='pt')
17
+ outputs = model.generate(input_ids=input_ids,
18
+ max_length=10 + len(prompt),
19
+ temperature=1.0,
20
+ top_k=50,
21
+ top_p=0.95,
22
+ do_sample=True,
23
+ num_return_sequences=5,
24
+ early_stopping=True)
25
+ for i in range(5):
26
+ print(tokenizer.decode(outputs[i]))
27
+ ```
28
+ Most likely outputs (Disclaimer: I highly recommend using this over just generating):
29
+ ```
30
+ prompt = """informal english: corn fields are all across illinois, visible once you leave chicago.\nTranslated into the Style of Abraham Lincoln:"""
31
+ text = tokenizer.encode(prompt)
32
+ myinput, past_key_values = torch.tensor([text]), None
33
+ myinput = myinput
34
+ myinput= myinput.to(device)
35
+ logits, past_key_values = model(myinput, past_key_values = past_key_values, return_dict=False)
36
+ logits = logits[0,-1]
37
+ probabilities = torch.nn.functional.softmax(logits)
38
+ best_logits, best_indices = logits.topk(250)
39
+ best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
40
+ text.append(best_indices[0].item())
41
+ best_probabilities = probabilities[best_indices].tolist()
42
+ words = []
43
+ print(best_words)
44
+ ```
45
+
46
+ Infill / Infilling / Masking / Phrase Masking
47
+
48
+ ```
49
+ his contention [blank] by the evidence [sep] was refuted [answer]
50
+
51
+ ***
52
+
53
+ few sights are as [blank] new york city as the colorful, flashing signage of its bodegas [sep] synonymous with [answer]
54
+
55
+ ***
56
+
57
+ when rick won the lottery, all of his distant relatives [blank] his winnings [sep] clamored for [answer]
58
+
59
+ ***
60
+
61
+ the library’s quiet atmosphere encourages visitors to [blank] in their work [sep] immerse themselves [answer]
62
+
63
+ ***
64
+ ```