{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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": null, "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": null, "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": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "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", " Here we show that decompositions of sparse graphs are sometimes more efficient than\n", "combinations of adjacent trees. In this paper, we apply a combinatorial\n", "analysis of SparseGraph.com [5, 6] to evaluate our algorithm for finding\n", "appropriate decompositions of sparse graphs in the upper range of sparse graphs\n", "and in the lower range of sparse graphs. We show that the decomposition\n", "certified in SparseGraph.com is as accurate as a tree-building algorithm\n", "in the upper range of sparse graphs. This demonstrates that for the\n", "case of SparseGraph.com [5], it is possible to construct a suitable decomposition\n", "class within the bounds of the graph. The algorithm we use is based on a\n", "combination of decompositions.\n", "\n", "\n" ] } ], "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.7.11" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }