File size: 41,318 Bytes
c0dd6fb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "1dfd5ed8",
"metadata": {},
"outputs": [],
"source": [
"! wget https://data.statmt.org/cc-100/en.txt.xz"
]
},
{
"cell_type": "markdown",
"id": "0bbda5ef",
"metadata": {},
"source": [
"We first download the english common crawl and as per the original [paper](https://arxiv.org/pdf/1806.02847v2.pdf). Then we create a 'document' using the queries from [PDP-60](https://cs.nyu.edu/~davise/papers/WinogradSchemas/PDPChallenge2016.xml) and [WSC273](https://cs.nyu.edu/~davise/papers/WinogradSchemas/WSCollection.xml) by combinging the queries. Note, as the original dataset does not mention removing duplicate queries, neither do we. Following document creation we calculate n-grams(n=1-4) for the document and the documents in common crawl and keep the top 1% of similair documents. \n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "228623fe",
"metadata": {},
"outputs": [],
"source": [
"\n",
"source_document_raw = \"The city councilmen refused the demonstrators a permit because they feared violence \\n The city councilmen refused the demonstrators a permit because they advocated violence.\\n The trophy doesn't fit into the brown suitcase because it is too large.\\n The trophy doesn't fit into the brown suitcase because it is too small.\\n Joan made sure to thank Susan for all the help she had recieved.\\n Joan made sure to thank Susan for all the help she had given.\\n Paul tried to call George on the phone, but he wasn't successful.\\n Paul tried to call George on the phone, but he wasn't available.\\n The lawyer asked the witness a question, but he was reluctant to repeat it.\\n The lawyer asked the witness a question, but he was reluctant to answer it.\\n The delivery truck zoomed by the school bus because it was going so fast.\\n The delivery truck zoomed by the school bus because it was going so slow.\\n Frank felt vindicated when his longtime rival Bill revealed that he was the winner of the competition.\\n Frank felt crushed when his longtime rival Bill revealed that he was the winner of the competition.\\n The man couldn't lift his son because he was so weak.\\n The man couldn't lift his son because he was so heavy.\\n The large ball crashed right through the table because it was made of steel.\\n The large ball crashed right through the table because it was made of styrofoam.\\n John couldn't see the stage with Billy in front of him because he is so short.\\n John couldn't see the stage with Billy in front of him because he is so tall.\\n Tom threw his schoolbag down to Ray after he reached the top of the stairs.\\n Tom threw his schoolbag down to Ray after he reached the bottom of the stairs.\\n Although they ran at about the same speed, Sue beat Sally because she had such a good start.\\n Although they ran at about the same speed, Sue beat Sally because she had such a bad start.\\n The sculpture rolled off the shelf because it wasn't anchored.\\n The sculpture rolled off the shelf because it wasn't level.\\n Sam's drawing was hung just above Tina's and it did look much better with another one below it.\\n Sam's drawing was hung just above Tina's and it did look much better with another one above it.\\n Anna did a lot better than her good friend Lucy on the test because she had studied so hard.\\n Anna did a lot worse than her good friend Lucy on the test because she had studied so hard.\\n The firemen arrived after the police because they were coming from so far away.\\n The firemen arrived before the police because they were coming from so far away.\\n Frank was upset with Tom because the toaster he had bought from him didn't work.\\n Frank was upset with Tom because the toaster he had sold him didn't work.\\n Jim yelled at Kevin because he was so upset.\\n Jim comforted Kevin because he was so upset.\\n The sack of potatoes had been placed above the bag of flour, so it had to be moved first.\\n The sack of potatoes had been placed below the bag of flour, so it had to be moved first.\\n Pete envies Martin although he is very successful.\\n Pete envies Martin because he is very successful.\\n The older students were bullying the younger ones, so we punished them.\\n The older students were bullying the younger ones, so we rescued them.\\n I poured water from the bottle into the cup until it was empty.\\n I poured water from the bottle into the cup until it was full.\\n Susan knows all about Ann's personal problems because she is nosy.\\n Susan knows all about Ann's personal problems because she is indiscreet.\\n Sid explained his theory to Mark but he couldn't convince him.\\n Sid explained his theory to Mark but he couldn't understand him.\\n Susan knew that Ann's son had been in a car accident, so she told her about it.\\n Susan knew that Ann's son had been in a car accident, because she told her about it.\\n Joe's uncle can still beat him at tennis, even though he is 30 years younger.\\n Joe's uncle can still beat him at tennis, even though he is 30 years older.\\n The painting in Mark's living room shows an oak tree. It is to the right of the bookcase.\\n The painting in Mark's living room shows an oak tree. It is to the right of a house.\\n There is a gap in the wall. You can see the garden through it.\\n There is a gap in the wall. You can see the garden behind it.\\n The drain is clogged with hair. It has to be cleaned.\\n The drain is clogged with hair. It has to be removed.\\n My meeting started at 4:00 and I needed to catch the train at 4:30, so there wasn't much time. Luckily, it was short, so it worked out.\\n My meeting started at 4:00 and I needed to catch the train at 4:30, so there wasn't much time. Luckily, it was delayed, so it worked out.\\n There is a pillar between me and the stage, and I can't see around it.\\n There is a pillar between me and the stage, and I can't see it.\\n They broadcast an announcement, but a subway came into the station and I couldn't hear it.\\n They broadcast an announcement, but a subway came into the station and I couldn't hear over it.\\n In the middle of the outdoor concert, the rain started falling, but it continued until 10.\\n In the middle of the outdoor concert, the rain started falling, and it continued until 10.\\n I used an old rag to clean the knife, and then I put it in the trash.\\n I used an old rag to clean the knife, and then I put it in the drawer.\\n Ann asked Mary what time the library closes, because she had forgotten.\\n Ann asked Mary what time the library closes, but she had forgotten.\\n I took the water bottle out of the backpack so that it would be handy.\\n I took the water bottle out of the backpack so that it would be lighter.\\n I couldn't put the pot on the shelf because it was too tall.\\n I couldn't put the pot on the shelf because it was too high.\\n I'm sure that my map will show this building; it is very good.\\n I'm sure that my map will show this building; it is very famous.\\n Bob paid for Charlie's college education. He is very generous.\\n Bob paid for Charlie's college education. He is very grateful.\\n Bob paid for Charlie's college education, but now Charlie acts as though it never happened. He is very hurt.\\n Bob paid for Charlie's college education, but now Charlie acts as though it never happened. He is very ungrateful.\\n Bob was playing cards with Adam and was way ahead. If Adam hadn't had a sudden run of good luck, he would have won.\\n Bob was playing cards with Adam and was way ahead. If Adam hadn't had a sudden run of good luck, he would have lost.\\n Adam can't leave work here until Bob arrives to replace him. If Bob had left home for work on time, he would be gone by this time.\\n Adam can't leave work here until Bob arrives to replace him. If Bob had left home for work on time, he would be here by this time.\\n If the con artist has succeeded in fooling Sam, he would have gotten a lot of money.\\n If the con artist has succeeded in fooling Sam, he would have lost a lot of money.\\n It was a summer afternoon, and the dog was sitting in the middle of the lawn. After a while, it got up and moved to a spot under the tree, because it was hot.\\n It was a summer afternoon, and the dog was sitting in the middle of the lawn. After a while, it got up and moved to a spot under the tree, because it was cooler.\\n The cat was lying by the mouse hole waiting for the mouse, but it was too impatient.\\n The cat was lying by the mouse hole waiting for the mouse, but it was too cautious.\\n Anne gave birth to a daughter last month. She is a very charming woman.\\n Anne gave birth to a daughter last month. She is a very charming baby.\\n Alice tried frantically to stop her daughter from chatting at the party, leaving us to wonder why she was behaving so strangely.\\n Alice tried frantically to stop her daughter from barking at the party, leaving us to wonder why she was behaving so strangely.\\n I saw Jim yelling at some guy in a military uniform with a huge red beard. I don't know why he was, but he looked very unhappy.\\n I saw Jim yelling at some guy in a military uniform with a huge red beard. I don't know who he was, but he looked very unhappy.\\n The fish ate the worm. It was hungry.\\n The fish ate the worm. It was tasty.\\n I was trying to open the lock with the key, but someone had filled the keyhole with chewing gum, and I couldn't get it in.\\n I was trying to open the lock with the key, but someone had filled the keyhole with chewing gum, and I couldn't get it out.\\n The dog chased the cat, which ran up a tree. It waited at the bottom.\\n The dog chased the cat, which ran up a tree. It waited at the top.\\n In the storm, the tree fell down and crashed through the roof of my house. Now, I have to get it removed.\\n In the storm, the tree fell down and crashed through the roof of my house. Now, I have to get it repaired.\\n The customer walked into the bank and stabbed one of the tellers. He was immediately taken to the police station.\\n The customer walked into the bank and stabbed one of the tellers. He was immediately taken to the hospital.\\n John was doing research in the library when he heard a man humming and whistling. He was very annoyed.\\n John was doing research in the library when he heard a man humming and whistling. He was very annoying.\\n John was jogging through the park when he saw a man juggling watermelons. He was very impressed.\\n John was jogging through the park when he saw a man juggling watermelons. He was very impressive.\\n Bob collapsed on the sidewalk. Soon he saw Carl coming to help. He was very ill.\\n Bob collapsed on the sidewalk. Soon he saw Carl coming to help. He was very concerned.\\n Sam and Amy are passionately in love, but Amy's parents are unhappy about it, because they are fifteen.\\n Sam and Amy are passionately in love, but Amy's parents are unhappy about it, because they are snobs.\\n Mark told Pete many lies about himself, which Pete included in his book. He should have been more truthful.\\n Mark told Pete many lies about himself, which Pete included in his book. He should have been more skeptical.\\n Joe has sold his house and bought a new one a few miles away. He will be moving out of it on Thursday.\\n Joe has sold his house and bought a new one a few miles away. He will be moving into it on Thursday.\\n Many people start to read Paul's books and can't put them down. They are gripped because Paul writes so well.\\n Many people start to read Paul's books and can't put them down. They are popular because Paul writes so well.\\n Mary took out her flute and played one of her favorite pieces. She has had it since she was a child.\\n Mary took out her flute and played one of her favorite pieces. She has loved it since she was a child.\\n Sam pulled up a chair to the piano, but it was broken, so he had to stand instead.\\n Sam pulled up a chair to the piano, but it was broken, so he had to sing instead.\\n Since it was raining, I carried the newspaper in my backpack to keep it dry.\\n Since it was raining, I carried the newspaper over my backpack to keep it dry.\\n Sara borrowed the book from the library because she needs it for an article she is working on. She reads it when she gets home from work.\\n Sara borrowed the book from the library because she needs it for an article she is working on. She writes it when she gets home from work.\\n This morning, Joey built a sand castle on the beach, and put a toy flag in the highest tower, but this afternoon the tide knocked it down.\\n This morning, Joey built a sand castle on the beach, and put a toy flag in the highest tower, but this afternoon the wind knocked it down.\\n Jane knocked on Susan's door, but there was no answer. She was disappointed.\\n Jane knocked on Susan's door, but there was no answer. She was out.\\n Jane knocked on the door, and Susan answered it. She invited her to come out.\\n Jane knocked on the door, and Susan answered it. She invited her to come in.\\n Sam took French classes from Adam, because he was eager to speak it fluently.\\n Sam took French classes from Adam, because he was known to speak it fluently.\\n The path to the lake was blocked, so we couldn't use it.\\n The path to the lake was blocked, so we couldn't reach it.\\n The sun was covered by a thick cloud all morning, but luckily, by the time the picnic started, it was out.\\n The sun was covered by a thick cloud all morning, but luckily, by the time the picnic started, it was gone.\\n We went to the lake, because a shark had been seen at the ocean beach, so it was a safer place to swim.\\n We went to the lake, because a shark had been seen at the ocean beach, so it was a dangerous place to swim.\\n Sam tried to paint a picture of shepherds with sheep, but they ended up looking more like golfers.\\n Sam tried to paint a picture of shepherds with sheep, but they ended up looking more like dogs.\\n Mary tucked her daughter Anne into bed, so that she could work.\\n Mary tucked her daughter Anne into bed, so that she could sleep.\\n Fred and Alice had very warm down coats, but they were not prepared for the cold in Alaska.\\n Fred and Alice had very warm down coats, but they were not enough for the cold in Alaska.\\n Thomson visited Cooper's grave in 1765. At that date he had been travelling for five years.\\n Thomson visited Cooper's grave in 1765. At that date he had been dead for five years.\\n Jackson was greatly influenced by Arnold, though he lived two centuries later.\\n Jackson was greatly influenced by Arnold, though he lived two centuries earlier.\\n I can't cut that tree down with that axe; it is too thick.\\n I can't cut that tree down with that axe; it is too small.\\n The foxes are getting in at night and attacking the chickens. I shall have to kill them.\\n The foxes are getting in at night and attacking the chickens. I shall have to guard them.\\n The foxes are getting in at night and attacking the chickens. They have gotten very bold.\\n The foxes are getting in at night and attacking the chickens. They have gotten very nervous.\\n Fred covered his eyes with his hands, because the wind was blowing sand around. He opened them when the wind stopped.\\n Fred covered his eyes with his hands, because the wind was blowing sand around. He lowered them when the wind stopped.\\n The actress used to be named Terpsichore, but she changed it to Tina a few years ago, because she figured it was too hard to pronounce.\\n The actress used to be named Terpsichore, but she changed it to Tina a few years ago, because she figured it was easier to pronounce.\\n Fred watched TV while George went out to buy groceries. After an hour he got up.\\n Fred watched TV while George went out to buy groceries. After an hour he got back.\\n Fred was supposed to run the dishwasher, but he put it off, because he wanted to watch TV. But the show turned out to be boring, so he changed his mind and turned it on.\\n Fred was supposed to run the dishwasher, but he put it off, because he wanted to watch TV. But the show turned out to be boring, so he changed his mind and turned it off.\\n Fred is the only man still alive who remembers my great-grandfather. He is a remarkable man.\\n Fred is the only man still alive who remembers my great-grandfather. He was a remarkable man.\\n Fred is the only man alive who still remembers my father as an infant. When Fred first saw my father, he was twelve years old.\\n Fred is the only man alive who still remembers my father as an infant. When Fred first saw my father, he was twelve months old.\\n In July, Kamtchatka declared war on Yakutsk. Since Yakutsk's army was much better equipped and ten times larger, they were defeated within weeks.\\n In July, Kamtchatka declared war on Yakutsk. Since Yakutsk's army was much better equipped and ten times larger, they were victorious within weeks.\\n Look! There is a minnow swimming right below that duck! It had better get away to safety fast!\\n Look! There is a shark swimming right below that duck! It had better get away to safety fast!\\n Archaeologists have concluded that humans lived in Laputa 20,000 years ago. They hunted for evidence on the river banks.\\n Archaeologists have concluded that humans lived in Laputa 20,000 years ago. They hunted for deer on the river banks.\\n The scientists are studying three species of fish that have recently been found living in the Indian Ocean. They began two years ago.\\n The scientists are studying three species of fish that have recently been found living in the Indian Ocean. They appeared two years ago.\\n The journalists interviewed the stars of the new movie. They were very persistent, so the interview lasted for a long time.\\n The journalists interviewed the stars of the new movie. They were very cooperative, so the interview lasted for a long time.\\n The police arrested all of the gang members. They were trying to stop the drug trade in the neighborhood.\\n The police arrested all of the gang members. They were trying to run the drug trade in the neighborhood.\\n I put the cake away in the refrigerator. It has a lot of butter in it.\\n I put the cake away in the refrigerator. It has a lot of leftovers in it.\\n Sam broke both his ankles and he's walking with crutches. But a month or so from now they should be better.\\n Sam broke both his ankles and he's walking with crutches. But a month or so from now they should be unnecessary.\\n When the sponsors of the bill got to the town hall, they were surprised to find that the room was full of opponents. They were very much in the minority.\\n When the sponsors of the bill got to the town hall, they were surprised to find that the room was full of opponents. They were very much in the majority.\\n Everyone really loved the oatmeal cookies; only a few people liked the chocolate chip cookies. Next time, we should make more of them.\\n Everyone really loved the oatmeal cookies; only a few people liked the chocolate chip cookies. Next time, we should make fewer of them.\\n We had hoped to place copies of our newsletter on all the chairs in the auditorium, but there were simply not enough of them.\\n We had hoped to place copies of our newsletter on all the chairs in the auditorium, but there were simply too many of them.\\n I stuck a pin through a carrot. When I pulled the pin out, it left a hole.\\n I stuck a pin through a carrot. When I pulled the pin out, it had a hole.\\n I couldn't find a spoon, so I tried using a pen to stir my coffee. But that turned out to be a bad idea, because it got full of coffee.\\n I couldn't find a spoon, so I tried using a pen to stir my coffee. But that turned out to be a bad idea, because it got full of ink.\\n Steve follows Fred's example in everything. He admires him hugely.\\n Steve follows Fred's example in everything. He influences him hugely.\\n The table won't fit through the doorway because it is too wide.\\n The table won't fit through the doorway because it is too narrow.\\n Grace was happy to trade me her sweater for my jacket. She thinks it looks dowdy on her.\\n Grace was happy to trade me her sweater for my jacket. She thinks it looks great on her.\\n John hired Bill to take care of him.\\n John hired himself out to Bill to take care of him.\\n John promised Bill to leave, so an hour later he left.\\n John ordered Bill to leave, so an hour later he left.\\n Sam Goodman's biography of the Spartan general Xenophanes conveys a vivid sense of the difficulties he faced in his research.\\n Sam Goodman's biography of the Spartan general Xenophanes conveys a vivid sense of the difficulties he faced in his childhood.\\n Emma's mother had died long ago, and her education had been managed by an excellent woman as governess.\\n Emma's mother had died long ago, and her place had been taken by an excellent woman as governess.\\n Jane knocked on Susan's door but she did not get an answer.\\n ane knocked on Susan's door but she did not answer.\\n Joe paid the detective after he received the final report on the case.\\n Joe paid the detective after he delivered the final report on the case.\\n Beth didn't get angry with Sally, who had cut her off, because she stopped and counted to ten.\\n Beth didn't get angry with Sally, who had cut her off, because she stopped and apologized.\\n Jim signaled the barman and gestured toward his empty glass\\n Jim signaled the barman and gestured toward his bathroom key.\\n Dan took the rear seat while Bill claimed the front because his 'Dibs!' was slow.\\n Dan took the rear seat while Bill claimed the front because his 'Dibs!' was quicker.\\n Tom said 'Check' to Ralph as he moved his bishop.\\n Tom said 'Check' to Ralph as he took his bishop.\\n As Andrea in the crop duster passed over Susan, she could see the landing strip.\\n As Andrea in the crop duster passed over Susan, she could see the landing gear.\\n Tom gave Ralph a lift to school so he wouldn't have to drive alone.\\n Tom gave Ralph a lift to school so he wouldn't have to walk.\\n Bill passed the half-empty plate to John because he was full.\\n Bill passed the half-empty plate to John because he was hungry.\\n Bill passed the gameboy to John because his turn was over.\\n Bill passed the gameboy to John because his turn was next.\\n The man lifted the boy onto his shoulders.\\n The man lifted the boy onto his bunk bed.\\n Stretching her back, the woman smiled at the girl.\\n Patting her back, the woman smiled at the girl.\\n Billy cried because Toby wouldn't accept his toy.\\n Billy cried because Toby wouldn't share his toy.\\n Lily spoke to Donna, breaking her silence.\\n Lily spoke to Donna, breaking her concentration.\\n When Tommy dropped his ice cream, Timmy giggled, so father gave him a sympathetic look.\\n When Tommy dropped his ice cream, Timmy giggled, so father gave him a stern look.\\n As Ollie carried Tommy up the long winding steps, his legs ached.\\n As Ollie carried Tommy up the long winding steps, his legs dangled.\\n The father carried the sleeping boy in his arms\\n The father carried the sleeping boy in his bassinet.\\n The woman held the girl against her chest\\n The woman held the girl against her will.\\n Pam's parents came home and found her having sex with her boyfriend, Paul. They were furious about it.\\n Pam's parents came home and found her having sex with her boyfriend, Paul. They were embarrassed about it.\\n Dr. Adams informed Kate that she had retired and presented several options for future treatment.\\n Dr. Adams informed Kate that she had cancer and presented several options for future treatment.\\n Dan had to stop Bill from toying with the injured bird. He is very compassionate.\\n Dan had to stop Bill from toying with the injured bird. He is very cruel.\\n George got free tickets to the play, but he gave them to Eric, even though he was particularly eager to see it.\\n George got free tickets to the play, but he gave them to Eric, because he was particularly eager to see it.\\n George got free tickets to the play, but he gave them to Eric, because he was not particularly eager to see it.\\n Jane gave Joan candy because she wasn't hungry.\\n Jane gave Joan candy because she was hungry.\\n I tried to paint a picture of an orchard, with lemons in the lemon trees, but they came out looking more like light bulbs.\\n I tried to paint a picture of an orchard, with lemons in the lemon trees, but they came out looking more like telephone poles.\\n James asked Robert for a favor but he was refused.\\n James asked Robert for a favor but he refused.\\n Kirilov ceded the presidency to Shatov because he was less popular.\\n Kirilov ceded the presidency to Shatov because he was more popular.\\n Emma did not pass the ball to Janie although she saw that she was open.\\n Emma did not pass the ball to Janie although she was open.\\n I put the butterfly wing on the table and it broke.\\n I put the heavy book on the table and it broke.\\n Madonna fired her trainer because she couldn't stand her boyfriend.\\n Madonna fired her trainer because she slept with her boyfriend.\\n Madonna fired her trainer because she slept with her boyfriend.\\n Madonna fired her trainer because she couldn't stand her boyfriend.\\n Carol believed that Rebecca suspected that she had stolen the watch.\\n Carol believed that Rebecca regretted that she had stolen the watch.\\n This book introduced Shakespeare to Ovid; it was a major influence on his writing.\\n This book introduced Shakespeare to Goethe; it was a major influence on his writing.\\n This book introduced Shakespeare to Ovid; it was a fine selection of his writing.\\n This book introduced Shakespeare to Goethe; it was a fine selection of his writing.\\n Alice looked for her friend Jade in the crowd. Since she always has good luck, Alice spotted her quickly.\\n Alice looked for her friend Jade in the crowd. Since she always wears a red turban, Alice spotted her quickly.\\n During a game of tag, Ethan chased Luke because he was 'it'.\\n During a game of tag, Ethan ran from Luke because he was 'it'.\\n At the Loebner competition the judges couldn't figure out which respondents were the chatbots because they were so stupid.\\n At the Loebner competition the judges couldn't figure out which respondents were the chatbots because they were so advanced.\\n The user changed his password from 'GrWQWu8JyC' to 'willow-towered Canopy Huntertropic wrestles' as it was easy to forget.\\n The user changed his password from 'GrWQWu8JyC' to 'willow-towered Canopy Huntertropic wrestles' as it was easy to remember.\\n Then Dad figured out how much the man owed the store; to that he added the man's board-bill at the cook-shanty. He subtracted that amount from the man's wages, and made out his check\\n Always before, Larry had helped Dad with his work. But he could not help him now, for Dad said that his boss at the railroad company would not want anyone but him to work in the office.\\n Always before, Larry had helped Dad with his work. But he could not help him now, for Dad said that his boss at the railroad company would not want anyone but him to work in the office.\\n Always before, Larry had helped Dad with his work. But he could not help him now, for Dad said that his boss at the railroad company would not want anyone but him to work in the office.\\n The donkey wished a wart on its hind leg would disappear, and it did.\\n When they had eventually calmed down a bit, and had gotten home, Mr. Farley put the magic pebble in an iron safe. Some day they might want to use it, but really for now, what more could they wish for?\\n The Wainwrights treated Mr. Crowley like a prince until he made his will in their favor; then they treated him like dirt. Folks said he died just to be rid of their everlasting nagging.\\n A number of times Henry had been present at interviews which his father had had with noted detectives who desired his aid in solving perplexing mysteries, and those occasions stood out as red-letter days for him.\\n What about the time you cut up tulip bulbs in the hamburgers because you thought they were onions?\\n No one joins Facebook to be sad and lonely. But a new study from the University of Wisconsin psychologist George Lincoln argues that that's exactly how it makes us feel.\\n Equally swoon-worthy is C.K. Dexter Haven, a pallid young dandy holding a jade-handled walking stick, with a poodle asleep at his feet\\n Lionel is holding captive a scientist, Dr. Vardi, who has invented a device that turns animals invisible; Lionel plans to use it on Geoffrey and send him to steal nuclear material from an army vault.\\n Larry, a timid teen-ager, lives with his widowed mother in a Brooklyn housing project. Larry's father, a gang leader, was shot to death; his father's disciple, Antonio, takes Larry under his wing, and quickly molds him into a drug runner.\\n The Dakota prairie lay so warm and bright under the shining sun that it did not seem possible that it had ever been swept by the winds and snows of that hard winter.\\n It is not easy to space buttonholes exactly the same distance apart, and it is very difficult to cut them precisely the right size. The tiniest slip of the scissors will make the hole too large, and even one thread uncut will leave it too small.\\n The storekeepers stayed in town to run their stores and lived in the rooms behind them.\\n Even before they reached town, they could hear a sound like corn popping. Dora asked what it was, and Dad said it was firecrackers.\\n All the buttons up the back of Dora's plaid dress were buttoned outside-in. Maude should have thought to button her up; but no, she had left poor little Dora to do the best she could, alone.\\n Bernard, who had not told the government official that he was less than 21 when he filed for a homestead claim, did not consider that he had done anything dishonest. Still, anyone who knew that he was 19 years old could take his claim away from him.\\n Bernard, who had not told the government official that he was less than 21 when he filed for a homestead claim, did not consider that he had done anything dishonest. Still, anyone who knew that he was 19 years old could take his claim away from him.\\n Bernard, who had not told the government official that he was less than 21 when he filed for a homestead claim, did not consider that he had done anything dishonest. Still, anyone who knew that he was 19 years old could take his claim away from him.\\n The politicians far away in Washington could not know the settlers so they must make rules to regulate them.\\n The politicians far away in Washington could not know the settlers so they must make rules to regulate them.\\n Men had the right to keep their sons working for them until they were 21 years of age.\\n Since Chester was dependent on Uncle Vernon, he couldn't very well marry without his approval\\n Since Chester was dependent on Uncle Vernon, he couldn't very well marry without his approval\\n I sat there feeling rather like a chappie I'd once read about in a book, who murdered another cove and hid the body under the dining-room table, and then had to be the life and soul of a dinner party, with it there all the time.\\n Mr. Taylor was a man of uncertain temper and his general tendency was to think that David was a poor chump and that whatever step he took in any direction on his own account was just another proof of his innate idiocy,\\n I sallied out for a bit of food, more to pass the time than because I wanted it.\\n Mr. Moncrieff visited Chester's luxurious New York apartment, thinking that it belonged to his son Edward. The result was that Mr. Moncrieff has decided to cancel Edward's allowance on the ground that he no longer requires his financial support.\\n Mr. Moncrieff visited Chester's luxurious New York apartment, thinking that it belonged to his son Edward. The result was that Mr. Moncrieff has decided to cancel Edward's allowance on the ground that he no longer requires his financial support.\\n Mama came over and sat down beside Alice. Gently she stroked her hair and let the child weep.\\n Mama came over and sat down beside Alice. Gently she stroked her hair and let the child weep.\\n Alice was dusting the living room and trying to find the button that Mama had hidden. No time today to look at old pictures in her favorite photo album. Today she had to hunt for a button, so she put the album on a chair without even opening it.\\n Alice was dusting the living room and trying to find the button that Mama had hidden. No time today to look at old pictures in her favorite photo album. Today she had to hunt for a button, so she put the album on a chair without even opening it.\\n Alice was dusting the living room and trying to find the button that Mama had hidden. No time today to look at old pictures in her favorite photo album. Today she had to hunt for a button, so she put the album on a chair without even opening it.\\n Papa looked down at the children's faces, so puzzled and sad now. It was bad enough that they had to be denied so many things because he couldn't afford them.\\n Papa looked down at the children's faces, so puzzled and sad now. It was bad enough that they had to be denied so many things because he couldn't afford them.\\n Every day after dinner Mr. Schmidt took a long nap. Mark would let him sleep for an hour, then wake him up, scold him, and get him to work. He needed to get him to finish his work, because his work was beautiful\\n Every day after dinner Mr. Schmidt took a long nap. Mark would let him sleep for an hour, then wake him up, scold him, and get him to work. He needed to get him to finish his work, because his work was beautiful\\n The signs over the shops' doors had pictures that indicated what work was done inside. Although more and more people were learning how to read, each artisan still had signs, not wishing to lose a possible patron merely because he happened to be illiterate.\\n Mark became absorbed in Blaze, the white horse. He was afraid the stable boys at the Burlington Stables struck at him and bullied him because he was timid, so he took upon himself the feeding and care of the animal.\\n Mark became absorbed in Blaze, the white horse. He was afraid the stable boys at the Burlington Stables struck at him and bullied him because he was timid, so he took upon himself the feeding and care of the animal.\\n Mark was close to Mr. Singer's heels. He heard him calling for the captain, promising him, in the jargon everyone talked that night, that not one thing should be damaged on the ship except only the ammunition, but the captain and all his crew had best stay in the cabin until the work was over\\n Mark was close to Mr. Singer's heels. He heard him calling for the captain, promising him, in the jargon everyone talked that night, that not one thing should be damaged on the ship except only the ammunition, but the captain and all his crew had best stay in the cabin until the work was over.\\n Mark was close to Mr. Singer's heels. He heard him calling for the captain, promising him, in the jargon everyone talked that night, that not one thing should be damaged on the ship except only the ammunition, but the captain and all his crew had best stay in the cabin until the work was over.\\n Mark heard Steve's feet going down the ladder. The door of the shop closed after him. He ran to look out the window.\\n Mark heard Steve's feet going down the ladder. The door of the shop closed after him. He ran to look out the window.\\n Of one thing Mark was sure. Harry knew much less than he did.\\n So Mark slept. It was daylight when he woke with Warren's hand upon his shoulder.\\n By rolling over in her upper berth, Tatyana could look over the edge of it and see her mother plainly. How very small and straight and rigid she lay in the bunk below! Her eyes were closed, but Tatyana doubted if she slept.\\n By rolling over in her upper berth, Tatyana could look over the edge of it and see her mother plainly. How very small and straight and rigid she lay in the bunk below! Her eyes were closed, but Tatyana doubted if she slept.\\n When Tatyana reached the cabin, her mother was sleeping. She was careful not to disturb her, undressing and climbing back into her berth.\\n When Tatyana reached the cabin, her mother was sleeping. She was careful not to disturb her, undressing and climbing back into her berth.\\n When Tatyana reached the cabin, her mother was sleeping. She was careful not to disturb her, undressing and climbing back into her berth.\\n Tatyana managed two guitars and a bag, and still could point out the Freemans: 'Isn't it nice that they have come, Mama!'\\n Tatyana knew that Grandma always enjoyed serving an abundance of food to her guests. Now Tatyana watched as Grandma gathered Tatyana's small mother into a wide, scrawny embrace and then propelled her to the table, lifting her shawl from her shoulders, seating her in the place of honor, and saying simply: 'There's plenty.'\\n The table was piled high with food, and on the floor beside it there were crocks, baskets, and a five-quart pail of milk.\\n Grant worked hard to harvest his beans so he and his family would have enough to eat that winter, His friend Henry let him stack them in his barn where they would dry. Later, he and Tatyana would shell them and cook them for their Sunday dinners.\\n Grant worked hard to harvest his beans so he and his family would have enough to eat that winter, His friend Henry let him stack them in his barn where they would dry. Later, he and Tatyana would shell them and cook them for their Sunday dinners.\""
]
},
{
"cell_type": "markdown",
"id": "897f2665",
"metadata": {},
"source": [
"$similarityscore_{document} = \\frac{\\sum_n^4 n F1(n)}{\\sum_n^4 n}$"
]
},
{
"cell_type": "code",
"execution_count": 123,
"id": "51801f0c",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import spacy\n",
"import textacy\n",
"nlp = spacy.load(\"en_core_web_sm\")\n",
"def intersection(lst1, lst2):\n",
" lst3 = [value for value in lst1 if value in lst2]\n",
" return lst3\n",
"def get_doc_ngrams(doc,min_freq=1):\n",
" unigrams = [str(i) for i in set(textacy.extract.basics.ngrams(doc, 1, min_freq=min_freq))]\n",
" bigrams = [str(i) for i in set(textacy.extract.basics.ngrams(doc, 2, min_freq=min_freq))]\n",
" trigrams = [str(i) for i in set(textacy.extract.basics.ngrams(doc, 3, min_freq=min_freq))]\n",
" quadgrams = [str(i) for i in set(textacy.extract.basics.ngrams(doc, 4, min_freq=min_freq))]\n",
" return [unigrams,bigrams,trigrams,quadgrams]"
]
},
{
"cell_type": "code",
"execution_count": 124,
"id": "b5c348a6",
"metadata": {},
"outputs": [],
"source": [
"source_document_raw = ''\n",
"with open('queries.txt','r') as f:\n",
" for l in f:\n",
" source_document_raw += l\n",
"\n",
" \n",
"source_document = nlp(source_document_raw.lower())\n",
"source_ngrams = get_doc_ngrams(source_document)"
]
},
{
"cell_type": "code",
"execution_count": 107,
"id": "e0c545bf",
"metadata": {},
"outputs": [],
"source": [
"j = 0\n",
"# 1 extract ngrams\n",
"# 2 extract TP FP and FN\n",
"# TP is the len of set intersection of target document and source document\n",
"# FP = len(target document) - len(intersection)\n",
"# FN = len(source document) - len(intersection)\n",
"with open('en.txt','r') as f:\n",
" for l in f:\n",
" target_document_raw = l.strip().lower()\n",
" target_document = nlp(target_document_raw.lower())\n",
" target_ngrams = get_doc_ngrams(target_document)\n",
" score = 0\n",
" for i in range(4):\n",
" TP = len(intersection(source_ngrams[i],target_ngrams[i]))\n",
" FP = len(target_ngrams[i]) - TP\n",
" FN = len(source_ngrams[i]) - TP\n",
" F1 = 0\n",
" if TP > 0:\n",
" P = TP/(TP+FP)\n",
" R = TP/(TP+FN)\n",
" F1 = (2*P*R)/(P+R)\n",
" score += F1 * (i + 1)\n",
" score /= 10 # Denominator is the sum of frequencies so 1+2+3+4=10\n",
" scores[j] = score\n",
" j += 1\n",
"top_percent = int(len(scores)/1000)\n",
"top_items = sorted(scores,key=scores.get,reverse=True)[:top_percent]\n",
"\n",
"j=0\n",
"with open('en.txt','r') as f:\n",
" with open('stories-cc.txt','w') as w:\n",
" for l in f:\n",
" if j in top_items:\n",
" w.write(l)\n",
" j+= 1\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "base"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|