Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
T5 Model for Formality Style Transfer. Trained on the GYAFC dataset.
|
2 |
+
|
3 |
+
|
4 |
+
PyTorch model available.
|
5 |
+
|
6 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
7 |
+
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("Isotonic/informal_to_formal")
|
9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Isotonic/informal_to_formal")
|
10 |
+
|
11 |
+
sentence = "will you look into these two deals and let me know"
|
12 |
+
|
13 |
+
text = "Make the following sentence Formal: " + sentence + " </s>"
|
14 |
+
|
15 |
+
encoding = tokenizer.encode_plus(text,pad_to_max_length=True, return_tensors="pt")
|
16 |
+
input_ids, attention_masks = encoding["input_ids"].to("cuda"), encoding["attention_mask"].to("cuda")
|
17 |
+
|
18 |
+
|
19 |
+
outputs = model.generate(
|
20 |
+
input_ids=input_ids, attention_mask=attention_masks,
|
21 |
+
max_length=256,
|
22 |
+
do_sample=True,
|
23 |
+
top_k=120,
|
24 |
+
top_p=0.95,
|
25 |
+
early_stopping=True,
|
26 |
+
num_return_sequences=5
|
27 |
+
)
|
28 |
+
|
29 |
+
for output in outputs:
|
30 |
+
line = tokenizer.decode(output, skip_special_tokens=True,clean_up_tokenization_spaces=True)
|
31 |
+
print(line)
|
32 |
+
Output: "Would you look into the two deals in question, then let me know?"
|