Skip to content

Instantly share code, notes, and snippets.

@dan-zheng
Last active June 4, 2017 05:55
Show Gist options
  • Save dan-zheng/c540928da85f6dbc43d7b5324ec64010 to your computer and use it in GitHub Desktop.
Save dan-zheng/c540928da85f6dbc43d7b5324ec64010 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Example 1:\n",
"\n",
"Original sentences:\n",
"(0): `Our neighbors dislike the music.`\n",
"(1): `If they are angry, the cops will show up soon.`\n",
"\n",
"Coreference chains:\n",
"CHAIN1-[\"Our\" in sentence 1]\n",
"CHAIN2-[\"the music\" in sentence 1]\n",
"CHAIN3-[\"Our neighbors\" in sentence 1, \"they\" in sentence 2]\n",
"CHAIN4-[\"the cops\" in sentence 2]\n",
"\n",
"Perturbed sentences:\n",
"Strategy: transform mentions to representative mention\n",
"(1): `If our neighbors are angry, the cops will show up soon.`\n",
"Strategy: transform mentions to pronominal form\n",
"(0): `Our neighbors dislike it.`\n",
"(0): `They dislike the music.`\n",
"(1): `If they are angry, they will show up soon.`\n",
"\n",
"Example 2:\n",
"\n",
"Original sentences:\n",
"(0): `Despite her difficulty, Wilma came to understand the point.`\n",
"\n",
"Coreference chains:\n",
"CHAIN0-[\"her\" in sentence 1, \"Wilma\" in sentence 1]\n",
"CHAIN1-[\"her difficulty\" in sentence 1]\n",
"CHAIN3-[\"the point\" in sentence 1]\n",
"\n",
"Perturbed sentences:\n",
"Strategy: transform mentions to representative mention\n",
"(0): `Despite Wilma's difficulty, Wilma came to understand the point.`\n",
"Strategy: transform mentions to pronominal form\n",
"(0): `Despite her difficulty, she came to understand the point.`\n",
"(0): `Despite it, Wilma came to understand the point.`\n",
"(0): `Despite her difficulty, Wilma came to understand it.`\n",
"\n",
"Example 3:\n",
"\n",
"Original sentences:\n",
"(0): `Carol told Bob to attend the party.`\n",
"(1): `They arrived together.`\n",
"\n",
"Coreference chains:\n",
"CHAIN0-[\"Carol\" in sentence 1]\n",
"CHAIN1-[\"Bob\" in sentence 1]\n",
"CHAIN3-[\"the party\" in sentence 1, \"They\" in sentence 2]\n",
"\n",
"Perturbed sentences:\n",
"Strategy: transform mentions to representative mention\n",
"(1): `The party arrived together.`\n",
"Strategy: transform mentions to pronominal form\n",
"(0): `She told Bob to attend the party.`\n",
"(0): `Carol told him to attend the party.`\n",
"(0): `Carol told Bob to attend it.`\n",
"\n",
"Example 4:\n",
"\n",
"Original sentences:\n",
"(0): `The project leader is refusing to help.`\n",
"(1): `The jerk thinks only of himself.`\n",
"\n",
"Coreference chains:\n",
"CHAIN1-[\"The jerk\" in sentence 2]\n",
"CHAIN2-[\"The project leader\" in sentence 1, \"himself\" in sentence 2]\n",
"\n",
"Perturbed sentences:\n",
"Strategy: transform mentions to representative mention\n",
"(1): `The jerk thinks only of the project leader.`\n",
"Strategy: transform mentions to pronominal form\n",
"(0): `He is refusing to help.`\n",
"(1): `He thinks only of himself.`\n",
"\n",
"Example 5:\n",
"\n",
"Original sentences:\n",
"(0): `A bird sat on a branch and it broke.`\n",
"\n",
"Coreference chains:\n",
"CHAIN1-[\"a branch\" in sentence 1]\n",
"CHAIN2-[\"A bird\" in sentence 1, \"it\" in sentence 1]\n",
"\n",
"Perturbed sentences:\n",
"Strategy: transform mentions to representative mention\n",
"(0): `A bird sat on a branch and a bird broke.`\n",
"Strategy: transform mentions to pronominal form\n",
"(0): `A bird sat on it and it broke.`\n",
"(0): `It sat on a branch and it broke.`\n",
"\n",
"Example 6:\n",
"\n",
"Original sentences:\n",
"(0): `Every farmer who owns a donkey beats it.`\n",
"\n",
"Coreference chains:\n",
"CHAIN0-[\"Every farmer who owns a donkey\" in sentence 1]\n",
"CHAIN2-[\"a donkey\" in sentence 1, \"it\" in sentence 1]\n",
"\n",
"Perturbed sentences:\n",
"Strategy: transform mentions to representative mention\n",
"(0): `Every farmer who owns a donkey beats a donkey.`\n",
"Strategy: transform mentions to pronominal form\n",
"(0): `He beats it.`\n",
"(0): `Every farmer who owns it beats it.`\n",
"\n"
]
}
],
"source": [
"// Turby: data augmentation for text\n",
"import com.digitalreasoning.tda.*\n",
"\n",
"// Sample coreference texts\n",
"// From: https://en.wikipedia.org/wiki/Coreference#Types_of_coreference\n",
"val texts: List<String> = listOf(\n",
" // Anaphora\n",
" \"Our neighbors dislike the music. If they are angry, the cops will show up soon.\",\n",
" // Cataphora\n",
" \"Despite her difficulty, Wilma came to understand the point.\",\n",
" // Split antecedents\n",
" \"Carol told Bob to attend the party. They arrived together.\",\n",
" // Coreferring noun phrases\n",
" \"The project leader is refusing to help. The jerk thinks only of himself.\",\n",
" // Challenge by Brandon\n",
" \"A bird sat on a branch and it broke.\",\n",
" // Request by Richard\n",
" \"Every farmer who owns a donkey beats it.\"\n",
")\n",
"\n",
"// Initialize and configure coreference perturber\n",
"val coreferencePerturber = CoreferencePerturber\n",
"coreferencePerturber.verbose = true\n",
"\n",
"// Get perturbations\n",
"texts.forEachIndexed { index, text ->\n",
" println(\"Example ${index + 1}:\")\n",
" val perturbations = coreferencePerturber.perturb(text)\n",
" println()\n",
"}"
]
}
],
"metadata": {
"gist_id": "c540928da85f6dbc43d7b5324ec64010",
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"language_info": {
"file_extension": "kt",
"name": "kotlin"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment