Spaces:
Runtime error
Runtime error
File size: 8,761 Bytes
abe5e7f |
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'gpt_2_simple'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\Users\\franz\\AbstractGenerator\\AbstractGenerator.ipynb Cell 1'\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/franz/AbstractGenerator/AbstractGenerator.ipynb#ch0000000?line=0'>1</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mgpt_2_simple\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mgpt2\u001b[39;00m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/franz/AbstractGenerator/AbstractGenerator.ipynb#ch0000000?line=1'>2</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mos\u001b[39;00m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/franz/AbstractGenerator/AbstractGenerator.ipynb#ch0000000?line=2'>3</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtensorflow\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mtf\u001b[39;00m\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'gpt_2_simple'"
]
}
],
"source": [
"\n",
"import gpt_2_simple as gpt2\n",
"import os\n",
"import tensorflow as tf\n",
"import pandas as pd\n",
"import re\n",
"print(\"GPU is\", \"available\" if tf.test.is_gpu_available() else \"NOT AVAILABLE\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"model_name = \"124M\"\n",
"if not os.path.isdir(os.path.join(\"models\", model_name)):\n",
"\tprint(f\"Downloading {model_name} model...\")\n",
"\tgpt2.download_gpt2(model_name=model_name) "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"path = 'AbstractGenerator/'\n",
"checkpoint_dir =path+'weights/'\n",
"data_path = path+'Tokenized_data/'\n",
"\n",
"\n",
"file_name = 'resumen'\n",
"file_path = data_path+file_name\n",
"\n",
"prefix= '<|startoftext|>'\n",
"sufix ='<|endoftext|>'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# pretrained"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sess = gpt2.start_tf_sess()\n",
"gpt2.load_gpt2(sess,checkpoint_dir=checkpoint_dir,run_name='run1')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# train "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tf.compat.v1.reset_default_graph()\n",
"sess = gpt2.start_tf_sess()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gpt2.finetune(sess,\n",
" file_path+'.txt',\n",
" model_name=model_name,\n",
" checkpoint_dir=checkpoint_dir, \n",
" steps=1000\n",
" ) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# test"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"text = \"\"\"Introduction and preliminaries\n",
"The focus of this paper is decompositions of (k, `)-sparse graphs into edge-disjoint subgraphs\n",
"that certify sparsity. We use graph to mean a multigraph, possibly with loops. We say that a\n",
"graph is (k, `)-sparse if no subset of n′ vertices spans more than kn′− ` edges in the graph; a\n",
"(k, `)-sparse graph with kn′− ` edges is (k, `)-tight. We call the range k ≤ `≤ 2k−1 the upper\n",
"range of sparse graphs and 0≤ `≤ k the lower range.\n",
"In this paper, we present efficient algorithms for finding decompositions that certify sparsity\n",
"in the upper range of `. Our algorithms also apply in the lower range, which was already ad-\n",
"dressed by [3, 4, 5, 6, 19]. A decomposition certifies the sparsity of a graph if the sparse graphs\n",
"and graphs admitting the decomposition coincide.\n",
"Our algorithms are based on a new characterization of sparse graphs, which we call the\n",
"pebble game with colors. The pebble game with colors is a simple graph construction rule that\n",
"produces a sparse graph along with a sparsity-certifying decomposition.\n",
"We define and study a canonical class of pebble game constructions, which correspond to\n",
"previously studied decompositions of sparse graphs into edge disjoint trees. Our results provide\n",
"a unifying framework for all the previously known special cases, including Nash-Williams-\n",
"Tutte and [7, 24]. Indeed, in the lower range, canonical pebble game constructions capture the\n",
"properties of the augmenting paths used in matroid union and intersection algorithms[5, 6].\n",
"Since the sparse graphs in the upper range are not known to be unions or intersections of the\n",
"matroids for which there are efficient augmenting path algorithms, these do not easily apply in\n",
"∗ Research of both authors funded by the NSF under grants NSF CCF-0430990 and NSF-DARPA CARGO\n",
"CCR-0310661 to the first author.\n",
"2 Ileana Streinu, Louis Theran\n",
"Term Meaning\n",
"Sparse graph G Every non-empty subgraph on n′ vertices has ≤ kn′− ` edges\n",
"Tight graph G G = (V,E) is sparse and |V |= n, |E|= kn− `\n",
"Block H in G G is sparse, and H is a tight subgraph\n",
"Component H of G G is sparse and H is a maximal block\n",
"Map-graph Graph that admits an out-degree-exactly-one orientation\n",
"(k, `)-maps-and-trees Edge-disjoint union of ` trees and (k− `) map-grpahs\n",
"`Tk Union of ` trees, each vertex is in exactly k of them\n",
"Set of tree-pieces of an `Tk induced on V ′ ⊂V Pieces of trees in the `Tk spanned by E(V ′)\n",
"Proper `Tk Every V ′ ⊂V contains ≥ ` pieces of trees from the `Tk\n",
"Table 1. Sparse graph and decomposition terminology used in this paper.\n",
"the upper range. Pebble game with colors constructions may thus be considered a strengthening\n",
"of augmenting paths to the upper range of matroidal sparse graphs.\n",
"1.1. Sparse graphs\n",
"\n",
"ABSTRACT\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gpt2.generate(sess,prefix=text,truncate=sufix,checkpoint_dir=checkpoint_dir,nsamples=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Tokeniser"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = pd.read_csv('Recipe-Creator\\data\\scientific_paper_full_text_translated.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import codecs\n",
"with codecs.open(\"Recipe-Creator/Tokenized_data/resumen.txt\",'a','utf-8') as f:\n",
" for i in ds.index:\n",
" f.write(prefix+\"\\n\")\n",
" f.write(ds.iloc[i]['text_no_abstract'])\n",
" f.write(\"ABSTRACT\\n\")\n",
" f.write(ds.iloc[i]['abstract']+\"\\n\")\n",
" f.write(sufix)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr\n",
"\n",
"def greet(text):\n",
" return gpt2.generate(sess,prefix=str(text),truncate=sufix,checkpoint_dir=checkpoint_dir,nsamples=1)\n",
"\n",
"iface = gr.Interface(fn=greet, inputs=\"text\", outputs=\"text\")\n",
"iface.launch(share=True,debug=True)"
]
}
],
"metadata": {
"interpreter": {
"hash": "53fbdc69e3e12c371950068c144423682c30d04ec68c2bd46937202e33e0058d"
},
"kernelspec": {
"display_name": "Python 3.7.11 ('receta')",
"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.9.7"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|