Skip to content

Commit

Permalink
All scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaminik1996 committed May 13, 2022
1 parent 9df5be9 commit 20b13c1
Show file tree
Hide file tree
Showing 14 changed files with 41,533 additions and 0 deletions.
20,646 changes: 20,646 additions & 0 deletions augmented_data_translator/by_prime.txt

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions augmented_data_translator/extract_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("t5-small")
#tokenizer.add_tokens("<cat>")
model = AutoModelForSeq2SeqLM.from_pretrained("./results/checkpoint-51650")
f1 = open("../data/extract_bx.txt", "r")
f2 = open("../data/extract_by.txt", "r")
a1 = f1.readlines()
a2 = f2.readlines()
f3 = open("../data/extract_by_prime.txt", "w")
prefix = "augmented ShEn to formal En: "
print("Starting translation")
for i in range(len(a1)):
input_sh = prefix + a1[i] + "<cat>" + a2[i]
input_ids = tokenizer.encode(input_sh, return_tensors="pt")
output = model.generate(input_ids, max_length=128)
t5_translated = tokenizer.decode(output[0], skip_special_tokens=True)
print(input_sh)
print(t5_translated)
print("\n")
f3.write(t5_translated)
f3.write("\n")
f1.close()
f2.close()
f3.close()
19 changes: 19 additions & 0 deletions augmented_data_translator/translate_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from transformers import AutoTokenizer, DataCollatorForSeq2Seq, AutoModelForSeq2SeqLM
import json
tokenizer = AutoTokenizer.from_pretrained("t5-small")
model = AutoModelForSeq2SeqLM.from_pretrained("./results/checkpoint-51650")
f1 = open("../data/augmented_data.json", "r")
a = json.load(f1)
a = a['data']
i = 0
f2 = open("by_prime.txt", "w")
prefix = "augmented ShEn to formal En: "
for example in a:
input_aug = prefix + example["translation"]["b_x"] + "<cat>" + example["translation"]["b_y"]
input_ids = tokenizer.encode(input_aug, return_tensors="pt")
output = model.generate(input_ids, max_length=128)
t5_translated = tokenizer.decode(output[0], skip_special_tokens=True)
print(t5_translated)
print("\n")
f2.write(t5_translated)
f2.write("\n")
31 changes: 31 additions & 0 deletions baseline/extract_baseline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import re
import argparse


def main():

device = "cuda:0" if torch.cuda.is_available() else "cpu"
print("Device is ", device)

tokenizer = AutoTokenizer.from_pretrained("filco306/gpt2-shakespeare-paraphraser")
model = AutoModelForCausalLM.from_pretrained("filco306/gpt2-shakespeare-paraphraser", pad_token_id=tokenizer.eos_token_id)
model.to(device)

generate("../data/extract.txt", "extract_baseline3.txt", tokenizer, model, device)

def generate(input_path, output_path, tokenizer, model, device):

f = open(input_path, "r")
input = f.readlines()

output_file = open(output_path, "w")
print(input)
for sentence in input:
input_ids = tokenizer.encode(sentence.strip(), return_tensors='pt').to(device)
greedy_output = model.generate(no_repeat_ngram_size=2, input_ids=input_ids, max_length=80, early_stopping = True, num_beams=5)
output_file.write('\n')
output_file.write(tokenizer.decode(greedy_output[0], skip_special_tokens=True))

main()
14 changes: 14 additions & 0 deletions baseline/extract_baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

I am sorry thou wilt leave my father so. I am sorry thou wilt leave my father so.I thank thee, for I am sorry thou wilt leave my father so.I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee, for I thank thee
Our house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.Thy house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.Thy house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.Thy house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.Thy house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.Thy house is
And Launcelot, soon at supper shalt thou see Lorenzo, who is thy new master’s guest.Go thou, Launcelot, and see Lorenzo, who is thy new master’s guest, soon at supper.Go thou, and see Lorenzo, who is thy new master’s guest, soon at supper.Go thou, and see Lorenzo, who is thy new master’s guest, come hither, for I have a mind to him.Go thou, and see Lorenzo, who is thy new master’s guest, come hither, for I have a mind to him
Give him this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have this letter. And let him have
Adieu!—I'll be gone!—I’ll be gone!Adieu!—I’ll leave thee!Adieu!—I’ll leave thee!Adieu!—I’ll leave thee!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu
If a Christian do not play the knave and get thee, I am much deceived. I am much deceived, sir, in the Christian's play.I do much mistake, sir, in the Christian's play, for I do not play the knave and get thee.I do much mistake, sir, in the Christian's play, for I do not play the knave and get thee.I do much mistake, sir, in the Christian's play, for I do not play the knave and get thee not.I do much mistake, sir, sir, in the Christian's play, for I
But adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. adieu. ad
These foolish drops do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.O foolish drops, do something drown my manly spirit.
Adieu. Farewell.Adieu. Farewell.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu
Farewell, good Launcelot. Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.Farewell, good Launcelot.
Alack, what heinous sin is it in me To be ashamed to be my father’s child!O, what heinous sin is it in me To be ashamed to be my father’s child!O, what heinous sin is it in me To be ashamed to be my father’s child!O, what heinous sin is it in me To be ashamed to be my father’s child!O, what heinous sin is it in me To be ashamed to be my father’s child!O, what heinous sin is it in me To be ashamed to be my father�
But though I am a daughter to his blood, I am not to his manners. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter.I am not to his manners, though I am his daughter; I am not to his manners
O Lorenzo, If thou keep promise, I shall end this strife, Become a Christian and thy loving wife.O Lorenzo, If thou keep promise, I’ll end this strife, Become a Christian and thy loving wife.O Lorenzo, if thou keep promise, I’ll end this strife, Become a Christian and thy loving wife.O Lorenzo, if thou keep promise, I’ll end this strife, Become a Christian and thy loving wife.O Lorenzo, if thou keep promise, I’ll end this strife, Become a Christian and thy loving wife.O Lorenzo, if thou
14 changes: 14 additions & 0 deletions baseline/extract_baseline2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

I am sorry thou wilt leave my father so. I am sorry thou wilt leave my father so.I prithee leave my father so.I prithee leave my father so.I prithee leave him so.I prithee leave him so.I prithee leave him so.I prithee leave him so.I prithee leave him so.I prithee leave him so.I prithee leave him so.I prithee leave him so.I prithee leave him so.I prithee
Our house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness. Thy house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.Thy house is hell, and thou, a merry fiend, Didst rob it of some taste of tediousness. Thy house is hell, and thou, a merry fiend, Didst rob it of some taste of tediousness.Thy house is hell, and thou, a merry fiend, Didst rob it of some taste of tediousness. Thy house is hell, and
And Launcelot, soon at supper shalt thou see Lorenzo, who is thy new master’s guest.Thou shalt see, Launcelot, soon at supper shalt thou see Lorenzo, Who is thy new master’s guest.Thou shalt see, Launcelot, soon at supper shalt thou see Lorenzo, Who is thy new master’s guest.Thou shalt see, Launcelot, who is thy new master’s guest.Thou shalt see, Launcelot, who is thy new master’s guest.Thou shalt see, Launcelot
Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this letter. Give him this
Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!Adieu!
If a Christian do not play the knave and get thee, I am much deceived. I am much deceived when a Christian do not play the knave and get thee.When a Christian do not play the knave and get thee, I am much deceived. I am much deceived when a Christian do not play the knave and get thee.When a Christian do not play the knave and get thee, I am much deceived. I am much deceived when a Christian do not play the knave and get thee.When a Christian do not play the knave and get thee, I am much deceived.I
But adieu. adieu. adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Ad
These foolish drops do something drown my manly spirit.
Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.Adieu.
Farewell, good Launcelot. Farewell, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu, good Launcelot.Adieu
Alack, what heinous sin is it in me To be ashamed to be my father’s child!O, what heinous sin is it in me To be ashamed to be my father’s child!O, what heinous sin is it in me To be ashamed to be my father’s child’s father!O, what heinous sin is it in me To be ashamed to be my father’s child’s father’s child!O, what heinous sin is it in me To be ashamed to be my father’s child’s father’s
But though I am a daughter to his blood, I am not to his manners. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his daughter. I am not to his manners, though I am his wife. I am not to his manners, though I am his wife. I am not to his manners, though I am his daughter. I am not to his manners, though I am his wife. I am not to his manners,
O Lorenzo, If thou keep promise, I shall end this strife, Become a Christian and thy loving wife. Lorenzo, If thou keep promise, I’ll end this strife, Become a Christian and thy loving wife.O Lorenzo, if thou keep’st promise, I’ll end this strife, Become a Christian and thy loving wife.O Lorenzo, if thou keep’st promise, I’ll end this strife, Become a Christian and thine own wife.O Lorenzo, if thou keep’st promise, I’ll end this strife, Become a Christian and thine
14 changes: 14 additions & 0 deletions baseline/extract_baseline3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

I am sorry thou wilt leave my father so.I thank thee that thou hast left me so, for I am most sorry for thy father’s absence.” ’Twas I that did leave thee so; for, as thou didst say, it is my duty to go with thee, and I will not stay for thee. ‘I do beseech
Our house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.Thy house’s hell hath robbed thee, And thou merry fiend, didst steal it from some sweet taste Of tediousity.” I have a house, my lord, in hell; and, as thou art, Thou hast robbed me of
And Launcelot, soon at supper shalt thou see Lorenzo, who is thy new master’s guest. ’Twas well said, and now thou shalt see, Lorenzo is the guest of thine.Thou shalt not see me till supper-time, For I am the new-crowned guest o' th' house of Lorenzo.”   
Give him this letter. Give him the letter, and let him know of it.Go with him to his lodging, And bring him word of ’t. And let his letter be given him, That he may acquaint you with it, as I do.” Bring him hither to my lodging; And give him leave to sup with me, As I have a letter
Adieu!Farewell!” ’Twas well said.’Tis well spoken.Tush, tush!— Farewell, farewell!   Tut, thou hast well chide'd me, and so well didst thou say it. Ay, sooth, ‘twas said well, And so it was well
If a Christian do not play the knave and get thee, I am much deceived. I have much mistaken thee.I do much mistake thee; for, as thou art, A Christian play'st me not; and, being so, Thou hast much misgivèd me.” ’Tis much to be deceived, my lord, by a man of faith.
But adieu. Farewell.Adieu to you. ’Tis time to part.’tis time for parting. Farewell to thee, and part with me, for this is the hour of my departure. I will not stay for thee; I'll go with thee to my lodging, where I shall stay till the morrow come; and so farewell.
These foolish drops do something drown my manly spirit.Foolish drops have something to do with drowning a man’s spirit, and so do I.” I do think, sir, that some of my menly drops Have something in them that drowns the spirit of mine own.  I think so, my lord, That some such as I
Adieu. Farewell.Farewell, farewell.” Amen’s song. ’Tis the song of the day. ‘Tarry, adieu, ‘tis the music of this day,   I think it is the very tune of it, and I do not know the tune, but I know it
Farewell, good Launcelot. Farewell.Adieu.” ’Twas well said.   Tis well that you should be so well met with me. Well met you, fair lady, in my house, and so fare you well at my gate, for I am come to fetch you word that your husband is gone.— Fare
Alack, what heinous sin is it in me To be ashamed to be my father’s child!O, how vile a sin it is in my heart To shame my mother to bear me the name of her father!” O, that I should be so much ashamed To bear my name in such a name as mine own!—   Ay, and
But though I am a daughter to his blood, I am not to his manners. His manners are mine, and mine are not his. I have no more to do with him than to be his daughter’s maidservant.His manners, though they be mine own, are none of mine. Mine eyes are his, mine ears his; his tongue is mine; mine eyes,
O Lorenzo, If thou keep promise, I shall end this strife, Become a Christian and thy loving wife.If thou hold’st promise of it, let me end the strife; Become thou Christian, and thine own wife, For this is the cause of this quarrel.” I do beseech thee, Lorenzo; if thou beest true to her,
13 changes: 13 additions & 0 deletions data/extract.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
I am sorry thou wilt leave my father so.
Our house is hell, and thou, a merry devil, Didst rob it of some taste of tediousness.
And Launcelot, soon at supper shalt thou see Lorenzo, who is thy new master’s guest.
Give him this letter.
Adieu!
If a Christian do not play the knave and get thee, I am much deceived.
But adieu.
These foolish drops do something drown my manly spirit.
Adieu.
Farewell, good Launcelot.
Alack, what heinous sin is it in me To be ashamed to be my father’s child!
But though I am a daughter to his blood, I am not to his manners.
O Lorenzo, If thou keep promise, I shall end this strife, Become a Christian and thy loving wife.
13 changes: 13 additions & 0 deletions data/extract_bx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
I’m sorry you’ll leave my father like that.
Our house is hell, and you, a merry devil, robbed it of some tediousness.
And Launcelot, you’ll see Lorenzo soon at supper.
Give him this letter.
Goodbye!
If a Christian doesn’t play the knave and get you, I’m very wrong.
But goodbye.
These foolish drops drown my manly spirit.
Goodbye.
Goodbye, good Launcelot.
Oh, what a heinous sin I’m having to be ashamed of being my father’s child!
But even though I’m a daughter to his blood, I’m not to his manners.
Oh Lorenzo, if you keep your promise, I’ll end this fight, become a Christian and your loving wife.
13 changes: 13 additions & 0 deletions data/extract_by.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
I am sorry you will leave my father like that.
Our house is hell, and you, a merry devil, robbed it of some tediousness.
And Launcelot, you will see Lorenzo soon at supper.
Give him this letter.
Goodbye!
If a Christian does not play the knave and get you, I am very wrong.
But goodbye.
These foolish drops drown my manly spirit.
Goodbye.
Goodbye, good Launcelot.
What a heinous sin I am having to be ashamed of being my father’s child.
Even though I am a daughter to his blood, I am not to his manners.
If you keep your promise, I will end this fight and become a Christian and your loving wife.
13 changes: 13 additions & 0 deletions data/extract_by_prime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
I am sorry you leave my father like that.
Our house is hell, and you, a merry devil, robbed it of some tedious work.
And Launcelot, you will soon be able to see Lorenzo at supper.
Give him this letter.
Farewell!
If a Christian does not play the knave and get you, I am very wrong.
But goodbye.
These foolish drops drown my manly spirit.
Farewell.
Farewell, Launcelot.
What a heinous sinner I am having to be ashamed of being my father’s child.
I am a daughter of his, but I do not like his manners.
Oh, Lorenzo, if you keep your promise, I will end this fight, become a Christian and marry you.
20 changes: 20 additions & 0 deletions translator/extract_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("t5-small")
model = AutoModelForSeq2SeqLM.from_pretrained("./results/checkpoint-54096")
f = open("../data/extract.txt", "r")
a = f.readlines()
f1 = open("../data/extract_bx.txt", "w")
prefix = "translate Shakespearean English to modern English: "
print("Starting translation")
for sh in a:
input_sh = prefix + sh
input_ids = tokenizer.encode(input_sh, return_tensors="pt")
output = model.generate(input_ids, max_length=128)
t5_translated = tokenizer.decode(output[0], skip_special_tokens=True)
print(input_sh)
print(t5_translated)
print("\n")
f1.write(t5_translated)
f1.write("\n")
f.close()
f1.close()
Loading

0 comments on commit 20b13c1

Please sign in to comment.