Skip to content

Instantly share code, notes, and snippets.

@stared
Created August 14, 2018 09:02
Show Gist options
  • Save stared/ec29b1e8d3c99a6288dcc20d77affc93 to your computer and use it in GitHub Desktop.
Save stared/ec29b1e8d3c99a6288dcc20d77affc93 to your computer and use it in GitHub Desktop.
NLP progress Markdown table to YAML
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import re\n",
"import pandas as pd\n",
"import json\n",
"import yaml\n",
"import oyaml\n",
"from collections import OrderedDict"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"dep_pars1 = \"\"\"\n",
"| Model | POS | UAS | LAS | Paper / Source | Code |\n",
"| ------------- | :-----: | :-----:| :-----:| --- | --- |\n",
"| Deep Biaffine (Dozat and Manning, 2017) | 97.3 | 95.44 | 93.76 | [Deep Biaffine Attention for Neural Dependency Parsing](https://arxiv.org/abs/1611.01734) | [Official](https://github.com/tdozat/Parser-v1) |\n",
"| jPTDP (Nguyen and Verspoor, 2018) | 97.97 | 94.51 | 92.87 | [An improved neural network model for joint POS tagging and dependency parsing](https://arxiv.org/abs/1807.03955) | [Official](https://github.com/datquocnguyen/jPTDP) |\n",
"| Andor et al. (2016) | 97.44 | 94.61 | 92.79 | [Globally Normalized Transition-Based Neural Networks](https://www.aclweb.org/anthology/P16-1231) | |\n",
"| Distilled neural FOG (Kuncoro et al., 2016) | 97.3 | 94.26 | 92.06 | [Distilling an Ensemble of Greedy Dependency Parsers into One MST Parser](https://arxiv.org/abs/1609.07561) | |\n",
"| Weiss et al. (2015) | 97.44 | 93.99 | 92.05 | [Structured Training for Neural Network Transition-Based Parsing](http://anthology.aclweb.org/P/P15/P15-1032.pdf) | |\n",
"| BIST transition-based parser (Kiperwasser and Goldberg, 2016) | 97.3 | 93.9 | 91.9 | [Simple and Accurate Dependency Parsing Using Bidirectional LSTM Feature Representations](https://aclweb.org/anthology/Q16-1023) | [Official](https://github.com/elikip/bist-parser/tree/master/barchybrid/src) | \n",
"| Arc-hybrid (Ballesteros et al., 2016) | 97.3 | 93.56 | 91.42 | [Training with Exploration Improves a Greedy Stack-LSTM Parser](https://arxiv.org/abs/1603.03793) | |\n",
"| BIST graph-based parser (Kiperwasser and Goldberg, 2016) | 97.3 | 93.1 | 91.0 | [Simple and Accurate Dependency Parsing Using Bidirectional LSTM Feature Representations](https://aclweb.org/anthology/Q16-1023) | [Official](https://github.com/elikip/bist-parser/tree/master/bmstparser/src) | \n",
"\"\"\"\n",
"\n",
"lang_model1 = \"\"\"\n",
"| Model | Validation perplexity | Test perplexity | Paper / Source |\n",
"| ------------- | :-----:| :-----:| --- |\n",
"| AWD-LSTM-MoS + dynamic eval (Yang et al., 2018)* | 48.33 | 47.69 | [Breaking the Softmax Bottleneck: A High-Rank RNN Language Model](https://arxiv.org/abs/1711.03953) |\n",
"| AWD-LSTM + dynamic eval (Krause et al., 2017)* | 51.6 | 51.1 | [Dynamic Evaluation of Neural Sequence Models](https://arxiv.org/abs/1709.07432) |\n",
"| AWD-LSTM + continuous cache pointer (Merity et al., 2017)* | 53.9 | 52.8 | [Regularizing and Optimizing LSTM Language Models](https://arxiv.org/abs/1708.02182) | \n",
"| AWD-LSTM-MoS (Yang et al., 2018) | 56.54 | 54.44 | [Breaking the Softmax Bottleneck: A High-Rank RNN Language Model](https://arxiv.org/abs/1711.03953) |\n",
"| AWD-LSTM (Merity et al., 2017) | 60.0 | 57.3 | [Regularizing and Optimizing LSTM Language Models](https://arxiv.org/abs/1708.02182) | \n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"md_link = r\"\\s*\\[(.*)\\]\\((.*)\\)\\s*\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('An improved neural network model for joint POS tagging and dependency parsing',\n",
" 'https://arxiv.org/abs/1807.03955')]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"re.findall(md_link, \" [An improved neural network model for joint POS tagging and dependency parsing](https://arxiv.org/abs/1807.03955)\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_table(s):\n",
" lines = s.split(\"\\n\")\n",
" #col_names = [name.strip() for name in lines[1].split(\"|\")]\n",
" col_names = re.split(r\"\\s*\\|\\s*\", lines[1])[1:-1]\n",
" data = [re.split(r\"\\s*\\|\\s*\", line)[1:-1] for line in lines[3:-1]]\n",
" lens = [len(row) for row in data]\n",
" if min(lens) != max(lens):\n",
" print(\"Misformatted data - from {} to {} columns!\".format(min(lens), max(lens)))\n",
" return pd.DataFrame(columns=col_names, data=data)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Model</th>\n",
" <th>POS</th>\n",
" <th>UAS</th>\n",
" <th>LAS</th>\n",
" <th>Paper / Source</th>\n",
" <th>Code</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Deep Biaffine (Dozat and Manning, 2017)</td>\n",
" <td>97.3</td>\n",
" <td>95.44</td>\n",
" <td>93.76</td>\n",
" <td>[Deep Biaffine Attention for Neural Dependency...</td>\n",
" <td>[Official](https://github.com/tdozat/Parser-v1)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>jPTDP (Nguyen and Verspoor, 2018)</td>\n",
" <td>97.97</td>\n",
" <td>94.51</td>\n",
" <td>92.87</td>\n",
" <td>[An improved neural network model for joint PO...</td>\n",
" <td>[Official](https://github.com/datquocnguyen/jP...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Andor et al. (2016)</td>\n",
" <td>97.44</td>\n",
" <td>94.61</td>\n",
" <td>92.79</td>\n",
" <td>[Globally Normalized Transition-Based Neural N...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Distilled neural FOG (Kuncoro et al., 2016)</td>\n",
" <td>97.3</td>\n",
" <td>94.26</td>\n",
" <td>92.06</td>\n",
" <td>[Distilling an Ensemble of Greedy Dependency P...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Weiss et al. (2015)</td>\n",
" <td>97.44</td>\n",
" <td>93.99</td>\n",
" <td>92.05</td>\n",
" <td>[Structured Training for Neural Network Transi...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>BIST transition-based parser (Kiperwasser and ...</td>\n",
" <td>97.3</td>\n",
" <td>93.9</td>\n",
" <td>91.9</td>\n",
" <td>[Simple and Accurate Dependency Parsing Using ...</td>\n",
" <td>[Official](https://github.com/elikip/bist-pars...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Arc-hybrid (Ballesteros et al., 2016)</td>\n",
" <td>97.3</td>\n",
" <td>93.56</td>\n",
" <td>91.42</td>\n",
" <td>[Training with Exploration Improves a Greedy S...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>BIST graph-based parser (Kiperwasser and Goldb...</td>\n",
" <td>97.3</td>\n",
" <td>93.1</td>\n",
" <td>91.0</td>\n",
" <td>[Simple and Accurate Dependency Parsing Using ...</td>\n",
" <td>[Official](https://github.com/elikip/bist-pars...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Model POS UAS LAS \\\n",
"0 Deep Biaffine (Dozat and Manning, 2017) 97.3 95.44 93.76 \n",
"1 jPTDP (Nguyen and Verspoor, 2018) 97.97 94.51 92.87 \n",
"2 Andor et al. (2016) 97.44 94.61 92.79 \n",
"3 Distilled neural FOG (Kuncoro et al., 2016) 97.3 94.26 92.06 \n",
"4 Weiss et al. (2015) 97.44 93.99 92.05 \n",
"5 BIST transition-based parser (Kiperwasser and ... 97.3 93.9 91.9 \n",
"6 Arc-hybrid (Ballesteros et al., 2016) 97.3 93.56 91.42 \n",
"7 BIST graph-based parser (Kiperwasser and Goldb... 97.3 93.1 91.0 \n",
"\n",
" Paper / Source \\\n",
"0 [Deep Biaffine Attention for Neural Dependency... \n",
"1 [An improved neural network model for joint PO... \n",
"2 [Globally Normalized Transition-Based Neural N... \n",
"3 [Distilling an Ensemble of Greedy Dependency P... \n",
"4 [Structured Training for Neural Network Transi... \n",
"5 [Simple and Accurate Dependency Parsing Using ... \n",
"6 [Training with Exploration Improves a Greedy S... \n",
"7 [Simple and Accurate Dependency Parsing Using ... \n",
"\n",
" Code \n",
"0 [Official](https://github.com/tdozat/Parser-v1) \n",
"1 [Official](https://github.com/datquocnguyen/jP... \n",
"2 \n",
"3 \n",
"4 \n",
"5 [Official](https://github.com/elikip/bist-pars... \n",
"6 \n",
"7 [Official](https://github.com/elikip/bist-pars... "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"create_table(dep_pars1)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('Multi-task tri-training', 'Ruder and Plank', '2018')]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"re.findall(r\"(.*)\\s+\\((.*)\\s*,\\s*(\\d{4})\\)\", \"Multi-task tri-training (Ruder and Plank, 2018)\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def model_parse(s):\n",
" # Multi-task tri-training (Ruder and Plank, 2018)\n",
" res = re.findall(r\"(.*)\\s+\\((.*)\\s*,\\s*(\\d{4})\\)\", s)\n",
" if len(res) == 1:\n",
" return {\"model\": res[0][0], \"authors\": res[0][1]}\n",
" elif len(res) == 0:\n",
" return {\"model\": \"\", \"authors\": re.findall(r\"(.*)\\s+\\(\", s)[0] }\n",
" else:\n",
" raise Exception\n",
"\n",
"def process_table(df):\n",
" df = df.copy()\n",
" if not \"Code\" in df.columns:\n",
" df[\"Code\"] = \"\"\n",
" df = df.rename(columns={\"Code\": \"raw_code\", \"Model\": \"raw_model\"})\n",
" df['paper'] = df['Paper / Source'].apply(lambda x: re.findall(md_link, x)[0][0])\n",
" df['url'] = df['Paper / Source'].apply(lambda x: re.findall(md_link, x)[0][1])\n",
" df['code'] = df['raw_code'].apply(lambda x: [{\"name\": link[0], \"url\": link[1]} for link in re.findall(md_link, x)])\n",
" df['year'] = df['raw_model'].apply(lambda x: int(re.findall(r\"\\d{4}\", x)[0]))\n",
" df['model'] = df['raw_model'].apply(lambda x: model_parse(x)['model'])\n",
" df['authors'] = df['raw_model'].apply(lambda x: model_parse(x)['authors'])\n",
" df = df.drop([\"raw_model\", \"raw_code\", \"Paper / Source\"], axis=1)\n",
" score_cols = [col for col in df.columns if col not in ['model', 'authors', 'year', 'code', 'paper', 'url']]\n",
" for col in score_cols:\n",
" df[col] = df[col].astype('float')\n",
" ordered_cols = ['model', 'authors', 'year'] + score_cols + ['paper', 'url', 'code']\n",
" df = df[ordered_cols]\n",
" return df\n",
"\n",
"def row2od(row):\n",
" return OrderedDict([(k, v) for k, v in row.items()])\n",
"\n",
"def table2ordered(df):\n",
" return [row2od(row) for k, row in df.iterrows()] \n",
"\n",
"def md_table2yaml_print(s):\n",
" print(oyaml.dump(table2ordered(process_table(create_table(s)))))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>model</th>\n",
" <th>authors</th>\n",
" <th>year</th>\n",
" <th>Validation perplexity</th>\n",
" <th>Test perplexity</th>\n",
" <th>paper</th>\n",
" <th>url</th>\n",
" <th>code</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>AWD-LSTM-MoS + dynamic eval</td>\n",
" <td>Yang et al.</td>\n",
" <td>2018</td>\n",
" <td>48.33</td>\n",
" <td>47.69</td>\n",
" <td>Breaking the Softmax Bottleneck: A High-Rank R...</td>\n",
" <td>https://arxiv.org/abs/1711.03953</td>\n",
" <td>[]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>AWD-LSTM + dynamic eval</td>\n",
" <td>Krause et al.</td>\n",
" <td>2017</td>\n",
" <td>51.60</td>\n",
" <td>51.10</td>\n",
" <td>Dynamic Evaluation of Neural Sequence Models</td>\n",
" <td>https://arxiv.org/abs/1709.07432</td>\n",
" <td>[]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>AWD-LSTM + continuous cache pointer</td>\n",
" <td>Merity et al.</td>\n",
" <td>2017</td>\n",
" <td>53.90</td>\n",
" <td>52.80</td>\n",
" <td>Regularizing and Optimizing LSTM Language Models</td>\n",
" <td>https://arxiv.org/abs/1708.02182</td>\n",
" <td>[]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>AWD-LSTM-MoS</td>\n",
" <td>Yang et al.</td>\n",
" <td>2018</td>\n",
" <td>56.54</td>\n",
" <td>54.44</td>\n",
" <td>Breaking the Softmax Bottleneck: A High-Rank R...</td>\n",
" <td>https://arxiv.org/abs/1711.03953</td>\n",
" <td>[]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>AWD-LSTM</td>\n",
" <td>Merity et al.</td>\n",
" <td>2017</td>\n",
" <td>60.00</td>\n",
" <td>57.30</td>\n",
" <td>Regularizing and Optimizing LSTM Language Models</td>\n",
" <td>https://arxiv.org/abs/1708.02182</td>\n",
" <td>[]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" model authors year \\\n",
"0 AWD-LSTM-MoS + dynamic eval Yang et al. 2018 \n",
"1 AWD-LSTM + dynamic eval Krause et al. 2017 \n",
"2 AWD-LSTM + continuous cache pointer Merity et al. 2017 \n",
"3 AWD-LSTM-MoS Yang et al. 2018 \n",
"4 AWD-LSTM Merity et al. 2017 \n",
"\n",
" Validation perplexity Test perplexity \\\n",
"0 48.33 47.69 \n",
"1 51.60 51.10 \n",
"2 53.90 52.80 \n",
"3 56.54 54.44 \n",
"4 60.00 57.30 \n",
"\n",
" paper \\\n",
"0 Breaking the Softmax Bottleneck: A High-Rank R... \n",
"1 Dynamic Evaluation of Neural Sequence Models \n",
"2 Regularizing and Optimizing LSTM Language Models \n",
"3 Breaking the Softmax Bottleneck: A High-Rank R... \n",
"4 Regularizing and Optimizing LSTM Language Models \n",
"\n",
" url code \n",
"0 https://arxiv.org/abs/1711.03953 [] \n",
"1 https://arxiv.org/abs/1709.07432 [] \n",
"2 https://arxiv.org/abs/1708.02182 [] \n",
"3 https://arxiv.org/abs/1711.03953 [] \n",
"4 https://arxiv.org/abs/1708.02182 [] "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"process_table(create_table(lang_model1))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"- model: AWD-LSTM-MoS + dynamic eval\n",
" authors: Yang et al.\n",
" year: 2018\n",
" Validation perplexity: 48.33\n",
" Test perplexity: 47.69\n",
" paper: 'Breaking the Softmax Bottleneck: A High-Rank RNN Language Model'\n",
" url: https://arxiv.org/abs/1711.03953\n",
" code: []\n",
"- model: AWD-LSTM + dynamic eval\n",
" authors: Krause et al.\n",
" year: 2017\n",
" Validation perplexity: 51.6\n",
" Test perplexity: 51.1\n",
" paper: Dynamic Evaluation of Neural Sequence Models\n",
" url: https://arxiv.org/abs/1709.07432\n",
" code: []\n",
"- model: AWD-LSTM + continuous cache pointer\n",
" authors: Merity et al.\n",
" year: 2017\n",
" Validation perplexity: 53.9\n",
" Test perplexity: 52.8\n",
" paper: Regularizing and Optimizing LSTM Language Models\n",
" url: https://arxiv.org/abs/1708.02182\n",
" code: []\n",
"- model: AWD-LSTM-MoS\n",
" authors: Yang et al.\n",
" year: 2018\n",
" Validation perplexity: 56.54\n",
" Test perplexity: 54.44\n",
" paper: 'Breaking the Softmax Bottleneck: A High-Rank RNN Language Model'\n",
" url: https://arxiv.org/abs/1711.03953\n",
" code: []\n",
"- model: AWD-LSTM\n",
" authors: Merity et al.\n",
" year: 2017\n",
" Validation perplexity: 60.0\n",
" Test perplexity: 57.3\n",
" paper: Regularizing and Optimizing LSTM Language Models\n",
" url: https://arxiv.org/abs/1708.02182\n",
" code: []\n",
"\n"
]
}
],
"source": [
"md_table2yaml_print(lang_model1)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"- model: Stack-only RNNG\n",
" authors: Kuncoro et al.\n",
" year: 2017\n",
" UAS: 95.8\n",
" LAS: 94.6\n",
" paper: What Do Recurrent Neural Network Grammars Learn About Syntax?\n",
" url: https://arxiv.org/abs/1611.05774\n",
" code: []\n",
"- model: Semi-supervised LSTM-LM\n",
" authors: Choe and Charniak\n",
" year: 2016\n",
" UAS: 95.9\n",
" LAS: 94.1\n",
" paper: Parsing as Language Modeling\n",
" url: http://www.aclweb.org/anthology/D16-1257\n",
" code: []\n",
"- model: Deep Biaffine\n",
" authors: Dozat and Manning\n",
" year: 2017\n",
" UAS: 95.66\n",
" LAS: 94.03\n",
" paper: Deep Biaffine Attention for Neural Dependency Parsing\n",
" url: https://arxiv.org/abs/1611.01734\n",
" code: []\n",
"\n"
]
}
],
"source": [
"md_table2yaml_print(\"\"\"\n",
"| Model | UAS | LAS | Paper / Source | \n",
"| ------------- | :-----:| :-----:| --- | --- |\n",
"| Stack-only RNNG (Kuncoro et al., 2017) | 95.8 | 94.6 | [What Do Recurrent Neural Network Grammars Learn About Syntax?](https://arxiv.org/abs/1611.05774) |\n",
"| Semi-supervised LSTM-LM (Choe and Charniak, 2016) (Constituent parser) | 95.9 | 94.1 | [Parsing as Language Modeling](http://www.aclweb.org/anthology/D16-1257) |\n",
"| Deep Biaffine (Dozat and Manning, 2017) | 95.66 | 94.03 | [Deep Biaffine Attention for Neural Dependency Parsing](https://arxiv.org/abs/1611.01734) |\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"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.5.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@stared
Copy link
Author

stared commented Aug 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment