{ "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\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\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 2\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mos\u001b[39;00m\n\u001b[0;32m 3\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 }