Skip to content

Instantly share code, notes, and snippets.

@zitterbewegung
Created September 14, 2020 02:21
Show Gist options
  • Save zitterbewegung/c14b5b7f91463e04d75c1773e1660bc8 to your computer and use it in GitHub Desktop.
Save zitterbewegung/c14b5b7f91463e04d75c1773e1660bc8 to your computer and use it in GitHub Desktop.
TLDR with Huggingface
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "TLDR with Huggingface",
"provenance": [],
"private_outputs": true,
"authorship_tag": "ABX9TyOk7J7hoFOwS+4GJjeeWol7",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/zitterbewegung/c14b5b7f91463e04d75c1773e1660bc8/tldr-with-huggingface.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "rQi04megzQXk",
"colab_type": "text"
},
"source": [
"Adapted from the python notebook https://github.com/huggingface/blog/blob/master/notebooks/01_how_to_train.ipynb\n",
"\n",
"\n",
"https://timdettmers.com/2020/09/07/which-gpu-for-deep-learning/\n",
"\n",
"https://colab.research.google.com/signup\n",
"\n",
"DISCLAIMER: Note I own stock in NVDA and AAPL."
]
},
{
"cell_type": "code",
"metadata": {
"id": "KNC07fXtyqzp",
"colab_type": "code",
"colab": {}
},
"source": [
"!pip install -q transformers\n",
"from __future__ import print_function\n",
"import ipywidgets as widgets\n",
"from transformers import pipeline\n",
"JMC_TEXT_TO_SUMMARIZE = '''\n",
"Notes on Heavy Duty Set Theory\n",
"\n",
"\n",
" \"Heavy Duty Set Theory\" (abbreviated HDST) is to be an\n",
"FOL axiomatization of set theory suitable for proving theorems\n",
"in various domains of mathematics, MTC, and artificial intelligence.\n",
"The object of the axiomatization is to make proofs as short as\n",
"possible and to get as close as possible to informal notation.\n",
"Therefore, it will have a large number of axioms.\n",
"\n",
"Recommendations:\n",
"\n",
"1. HDST will be like Kelley's system in containing both classes\n",
"and sets and also axiom schemata for comprehension and replacement.\n",
"\n",
"2. There will be members of sets that are not sets, and the axioms\n",
"will have to be adjusted for this. Numbers and S-expressions\n",
"will be sorts and will be axiomatized and identified with the\n",
"machine versions.\n",
"This may be incompatible with identifying numbers with certain sets.\n",
"An isomorphism with this set can be asserted if wanted.\n",
"Presumably the building the integers from the null set is useful in\n",
"the theory of ordinal numbers, since it identifies the ordering with\n",
"set inclusion and drastically reduces the number of kinds of entities\n",
"occurring in proofs.\n",
"\n",
"3. apply(f,x) giving the value of f(x) will be present and suitably\n",
"axiomatized. In order that apply can be a function in the logic\n",
"we will need an INDCONST UU which is the nominal value for undefined\n",
"quantities. *****I'm not quite sure of this.***** 1979 That's right,\n",
"but it would be well to be able to write f(x) for this. Functions\n",
"of several arguments give notational problems.\n",
"\n",
"4. Suitable sorts for sets, classes, and objects will be set up.\n",
"\n",
"5. Can we make cons and the ordered pair former synonymous?\n",
"If we want the ordered tuple to satisfy reasonable axioms,\n",
"it should be made more like LISP.\n",
"For example, we should distinguish between ordered pairs\n",
"and tuples: Suppose we use (x.y) for the ordered pair\n",
"usually denoted by <x,y>. We will then use for\n",
"the 0-tuple, and define the n+1-tuple by suitable instances of\n",
"<x1,x2,...,xn> = (x1.<x2,...,xn>).\n",
"\n",
"6. We will distinguish two systems; those that don't involve modifications\n",
"to FOL and those that do.\n",
"\n",
"7. If we can modify FOL, then the finite set former {a,b,d,e} should\n",
"be such that membership and subset relationships are immediate.\n",
"Thus \"SET-OBVIOUSITY {b {d e}} {{f d} a b} 7;\", where 7 is f=e,\n",
"should work. Richard points out that a collection of such results\n",
"can be obtained from taut by a suitable translation.\n",
"\n",
"8. For ordered lists, inclusion relations should be obvious.\n",
"In general: what set-theoretic relations are obvious?\n",
"\n",
"Here is an attempt to modify kelley.ax[ax,rww] to suit. The current\n",
"version her reads into FOL. The SETINDUCTION axiom is not correct.\n",
"Ordered triples have been omitted pending a notation change. and\n",
"EXP2 and EXP3 have been omitted.\n",
"\n",
"This file is /u/jmc/w76/heavy.set and a set of axioms is /u/jmc/w76/heavy.ax.\n",
"\n",
"\n",
"'''\n",
"\n",
"nlp_qa = pipeline('question-answering')\n",
"\n",
"\n",
"# This wil return a valid answer\n",
"nlp_qa(context=JMC_TEXT_TO_SUMMARIZE, question='Where is the file?')\n",
"# This will return a ok answer\n",
"nlp_qa(context=JMC_TEXT_TO_SUMMARIZE, question='What is FOL?')\n",
"# This will return a answer that doesn't make sense\n",
"nlp_qa(context=JMC_TEXT_TO_SUMMARIZE, question='What is Heavy Duty Set Theory?')\n",
"\n",
"\n",
"summarizer = pipeline('summarization')\n",
"summary = summarizer(JMC_TEXT_TO_SUMMARIZE)\n",
"print(summary)\n",
"\n",
"context = widgets.Textarea(\n",
" value=summary[0].get('summary_text','Failed'),\n",
" placeholder='Enter something',\n",
" description='Summary:',\n",
" disabled=True\n",
")\n",
"\n",
"query = widgets.Text(\n",
" value='What is this file?',\n",
" placeholder='Enter something',\n",
" description='Question:',\n",
" disabled=False\n",
")\n",
"\n",
"def forward(_):\n",
" if len(query.value) > 0: \n",
" output = nlp_qa(question=query.value, context=JMC_TEXT_TO_SUMMARIZE) \n",
" print(output)\n",
"\n",
"query.on_submit(forward)\n",
"display(context, query)\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Eom1pUFrzPDe",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "DNoOcyFpzMan",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "code",
"metadata": {
"id": "s9Lvf--My232",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment