Created
August 6, 2021 17:02
-
-
Save simecek/5aca86f6b7189db87fade33ca1b1d733 to your computer and use it in GitHub Desktop.
Styleformer demo.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Styleformer demo.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyNdyB1L7fPPOgb0HqpkCS2T", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/simecek/5aca86f6b7189db87fade33ca1b1d733/styleformer-demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "yh_Dfk-bVzkX", | |
"outputId": "0ffb0c17-6b21-452b-eca4-5d696f8c541a" | |
}, | |
"source": [ | |
"!pip install git+https://github.com/PrithivirajDamodaran/Styleformer.git" | |
], | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Collecting git+https://github.com/PrithivirajDamodaran/Styleformer.git\n", | |
" Cloning https://github.com/PrithivirajDamodaran/Styleformer.git to /tmp/pip-req-build-9mrog8bk\n", | |
" Running command git clone -q https://github.com/PrithivirajDamodaran/Styleformer.git /tmp/pip-req-build-9mrog8bk\n", | |
"Requirement already satisfied: transformers in /usr/local/lib/python3.7/dist-packages (from styleformer==0.1) (4.9.1)\n", | |
"Requirement already satisfied: sentencepiece in /usr/local/lib/python3.7/dist-packages (from styleformer==0.1) (0.1.96)\n", | |
"Requirement already satisfied: python-Levenshtein in /usr/local/lib/python3.7/dist-packages (from styleformer==0.1) (0.12.2)\n", | |
"Requirement already satisfied: fuzzywuzzy in /usr/local/lib/python3.7/dist-packages (from styleformer==0.1) (0.18.0)\n", | |
"Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from python-Levenshtein->styleformer==0.1) (57.2.0)\n", | |
"Requirement already satisfied: sacremoses in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (0.0.45)\n", | |
"Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (2019.12.20)\n", | |
"Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (2.23.0)\n", | |
"Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (4.6.1)\n", | |
"Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (1.19.5)\n", | |
"Requirement already satisfied: filelock in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (3.0.12)\n", | |
"Requirement already satisfied: huggingface-hub==0.0.12 in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (0.0.12)\n", | |
"Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (4.41.1)\n", | |
"Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (21.0)\n", | |
"Requirement already satisfied: tokenizers<0.11,>=0.10.1 in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (0.10.3)\n", | |
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.7/dist-packages (from transformers->styleformer==0.1) (5.4.1)\n", | |
"Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from huggingface-hub==0.0.12->transformers->styleformer==0.1) (3.7.4.3)\n", | |
"Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->transformers->styleformer==0.1) (2.4.7)\n", | |
"Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->transformers->styleformer==0.1) (3.5.0)\n", | |
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->transformers->styleformer==0.1) (2.10)\n", | |
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->transformers->styleformer==0.1) (1.24.3)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->transformers->styleformer==0.1) (2021.5.30)\n", | |
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->transformers->styleformer==0.1) (3.0.4)\n", | |
"Requirement already satisfied: click in /usr/local/lib/python3.7/dist-packages (from sacremoses->transformers->styleformer==0.1) (7.1.2)\n", | |
"Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from sacremoses->transformers->styleformer==0.1) (1.15.0)\n", | |
"Requirement already satisfied: joblib in /usr/local/lib/python3.7/dist-packages (from sacremoses->transformers->styleformer==0.1) (1.0.1)\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "vQCg9-2EV0oK" | |
}, | |
"source": [ | |
"from styleformer import Styleformer\n", | |
"import warnings\n", | |
"warnings.filterwarnings(\"ignore\")" | |
], | |
"execution_count": 8, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 52 | |
}, | |
"id": "FLpNWB0OWlFx", | |
"outputId": "9bd0a295-6de5-4242-d558-6ebd97c9ca69" | |
}, | |
"source": [ | |
"# style 0 = Casual to Formal\n", | |
"sf = Styleformer(style = 0)\n", | |
"\n", | |
"sf.transfer(\"I need to pee\")" | |
], | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Casual to Formal model loaded...\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'I need to use the restroom.'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 9 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 52 | |
}, | |
"id": "PBkFDLq4WpYV", | |
"outputId": "5a23c89b-9765-4f23-bfbd-6a70db65d5e4" | |
}, | |
"source": [ | |
"# style 1 = Formal to Causal\n", | |
"sf = Styleformer(style = 1)\n", | |
"\n", | |
"sf.transfer(\"Please, tell us about your wishes\")" | |
], | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Formal to Casual model loaded...\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'Tell us what you want'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 11 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 52 | |
}, | |
"id": "9m0yaUf4ZfH-", | |
"outputId": "5bbd77b0-5bc0-41f5-cd55-898b3e6e0a84" | |
}, | |
"source": [ | |
"# 2=Active to Passive, 3=Passive to Active\n", | |
"sf = Styleformer(style = 2)\n", | |
"\n", | |
"sf.transfer(\"We are going to watch a movie tonight\")" | |
], | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Active to Passive model loaded...\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'a movie is going to be watched by us tonight'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 13 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment